初学者
10 分钟

进入使用ISO1042和PIC32MZ2048EFM100的安全CAN通信领域

自信推动您的数据前进!

CAN Isolator 2 Click with Curiosity PIC32 MZ EF

已发布 6月 24, 2024

点击板

CAN Isolator 2 Click

开发板

Curiosity PIC32 MZ EF

编译器

NECTO Studio

微控制器单元

PIC32MZ2048EFM100

该解决方案提供针对地电位差、电噪声和电压尖峰的保护,确保在 CAN 总线上进行稳定可靠的通信。

A

A

硬件概览

它是如何工作的?

CAN Isolator 2 Click 基于德州仪器的 ISO1042,这是一款隔离的 CAN 收发器。它具有多种特性,如欠压保护、驱动器主导超时 (TXD DTO)、总线引脚上的 HBM ESD 容差等。该收发器在无电状态下具有理想的被动高阻抗总线端子。如果与隔离电源配合使用,CAN Isolator 2 Click 是保护总线免受高电压和噪声电流的理想选择。此 Click board™ 上有两种操作状态:主导和隐性。在主导状态下,总线由驱动器差动驱动。在隐性状态下,CAN 节点的主 MCU 使用 TXD 引脚驱动总线,并通过 RXD 引脚从总线接

收数据。为了将 ISO1042 连接到 CAN 总线上,此 Click board™ 配备了一个标准的 DB 9 针公连接器。根据 ISO 11898-2 标准,最大总线长度为 40m,最大支线长度为 0.3m,而通过精心设计,电缆可以更长。该收发器具有高输入阻抗,因此允许在 CAN 总线上连接大量节点。CAN Isolator 2 Click 使用标准的 UART 接口与主 MCU 通信,通常使用的 UART RX 和 TX 引脚。此外,还有几个连接头可以通过跳线直接连接接口线。CAN Isolator 2 Click 的左侧有一个 VEXT 2 针连接头,用于连接外部电

源。与 VEXT 一起,在另一侧有 CANH 和 CANL 引脚,以相同方式连接 CAN 总线。在 CAN 连接头下方,还有一个 TX 和 RX 连接头,允许此 Click board™ 独立于主 MCU 使用。此 Click board™ 可以通过 VCC SEL 跳线选择 3.3V 或 5V 逻辑电压电平进行操作。这样,3.3V 和 5V 的 MCU 都可以正确使用通信线路。此外,此 Click board™ 配备了包含易于使用的函数和示例代码的库,可用于进一步开发。

CAN Isolator 2 Click hardware overview image

功能概述

开发板

Curiosity PIC32 MZ EF 开发板是一个完全集成的 32 位开发平台,特点是高性能的 PIC32MZ EF 系列(PIC32MZ2048EFM),该系列具有 2MB Flash、512KB RAM、集成的浮点单元(FPU)、加密加速器和出色的连接选项。它包括一个集成的程序员和调试器,无需额外硬件。用户可以通过 MIKROE 

mikroBUS™ Click™ 适配器板扩展功能,通过 Microchip PHY 女儿板添加以太网连接功能,使用 Microchip 扩展板添加 WiFi 连接能力,并通过 Microchip 音频女儿板添加音频输入和输出功能。这些板完全集成到 PIC32 强大的软件框架 MPLAB Harmony 中,该框架提供了一个灵活且模块化的接口

来应用开发、一套丰富的互操作软件堆栈(TCP-IP、USB)和易于使用的功能。Curiosity PIC32 MZ EF 开发板提供了扩展能力,使其成为连接性、物联网和通用应用中快速原型设计的绝佳选择。

Curiosity PIC32MZ EF double side image

微控制器概述 

MCU卡片 / MCU

default

建筑

PIC32

MCU 内存 (KB)

2048

硅供应商

Microchip

引脚数

100

RAM (字节)

524288

你完善了我!

配件

DB9 Cable Female-to-Female (2m) 电缆是建立设备之间可靠串行数据连接的必备工具。这条电缆两端均配有 DB9 母头连接器,使其能够在计算机、路由器、交换机和其他串行设备之间实现无缝连接。电缆长度为 2 米,提供灵活的布置选项而不会影响数据传输质量。该电缆经过精密制作,确保一致且可靠的数据交换,适用于工业应用、办公环境和家庭设置。无论是配置网络设备、访问控制台端口,还是使用串行外设,这条电缆的耐用结构和坚固连接器都能保证稳定的连接。使用 2 米 DB9 母对母电缆简化您的数据通信需求,这是一个高效解决方案,旨在轻松高效地满足您的串行连接要求。

CAN Isolator 2 Click accessories image

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
NC
NC
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
NC
NC
INT
UART TX
RPD10
TX
UART RX
RPD15
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

CAN Isolator 2 Click Schematic schematic

一步一步来

项目组装

Curiosity PIC32MZ EF front image hardware assembly

从选择您的开发板和Click板™开始。以Curiosity PIC32 MZ EF作为您的开发板开始。

Curiosity PIC32MZ EF front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
Curiosity PIC32 MZ EF MB 1 Access - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Curiosity PIC32 MZ EF MCU Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

实时跟踪您的结果

应用程序输出

1. 应用程序输出 - 在调试模式下,“应用程序输出”窗口支持实时数据监控,直接提供执行结果的可视化。请按照提供的教程正确配置环境,以确保数据正确显示。

2. UART 终端 - 使用UART Terminal通过USB to UART converter监视数据传输,实现Click board™与开发系统之间的直接通信。请根据项目需求配置波特率和其他串行设置,以确保正常运行。有关分步设置说明,请参考提供的教程

3. Plot 输出 - Plot功能提供了一种强大的方式来可视化实时传感器数据,使趋势分析、调试和多个数据点的对比变得更加直观。要正确设置,请按照提供的教程,其中包含使用Plot功能显示Click board™读数的分步示例。在代码中使用Plot功能时,请使用以下函数:plot(insert_graph_name, variable_name);。这是一个通用格式,用户需要将“insert_graph_name”替换为实际图表名称,并将“variable_name”替换为要显示的参数。

软件支持

库描述

该库包含 CAN Isolator 2 Click 驱动程序的 API。

关键功能:

  • canisolator2_generic_write - CAN Isolator 2 数据写入功能。

  • canisolator2_generic_read - CAN Isolator 2 数据读取功能。

  • canisolator2_send_data - CAN Isolator 2 发送数据功能。

开源

代码示例

完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio 应用程序代码也可以在MIKROE的GitHub账户中找到。

/*!
 * @file main.c
 * @brief CAN Isolator 2 Click Example.
 *
 * # Description
 * This example reads and processes data from CAN Isolator 2 clicks.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes driver and wake-up module.
 *
 * ## Application Task
 * Transmitter/Receiver task depends on uncommented code.
 * Receiver logging each received byte to the UART for data logging,
 * while transmitted send messages every 2 seconds.
 *
 * ## Additional Function
 * - static void canisolator2_clear_app_buf ( void )
 * - static err_t canisolator2_process ( void )
 *
 * @author Nenad Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "canisolator2.h"

#define PROCESS_BUFFER_SIZE 200

// #define TRANSMIT
#define RECIEVER

static canisolator2_t canisolator2;
static log_t logger;

static char app_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
static int32_t app_buf_len = 0;
static int32_t app_buf_cnt = 0;

unsigned char demo_message[ 9 ] = { 'M', 'i', 'k', 'r', 'o', 'E', 13, 10, 0 };

/**
 * @brief CAN Isolator 2 clearing application buffer.
 * @details This function clears memory of application buffer and reset it's length and counter.
 * @note None.
 */
static void canisolator2_clear_app_buf ( void );

/**
 * @brief CAN Isolator 2 data reading function.
 * @details This function reads data from device and concatenates data to application buffer.
 *
 * @return @li @c  0 - Read some data.
 *         @li @c -1 - Nothing is read.
 *         @li @c -2 - Application buffer overflow.
 *
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t canisolator2_process ( void );

void application_init ( void ) {
    log_cfg_t log_cfg;                    /**< Logger config object. */
    canisolator2_cfg_t canisolator2_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );

    // Click initialization.

    canisolator2_cfg_setup( &canisolator2_cfg );
    CANISOLATOR2_MAP_MIKROBUS( canisolator2_cfg, MIKROBUS_1 );
    err_t init_flag  = canisolator2_init( &canisolator2, &canisolator2_cfg );
    if ( init_flag == UART_ERROR ) {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }

    app_buf_len = 0;
    app_buf_cnt = 0;
    log_info( &logger, " Application Task " );
    Delay_ms( 100 );
    
    #ifdef TRANSMIT
    
        log_printf( &logger, "    Send data:    \r\n" );
        log_printf( &logger, "      MikroE      \r\n" );
        log_printf( &logger, "------------------\r\n" );
        log_printf( &logger, "  Transmit data   \r\n" );
        Delay_ms( 1000 );

    #endif
        
    #ifdef RECIEVER

        log_printf( &logger, "   Receive data  \r\n" );
        Delay_ms( 2000 );
    
    #endif
        
    log_printf( &logger, "------------------\r\n" );
}

void application_task ( void ) {
   #ifdef TRANSMIT
    
        canisolator2_send_data( &canisolator2, demo_message );
        log_printf( &logger, "\t%s", demo_message );
        Delay_ms( 2000 );
        log_printf( &logger, "------------------\r\n" );    
    
    #endif
    
    #ifdef RECIEVER
    
        canisolator2_process( );

        if ( app_buf_len > 0 ) {
            log_printf( &logger, "%s", app_buf );
            canisolator2_clear_app_buf(  );
        }
    
    #endif
}

void main ( void ) {
    application_init( );

    for ( ; ; ) {
        application_task( );
    }
}

static void canisolator2_clear_app_buf ( void ) {
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
    app_buf_cnt = 0;
}

static err_t canisolator2_process ( void ) {
    int32_t rx_size;
    char rx_buff[ PROCESS_BUFFER_SIZE ] = { 0 };

    rx_size = canisolator2_generic_read( &canisolator2, rx_buff, PROCESS_BUFFER_SIZE );

    if ( rx_size > 0 ) {
        int32_t buf_cnt = 0;

        if ( app_buf_len + rx_size >= PROCESS_BUFFER_SIZE ) {
           canisolator2_clear_app_buf(  );
            return CANISOLATOR2_ERROR;
        } else {
            buf_cnt = app_buf_len;
            app_buf_len += rx_size;
        }

        for ( int32_t rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ ) {
            if ( rx_buff[ rx_cnt ] != 0 ) {
                app_buf[ ( buf_cnt + rx_cnt ) ] = rx_buff[ rx_cnt ];
            } else {
                app_buf_len--;
                buf_cnt--;
            }

        }
        return CANISOLATOR2_OK;
    }
    return CANISOLATOR2_ERROR;
}

// ------------------------------------------------------------------------ END

额外支持

资源

喜欢这个项目吗?

'购买此套件' 按钮会直接带您进入购物车,您可以在购物车中轻松添加或移除产品。