中级
30 分钟

使用 TCAN4550 和 STM32L496AG 体验超快 CAN 连接

闪电般快速的通信

CAN FD 6 Click with Discovery kit with STM32L496AG MCU

已发布 7月 22, 2025

点击板

CAN FD 6 Click

开发板

Discovery kit with STM32L496AG MCU

编译器

NECTO Studio

微控制器单元

STM32L496AG

我们专为高速卓越设计的CAN FD收发器在汽车和工业系统中提供无与伦比的性能。

A

A

硬件概览

它是如何工作的?

CAN FD 6 Click基于TCAN4550,这是一款支持CAN和CAN FD协议的CAN收发器,提供德州仪器(Texas Instruments)从CAN总线到CAN协议控制器的接口,最高支持5兆比特每秒(Mbps)。它具有高带宽和数据速率灵活性,提供CAN总线与系统处理器之间的SPI接口,并支持通过CAN总线的本地和总线唤醒功能。该设备包括多种保护功能,以提供CAN总线的鲁棒性,包括故障安全模式、内部主导状态超时和宽总线工作范围。TCAN4550具有一个用于从睡眠模式唤醒设备的引脚。此引脚连接到标记为WAKE的外部按钮和标记为WKP的mikroBUS™插座的PWM引脚,以生成本地唤醒功能。CAN总线上的唤醒事件将使抑制输出引脚INH切换到高电平。INH引脚提供了一个内部开关,连接到电池电源电压,并控制外部电压调节

器Microchip的MCP1804。通过标记为3V3JMP和5VJMP的SMD跳线,LDO的输出电压可以为mikroBUS™ 3.3V和5V电源轨供电。然而,Mikroe不建议以这种方式为他们的系统供电,这就是为什么默认情况下这些跳线没有填充的原因。CAN FD 6 Click通过标准SPI接口与MCU通信,支持高达18MHz的时钟速率,用于传输和接收CAN帧。借助额外的40MHz晶振,TCAN4550可以满足高达5Mbps数据速率的CAN FD速率,以支持更高的数据吞吐量,并通过板右侧的6V至24V外部电源供电头进行操作。这一功能使TCAN4550设备非常适合包括汽车在内的许多应用。此Click板™配备了行业标准的DB-9连接器,使与CAN总线的接口简单易行。此外,用户可以通过板左侧边缘的CAN外部头直接连接CAN信号。除了这些功能,

TCAN4550还使用了几个连接到mikroBUS™插座的GPIO引脚。RST引脚和mikroBUS™可以执行硬件复位功能,将设备重置为默认设置并进入待机模式。此功能也可以通过板载标记为RST的按钮实现。除了这些引脚,ATA6571使用WKR引脚作为总线唤醒请求的专用唤醒请求引脚,使用INT引脚作为中断功能,连接到mikroBUS™插座的AN和INT引脚。用户还可以使用板右侧头上的GPIO引脚用于中断目的。此Click板™可以通过VIO SEL跳线选择3.3V和5V逻辑电压电平运行。它允许具有3.3V和5V功能的MCU正确使用UART通信线路。然而,Click板™配备了一个库,包含易于使用的函数和示例代码,可作为进一步开发的参考。

CAN FD 6 Click hardware overview image

功能概述

开发板

32L496GDISCOVERY Discovery 套件是一款功能全面的演示和开发平台,专为搭载 Arm® Cortex®-M4 内核的 STM32L496AG 微控制器设计。该套件适用于需要在高性能、先进图形处理和超低功耗之间取得平衡的应用,支持无缝原型开发,适用于各种嵌入式解决方案。STM32L496AG 采用创新的节能架构,集成

了扩展 RAM 和 Chrom-ART 图形加速器,在提升图形性能的同时保持低功耗,使其特别适用于音频处理、图形用户界面和实时数据采集等对能效要求较高的应用。为了简化开发流程,该开发板配备了板载 ST-LINK/V2-1 调试器/编程器,提供即插即用的调试和编程体验,使用户无需额外硬件即可轻松加载、调

试和测试应用程序。凭借低功耗特性、增强的内存能力以及内置调试工具,32L496GDISCOVERY 套件是开发先进嵌入式系统、实现高效能解决方案的理想选择。

Discovery kit with STM32L496AG MCU double side image

微控制器概述 

MCU卡片 / MCU

STM32L496AG Image

建筑

ARM Cortex-M4

MCU 内存 (KB)

1024

硅供应商

STMicroelectronics

引脚数

169

RAM (字节)

327680

你完善了我!

配件

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

CAN FD 6 Click accessories image

使用的MCU引脚

mikroBUS™映射器

Wake Request
PA4
AN
Reset
PB2
RST
SPI Chip Select
PG11
CS
SPI Clock
PI1
SCK
SPI Data OUT
PD3
MISO
SPI Data IN
PI3
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Wake Up
PA0
PWM
Interrupt
PH2
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

CAN FD 6 Click Schematic schematic

一步一步来

项目组装

Discovery kit with STM32H750XB MCU front image hardware assembly

从选择您的开发板和Click板™开始。以Discovery kit with STM32L496AG MCU作为您的开发板开始。

Discovery kit with STM32H750XB MCU front image hardware assembly
Thermo 21 Click front image hardware assembly
Prog-cut hardware assembly
Thermo 21 Click complete accessories setup image hardware assembly
Board mapper by product7 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
Discovery kit with STM32H750XB MCU NECTO MCU Selection Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto image step 11 hardware assembly

软件支持

库描述

该库包含 CAN FD 6 Click 驱动程序的 API。

关键功能:

  • canfd6_mcan_write_txbuffer - 此功能将CAN消息写入指定的TX缓冲区,以便稍后通过发送缓冲区内容功能进行传输。

  • canfd6_mcan_transmit_buffer_contents - 此功能将指定的缓冲区索引位值写入TXBAR寄存器,以请求发送消息。

  • canfd6_mcan_read_nextfifo - 此功能将读取指定的下一个MCAN FIFO元素,并返回相应的头信息和数据负载。

开源

代码示例

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

/*!
 * @file main.c
 * @brief CANFD6 Click example
 *
 * # Description
 * This application presents the capabilities of the
 * CAN FD 6 Click board. The board can be used both
 * as a receiver and a transmitter. Use def directive
 * to define the receive or transmit app.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * The app starts by initializing the UART LOG and
 * SPI drivers. The default cfg function performs the
 * mandatory settings of the device. The user's default
 * configuration can be modified ( for more information
 * about device configuration, check the datasheet ).
 * Additionally, the app writes two messages to the FIFO
 * buffer and sends them if the transmit buffer content
 * event is triggered.
 *
 * ## Application Task
 * Depending on the defined app option, the application
 * task performs the following procedure. If the transmitter
 * is preferred, the application task triggers the transmit
 * buffer contents event of the first message and, later on,
 * the second message. On the other hand, the receiver waits
 * for the CAN FD interrupt, where the payload is read along
 * with the header ID.
 *
 * @author Stefan Nikolic
 *
 */

#include "board.h"
#include "log.h"
#include "canfd6.h"

// Comment out the line below in order to switch the application mode to receiver
#define DEMO_APP_TRANSMITTER

#define CANFD6_FIRST_MSG                        0
#define CANFD6_SECOND_MSG                       1

static canfd6_t canfd6;
static log_t logger;

void application_init ( void ) {
    log_cfg_t log_cfg;        /**< Logger config object. */
    canfd6_cfg_t canfd6_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.
    canfd6_cfg_setup( &canfd6_cfg );
    CANFD6_MAP_MIKROBUS( canfd6_cfg, MIKROBUS_1 );
    err_t init_flag = canfd6_init( &canfd6, &canfd6_cfg );
    if ( init_flag == SPI_MASTER_ERROR ) {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }

    canfd6_default_cfg( &canfd6 );
    Delay_ms ( 100 );
#ifdef DEMO_APP_TRANSMITTER
    canfd6_mcan_tx_header_t canfd6_header = { 0 };
    uint8_t data_send_buf[ 64 ] = { 0 };
    strcpy ( data_send_buf, "MIKROE" );
    canfd6_header.DLC = CANFD6_MCAN_DLC_6B;
    canfd6_header.ID = 0x123;
    canfd6_header.FDF = 1;
    canfd6_header.BRS = 1;
    canfd6_header.EFC = 0;
    canfd6_header.MM  = 0;
    canfd6_header.RTR = 0;
    canfd6_header.XTD = 0;
    canfd6_header.ESI = 0;
    canfd6_mcan_write_txbuffer( &canfd6, CANFD6_FIRST_MSG, &canfd6_header, data_send_buf );

    strcpy ( data_send_buf, "CAN FD 6 Click board" );
    canfd6_header.DLC = CANFD6_MCAN_DLC_20B;
    canfd6_header.ID = 0x456;
    canfd6_header.FDF = 1;
    canfd6_header.BRS = 1;
    canfd6_header.EFC = 0;
    canfd6_header.MM  = 0;
    canfd6_header.RTR = 0;
    canfd6_header.XTD = 0;
    canfd6_header.ESI = 0;
    canfd6_mcan_write_txbuffer( &canfd6, CANFD6_SECOND_MSG, &canfd6_header, data_send_buf );
    log_printf( &logger, " Application Mode: Transmitter\r\n" );
#else
    log_printf( &logger, " Application Mode: Receiver\r\n" );
#endif
    log_info( &logger, " Application Task " );
}

void application_task ( void ) {
#ifdef DEMO_APP_TRANSMITTER
    log_printf( &logger, " Transmit first message\r\n" );
    canfd6_mcan_transmit_buffer_contents( &canfd6, CANFD6_FIRST_MSG );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    log_printf( &logger, " Transmit second message\r\n" );
    canfd6_mcan_transmit_buffer_contents( &canfd6, CANFD6_SECOND_MSG );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
#else
    uint8_t cnt = 0;
    if ( !canfd6_get_int_pin( &canfd6 ) ) {
        canfd6_device_interrupts_t canfd6_dev_ir = { 0 };
        canfd6_mcan_interrupts_t canfd6_mcan_ir = { 0 };
        canfd6_device_read_interrupts( &canfd6, &canfd6_dev_ir );
        canfd6_mcan_read_interrupts( &canfd6, &canfd6_mcan_ir );

        if ( canfd6_dev_ir.SPIERR ) {
            canfd6_device_clear_spierr( &canfd6 );
        }

        if ( canfd6_mcan_ir.RF0N ) {
            canfd6_mcan_rx_header_t canfd6_msg_header = { 0 };
            uint8_t num_bytes = 0;
            uint8_t data_payload[ 64 ] = { 0 };

            canfd6_mcan_clear_interrupts( &canfd6, &canfd6_mcan_ir );

            num_bytes = canfd6_mcan_read_nextfifo( &canfd6, CANFD6_RXFIFO0, &canfd6_msg_header, data_payload );
            
            log_printf( &logger, " Message received ID[ 0x%X ]: ", canfd6_msg_header.ID );

            while ( cnt < 64 ) {
                if ( data_payload[ cnt ] ) {
                    log_printf( &logger, "%c", data_payload[ cnt ] );
                    cnt++;
                } else {
                    log_printf( &logger, "\r\n" );
                    cnt = 64;
                }
            }
        }
    }
#endif
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

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

额外支持

资源

喜欢这个项目吗?

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