TC397 CANFD 用例分析

目录

    • 前言
    • 位速率和采样点设置
    • Message RAM
    • 滤波器设置
    • 初始化部分代码汇总
    • Bus-Off中断处理
    • 发送函数
    • 接收中断处理
    • 测试
    • 微信公众号

前言

参考前几篇:

  • Jetson Xavier/XavierNX/TX2 CANFD 配置使用
  • STM32 CANFD 基础知识
  • STM32G474 CANFD 用例详解
  • STM32H750 更好用的CANFD 用例详解
  • AURIX TC397 CAN MCMCAN

本篇写TC397的CANFD的使用. TC397有3路MCMCAN组件(CAN0/1/2), 每路MCMCAN组件又支持4个节点, 所以, 共计支持12路CANFD, 资源如下, TC39x-B specific configuration of CAN:

Parameter CAN0 CAN1 CAN2
Node size in byte 1024 1024 1024
Number of CAN Nodes 4 4 4
Number of TTCAN Nodes 1
RAM size in byte 32768 16384 16384
Maximum Number of Standard ID Filter Messages per node 128 128 128
Maximum Number of Extended ID Filter Messages per node 64 64 64
Maximum Number of RxFIFO structures per node 2 2 2
Maximum Number of Messages in a Rx buffer per node 64 64 64
Maximum Number of Tx Event Messages per node 32 32 32
Maximum Number of Tx Messages in a Tx Buffer per node 32 32 32
Maximum number of trigger messages per TTCAN node 64

其中:

  • CAN0组件支持TTCAN
  • 正常每个MCMCAN组件4个节点(4路CANFD, M_CAN)共用的Message RAM大小为 16384 bytes = 4096 words = 16 KB, 相比之下, STM32H7所有FDCAN(目前最多3路)共用10KB

本篇使用TC397的CAN2中0~3节点中的CAN22, 连接到Xavier的CAN0, 仲裁段500K, 采样点0.8; 数据段2M, 采样点0.75.

位速率和采样点设置

TC397的相关计算:

    /*
     * Bit timing & sampling
     * Tq = (BRP+1)/Fcan if DIV8 = 0
     * Tq = 8*(BRP+1)/Fcan if DIV8 = 1
     * TSync = 1.Tq
     * TSeg1 = (TSEG1+1)*Tq                >= 3Tq
     * TSeg2 = (TSEG2+1)*Tq                >= 2Tq
     * Bit Time = TSync + TSeg1 + TSeg2    >= 8Tq
     *
     * Resynchronization:
     *
     * Tsjw = (SJW + 1)*Tq
     * TSeg1 >= Tsjw + Tprop
     * TSeg2 >= Tsjw
     */

主时钟频率来自IfxCan_getModuleFrequency()函数, 仿真或打印出来为 80MHz.

有两种方法设置位速率和采样点:

  • 设置 位速率, 采样点, SJW, calculateBitTimingValues设为True, 然后初始化节点函数中会自动计算位时间填入寄存器
  • 设置 BRP, TSEG1, TSEG2, SJW, calculateBitTimingValues设为False, 然后初始化节点函数中会直接把这些值填入寄存器

第一种的示例:

    g_mcmcan22.canNodeConfig.baudRate.baudrate = 500000;
    //10000*(1+TSeg1)/(1 + TSeg1 + TSeg2)     
    g_mcmcan22.canNodeConfig.baudRate.samplePoint = 10000*0.8;   
    //10000* TSeg2 / (1 + TSeg1 + TSeg2) = 10000 - samplePoint     
    g_mcmcan22.canNodeConfig.baudRate.syncJumpWidth = 2000;     
    g_mcmcan22.canNodeConfig.fastBaudRate.baudrate = 2000000;   
    g_mcmcan22.canNodeConfig.fastBaudRate.samplePoint = 10000*0.75;
    g_mcmcan22.canNodeConfig.fastBaudRate.syncJumpWidth = 2500;
    //TdcOffset default recommended value: DataTimeSeg1 * DataPrescaler
    g_mcmcan22.canNodeConfig.fastBaudRate.tranceiverDelayOffset = 28;
    g_mcmcan22.canNodeConfig.calculateBitTimingValues = TRUE;
	
	/*
    Ifx_Console_print(ENDLINE"moduleFreq: %.2f", IfxCan_getModuleFrequency());
    Ifx_Console_print(ENDLINE);

    Ifx_Console_print(ENDLINE"NBTP.B.NBRP = %d", g_mcmcan22.canNode.node->NBTP.B.NBRP);
    Ifx_Console_print(ENDLINE"NBTP.B.NSJW = %d", g_mcmcan22.canNode.node->NBTP.B.NSJW);
    Ifx_Console_print(ENDLINE"NBTP.B.NTSEG1 = %d", g_mcmcan22.canNode.node->NBTP.B.NTSEG1);
    Ifx_Console_print(ENDLINE"NBTP.B.NTSEG2 = %d", g_mcmcan22.canNode.node->NBTP.B.NTSEG2);
    Ifx_Console_print(ENDLINE);

    Ifx_Console_print(ENDLINE"DBTP.B.DBRP = %d", g_mcmcan22.canNode.node->DBTP.B.DBRP);
    Ifx_Console_print(ENDLINE"DBTP.B.DSJW = %d", g_mcmcan22.canNode.node->DBTP.B.DSJW);
    Ifx_Console_print(ENDLINE"DBTP.B.DTSEG1 = %d", g_mcmcan22.canNode.node->DBTP.B.DTSEG1);
    Ifx_Console_print(ENDLINE"DBTP.B.DTSEG2 = %d", g_mcmcan22.canNode.node->DBTP.B.DTSEG2);
    Ifx_Console_print(ENDLINE"DBTP.B.TDC = %d", g_mcmcan22.canNode.node->DBTP.B.TDC);
    Ifx_Console_print(ENDLINE"TDCR.B.TDCO = %d", g_mcmcan22.canNode.node->TDCR.B.TDCO);
    Ifx_Console_print(ENDLINE);
    */

    /*
     * moduleFreq   = 80000000.00
     * NBTP.B.NBRP   = 7
     * NBTP.B.NSJW   = 3
     * NBTP.B.NTSEG1 = 14
     * NBTP.B.NTSEG2 = 3
     * DBTP.B.DBRP   = 1
     * DBTP.B.DSJW   = 4
     * DBTP.B.DTSEG1 = 13
     * DBTP.B.DTSEG2 = 4
     * DBTP.B.TDC    = 1
     * TDCR.B.TDCO   = 28
    */

第二种的示例:

    //https://www.kvaser.com/support/calculators/can-fd-bit-timing-calculator/
    g_mcmcan22.canNodeConfig.baudRate.prescaler = 2 - 1;
    g_mcmcan22.canNodeConfig.baudRate.syncJumpWidth = 16 - 1;
    g_mcmcan22.canNodeConfig.baudRate.timeSegment1 = 63 - 1;
    g_mcmcan22.canNodeConfig.baudRate.timeSegment2 = 16 - 1;
    g_mcmcan22.canNodeConfig.fastBaudRate.prescaler = 2 - 1;
    g_mcmcan22.canNodeConfig.fastBaudRate.syncJumpWidth = 5 - 1;
    g_mcmcan22.canNodeConfig.fastBaudRate.timeSegment1 = 14 - 1;
    g_mcmcan22.canNodeConfig.fastBaudRate.timeSegment2 = 5 - 1;
    g_mcmcan22.canNodeConfig.fastBaudRate.tranceiverDelayOffset = 28;
    g_mcmcan22.canNodeConfig.calculateBitTimingValues = FALSE;

    /*
     * moduleFreq   = 80000000.00
     * NBTP.B.NBRP   = 1
     * NBTP.B.NSJW   = 15
     * NBTP.B.NTSEG1 = 62
     * NBTP.B.NTSEG2 = 15
     * DBTP.B.DBRP   = 1
     * DBTP.B.DSJW   = 4
     * DBTP.B.DTSEG1 = 13
     * DBTP.B.DTSEG2 = 4
     * DBTP.B.TDC    = 1
     * TDCR.B.TDCO   = 28
    */

用第二种时, iLLD TC39B Version: 1.0.1.12.0这个版本的IfxCan_Can_initNode()函数有点小bug, IfxCan_Can.c第140行由

IfxCan_Node_setFastBitTimingValues(nodeSfr, config->baudRate.syncJumpWidth, config->baudRate.timeSegment2, config->baudRate.timeSegment1, config->baudRate.prescaler);

改为

IfxCan_Node_setFastBitTimingValues(nodeSfr, config->fastBaudRate.syncJumpWidth, config->fastBaudRate.timeSegment2, config->fastBaudRate.timeSegment1, config->fastBaudRate.prescaler);

正常建议用第一种, 简单省心.

Message RAM

3个MCMCAN组件的起始和终止地址为:

Module Base Address End Address
CAN0 0xF0200000 0xF0208FFF
CAN1 0xF0210000 0xF0218FFF
CAN2 0xF0220000 0xF0228FFF

其中分配给Message RAM的空间为:

  • CAN0 Module的前0x8000 Bytes => 32768 Bytes 给了Message RAM
  • CAN1 Module的前0x4000 Bytes => 16384 Bytes 给了Message RAM
  • CAN2 Module的前0x4000 Bytes => 16384 Bytes 给了Message RAM

每个MCMCAN组件共4个节点所能使用的最大Message RAM资源如图所示:

TC397 CANFD 用例分析_第1张图片

如果全部元素都启用, 将占用 128 + 128 + 1152 + 1152 + 1152 + 64 + 576 + 128 = 4480 words = 17920 Bytes = 17.5KB, 超过了16384 bytes = 4096 words = 16 KB的最大Ram限制. 所以还是要有所取舍, 用到的分配, 不用的不分配.

下面会用到的参数总结如下:

  • 1 个 11-bit filter element => 1 words, 4个节点的11-bit filter element数量之和不超过128
  • 1 个 29-bit filter element => 2 words, 4个节点的29-bit filter element数量之和不超过64
  • 1 个 Rx FIFO 0 element => 18 words, 4个节点的Rx FIFO 0 element数量之和不超过64
  • 1 个 Tx Buffer element => 18 words, 4个节点的Tx Buffer element数量之和不超过32

0x4000 Bytes空间可以对四路CAN节点平均分配, 每路0x1000 Bytes, 所有资源也可以平分, 每路可以分:

  • 32 个 11-bit filter element
  • 16 个 29-bit filter element
  • 16 个 Rx FIFO 0 element
  • 16 个 Rx FIFO 1 element
  • 8 个 Tx Buffer element

当然一般不这么搞, 比如我这里只用了CAN22, 其它路不用, 完全可以分多点资源来用:

  • 32 个 11-bit filter elements
  • 16 个 29-bit filter elements
  • 20 个 Rx FIFO 0 elements
  • 20 个 Tx Buffer elements

对应的代码如下:

#define MODULE_CAN0_RAM    0xF0200000
#define MODULE_CAN1_RAM    0xF0210000
#define MODULE_CAN2_RAM    0xF0220000
#define NODE0_RAM_OFFSET   0x0
#define NODE1_RAM_OFFSET   0x1000
#define NODE2_RAM_OFFSET   0x2000
#define NODE3_RAM_OFFSET   0x3000

    g_mcmcan22.canNodeConfig.messageRAM.baseAddress = MODULE_CAN2_RAM;
    //Standard Frame, 32 elements => 32 words => 128 Bytes => 0x80
    g_mcmcan22.canNodeConfig.messageRAM.standardFilterListStartAddress = 0x0 + NODE2_RAM_OFFSET;
    //Extended Frame, 16 elements => 32 words => 128 Bytes => 0x80
    g_mcmcan22.canNodeConfig.messageRAM.extendedFilterListStartAddress = 0x80 + NODE2_RAM_OFFSET;
    //RxFIFO0, 20  elements => 360 words => 1440 Bytes => 0x5A0
    g_mcmcan22.canNodeConfig.messageRAM.rxBuffersStartAddress = 0x100 + NODE2_RAM_OFFSET;
    //Tx FIFO Buffers, 20  elements => 360 words => 1440 Bytes => 0x5A0
    g_mcmcan22.canNodeConfig.messageRAM.txBuffersStartAddress = 0x6A0 + NODE2_RAM_OFFSET;
    //Total: 128 + 128 + 1440 + 1440 = 3136 Bytes => 0xC40 Bytes

对应的资源分配如图所示:

TC397 CANFD 用例分析_第2张图片

滤波器设置

拿出1个标准帧滤波器+1个扩展帧滤波器, 用掩码的方式, 设置全接收到RxFIFO0中, 其它滤波器先不用:

    g_mcmcan22.canFilter.number = 0;
    g_mcmcan22.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxFifo0;
    g_mcmcan22.canFilter.type = IfxCan_FilterType_classic;
    g_mcmcan22.canFilter.id1 = 0;
    g_mcmcan22.canFilter.id2 = 0;
    g_mcmcan22.canFilter.rxBufferOffset = IfxCan_RxBufferId_0;
    IfxCan_Can_setStandardFilter(&(g_mcmcan22.canNode), &(g_mcmcan22.canFilter));

    g_mcmcan22.canFilter.number = 0;
    g_mcmcan22.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxFifo0;
    g_mcmcan22.canFilter.type = IfxCan_FilterType_classic;
    g_mcmcan22.canFilter.id1 = 0;
    g_mcmcan22.canFilter.id2 = 0;
    g_mcmcan22.canFilter.rxBufferOffset = IfxCan_RxBufferId_0;
    IfxCan_Can_setExtendedFilter(&(g_mcmcan22.canNode), &(g_mcmcan22.canFilter));

初始化部分代码汇总

#include "Ifx_Types.h"
#include "IfxCan_Can.h"
#include "IfxCan.h"

#define CAN22_TOS          IfxSrc_Tos_cpu0

#define MODULE_CAN0_RAM    0xF0200000
#define MODULE_CAN1_RAM    0xF0210000
#define MODULE_CAN2_RAM    0xF0220000
#define NODE0_RAM_OFFSET   0x0
#define NODE1_RAM_OFFSET   0x1000
#define NODE2_RAM_OFFSET   0x2000
#define NODE3_RAM_OFFSET   0x3000

#define MAXIMUM_CAN_DATA_PAYLOAD      16    //words

#define ISR_PRIORITY_CAN22_TX         121
#define ISR_PRIORITY_CAN22_RX         122
#define ISR_PRIORITY_CAN22_BUSOFF     135

typedef struct
{
    IfxCan_Can_Config canConfig;                /* CAN module configuration structure   */
    IfxCan_Can canModule;                       /* CAN module handle                    */
    IfxCan_Can_Node canNode;                    /* CAN source node handle data structure*/
    IfxCan_Can_NodeConfig canNodeConfig;        /* CAN node configuration structure     */
    IfxCan_Filter canFilter;                    /* CAN filter configuration structure   */
    IfxCan_Message txMsg;                       /* Transmitted CAN message structure    */
    IfxCan_Message rxMsg;                       /* Received CAN message structure       */
    uint32 txData[MAXIMUM_CAN_DATA_PAYLOAD];    /* Transmitted CAN data array           */
    uint32 rxData[MAXIMUM_CAN_DATA_PAYLOAD];    /* Received CAN data array              */
} McmcanType;

McmcanType g_mcmcan22;

void init_can22_fd(void)
{
    IfxCan_Can_initModuleConfig(&g_mcmcan22.canConfig, &MODULE_CAN2);
    IfxCan_Can_initModule(&g_mcmcan22.canModule, &g_mcmcan22.canConfig);
    IfxCan_Can_initNodeConfig(&g_mcmcan22.canNodeConfig, &g_mcmcan22.canModule);    //set default node value

    g_mcmcan22.canNodeConfig.nodeId = IfxCan_NodeId_2;  //4 node in 1 module
    g_mcmcan22.canNodeConfig.clockSource = IfxCan_ClockSource_both;

    g_mcmcan22.canNodeConfig.frame.type = IfxCan_FrameType_transmitAndReceive;
    g_mcmcan22.canNodeConfig.frame.mode = IfxCan_FrameMode_fdLongAndFast;  //CANFD Long Fast, FDF=1, BRS=1

    g_mcmcan22.canNodeConfig.txConfig.txMode = IfxCan_TxMode_fifo;
    g_mcmcan22.canNodeConfig.txConfig.txFifoQueueSize = 20;
    g_mcmcan22.canNodeConfig.txConfig.dedicatedTxBuffersNumber = 0;
    g_mcmcan22.canNodeConfig.txConfig.txEventFifoSize = 0;
    g_mcmcan22.canNodeConfig.txConfig.txBufferDataFieldSize = IfxCan_DataFieldSize_64;

    g_mcmcan22.canNodeConfig.rxConfig.rxMode = IfxCan_RxMode_fifo0;
    g_mcmcan22.canNodeConfig.rxConfig.rxFifo0Size = 20;
    g_mcmcan22.canNodeConfig.rxConfig.rxFifo0DataFieldSize = IfxCan_DataFieldSize_64;
    g_mcmcan22.canNodeConfig.rxConfig.rxFifo1Size = 0;
    g_mcmcan22.canNodeConfig.rxConfig.rxFifo1DataFieldSize = IfxCan_DataFieldSize_64;
    g_mcmcan22.canNodeConfig.rxConfig.rxBufferDataFieldSize = IfxCan_DataFieldSize_64;
    g_mcmcan22.canNodeConfig.rxConfig.rxFifo0WatermarkLevel = 0;    //event use
    g_mcmcan22.canNodeConfig.rxConfig.rxFifo1WatermarkLevel = 0;
    g_mcmcan22.canNodeConfig.rxConfig.rxFifo0OperatingMode = IfxCan_RxFifoMode_overwrite;   //or block
    g_mcmcan22.canNodeConfig.rxConfig.rxFifo1OperatingMode = IfxCan_RxFifoMode_overwrite;

    g_mcmcan22.canNodeConfig.filterConfig.messageIdLength = IfxCan_MessageIdLength_both;
    g_mcmcan22.canNodeConfig.filterConfig.standardListSize = 32;  //Standard Frame
    g_mcmcan22.canNodeConfig.filterConfig.extendedListSize = 16;  //Extended Frame
    g_mcmcan22.canNodeConfig.filterConfig.rejectRemoteFramesWithStandardId = TRUE;
    g_mcmcan22.canNodeConfig.filterConfig.rejectRemoteFramesWithExtendedId = TRUE;
    g_mcmcan22.canNodeConfig.filterConfig.standardFilterForNonMatchingFrames = IfxCan_NonMatchingFrame_reject;
    g_mcmcan22.canNodeConfig.filterConfig.extendedFilterForNonMatchingFrames = IfxCan_NonMatchingFrame_reject;

    //Message RAM
    g_mcmcan22.canNodeConfig.messageRAM.baseAddress = MODULE_CAN2_RAM;
    //Standard Frame, 32 elements => 32 words => 128 Bytes => 0x80
    g_mcmcan22.canNodeConfig.messageRAM.standardFilterListStartAddress = 0x0 + NODE2_RAM_OFFSET;
    //Extended Frame, 16 elements => 32 words => 128 Bytes => 0x80
    g_mcmcan22.canNodeConfig.messageRAM.extendedFilterListStartAddress = 0x80 + NODE2_RAM_OFFSET;
    //RxFIFO0, 20  elements => 360 words => 1440 Bytes => 0x5A0
    //g_mcmcan22.canNodeConfig.messageRAM.rxBuffersStartAddress = 0x100 + NODE2_RAM_OFFSET;
    g_mcmcan22.canNodeConfig.messageRAM.rxFifo0StartAddress = 0x100 + NODE2_RAM_OFFSET;
    //Tx FIFO Buffers, 20  elements => 360 words => 1440 Bytes => 0x5A0
    g_mcmcan22.canNodeConfig.messageRAM.txBuffersStartAddress = 0x6A0 + NODE2_RAM_OFFSET;
    //Total: 128 + 128 + 1440 + 1440 = 3136 Bytes

    //transmit interrupt
    g_mcmcan22.canNodeConfig.interruptConfig.transmissionCompletedEnabled = TRUE;
    g_mcmcan22.canNodeConfig.interruptConfig.traco.priority = ISR_PRIORITY_CAN22_TX;
    g_mcmcan22.canNodeConfig.interruptConfig.traco.interruptLine = IfxCan_InterruptLine_4;
    g_mcmcan22.canNodeConfig.interruptConfig.traco.typeOfService = CAN22_TOS;

    //receive interrupt
    g_mcmcan22.canNodeConfig.interruptConfig.rxFifo0NewMessageEnabled = TRUE;
    g_mcmcan22.canNodeConfig.interruptConfig.rxf0n.priority = ISR_PRIORITY_CAN22_RX;
    g_mcmcan22.canNodeConfig.interruptConfig.rxf0n.interruptLine = IfxCan_InterruptLine_5;
    g_mcmcan22.canNodeConfig.interruptConfig.rxf0n.typeOfService = CAN22_TOS;

    //bus-off interrupt
    g_mcmcan22.canNodeConfig.interruptConfig.busOffStatusEnabled = TRUE;
    g_mcmcan22.canNodeConfig.interruptConfig.boff.priority = ISR_PRIORITY_CAN22_BUSOFF;
    g_mcmcan22.canNodeConfig.interruptConfig.boff.interruptLine = IfxCan_InterruptLine_10;
    g_mcmcan22.canNodeConfig.interruptConfig.boff.typeOfService = CAN22_TOS;

    //clock: 80M
    g_mcmcan22.canNodeConfig.baudRate.baudrate = 500000;    
    g_mcmcan22.canNodeConfig.baudRate.samplePoint = 10000*0.8;         
    g_mcmcan22.canNodeConfig.baudRate.syncJumpWidth = 2000;
    g_mcmcan22.canNodeConfig.fastBaudRate.baudrate = 2000000;   
    g_mcmcan22.canNodeConfig.fastBaudRate.samplePoint = 10000*0.75;
    g_mcmcan22.canNodeConfig.fastBaudRate.syncJumpWidth = 2500;
    g_mcmcan22.canNodeConfig.fastBaudRate.tranceiverDelayOffset = 28;
    g_mcmcan22.canNodeConfig.calculateBitTimingValues = TRUE;

    IFX_CONST IfxCan_Can_Pins can22_pins = {
           &IfxCan_TXD22_P22_8_OUT,   IfxPort_OutputMode_pushPull,
           &IfxCan_RXD22E_P22_9_IN,   IfxPort_InputMode_pullUp,
           IfxPort_PadDriver_cmosAutomotiveSpeed4
    };
    g_mcmcan22.canNodeConfig.pins = &can22_pins;
    IfxCan_Can_initNode(&g_mcmcan22.canNode, &g_mcmcan22.canNodeConfig);

    //std filter 0
    g_mcmcan22.canFilter.number = 0;
    g_mcmcan22.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxFifo0;
    g_mcmcan22.canFilter.type = IfxCan_FilterType_classic;
    g_mcmcan22.canFilter.id1 = 0;
    g_mcmcan22.canFilter.id2 = 0;
    g_mcmcan22.canFilter.rxBufferOffset = IfxCan_RxBufferId_0;  //maybe need change
    IfxCan_Can_setStandardFilter(&(g_mcmcan22.canNode), &(g_mcmcan22.canFilter));

    g_mcmcan22.canFilter.number = 0;
    g_mcmcan22.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxFifo0;
    g_mcmcan22.canFilter.type = IfxCan_FilterType_classic;
    g_mcmcan22.canFilter.id1 = 0;
    g_mcmcan22.canFilter.id2 = 0;
    g_mcmcan22.canFilter.rxBufferOffset = IfxCan_RxBufferId_0;
    IfxCan_Can_setExtendedFilter(&(g_mcmcan22.canNode), &(g_mcmcan22.canFilter));

    g_mcmcan22.rxMsg.readFromRxFifo0 = TRUE;
}

Bus-Off中断处理

如果CANH, CANL短接, 或者和其它节点的传输速率/采样点不一致, 会引发Bus-Off, 初始化开启了Bus-Off中断, 发生Bus-Off时, 直接在中断中初始化节点:

IFX_INTERRUPT(can22IsrBusOffHandler, 0, ISR_PRIORITY_CAN22_BUSOFF);
void can22IsrBusOffHandler(void)
{
    IfxCan_Node_clearInterruptFlag(g_mcmcan22.canNode.node, IfxCan_Interrupt_busOffStatus);
    init_can22_fd();
}

发送函数

开启了ESI和BRS.

uint8 can22_send_fd(uint32 messageId, IfxCan_DataLengthCode lengthCode, uint32 t_data[])
{
    static uint8 i;
    //                         {0,1,2,3,4,5,6,7,8,12,16,20,24,32,48,64};
    //static uint8 dlc2len[]  ={1,1,1,1,1,2,2,2,2,3, 4, 5, 6, 8, 12,16};
    IfxCan_Can_initMessage(&g_mcmcan22.txMsg);

    //g_mcmcan22.txMsg.bufferNumber = 0;
    g_mcmcan22.txMsg.messageId = messageId;
    if(messageId < 0x800) {
        g_mcmcan22.txMsg.messageIdLength=IfxCan_MessageIdLength_standard;
    } else {
        g_mcmcan22.txMsg.messageIdLength=IfxCan_MessageIdLength_extended;
    }
    g_mcmcan22.txMsg.errorStateIndicator = TRUE;
    g_mcmcan22.txMsg.dataLengthCode = lengthCode;
    g_mcmcan22.txMsg.frameMode = IfxCan_FrameMode_fdLongAndFast;    //FDF=1, BRS=1
    g_mcmcan22.txMsg.storeInTxFifoQueue = TRUE;

    //for(i = 0; i < dlc2len(lengthCode); i++) {
    for(i = 0; i < IfxCan_Node_getDataLength(lengthCode); i++) {
        g_mcmcan22.txData[i] = t_data[i];
    }

    if(IfxCan_Status_notSentBusy ==
            IfxCan_Can_sendMessage(&g_mcmcan22.canNode, &g_mcmcan22.txMsg, &g_mcmcan22.txData[0]))
    {
        return 1;   //not send
    }
    return 0;   //send success
}

如果不习惯word数组的方式发送, 可以用byte数组拼凑:

    uint32 t_data[64];
    g_mcmcan22.txData[0] = (t_data[3]<<24) | (t_data[2]<<16) | (t_data[1]<<8) | t_data[0];
    g_mcmcan22.txData[1] = (t_data[7]<<24) | (t_data[6]<<16) | (t_data[5]<<8) | t_data[4];
    g_mcmcan22.txData[2] = ...
    ...

接收中断处理

初始化中滤波器设置了全接收到RxFIFO0, 开启了RxFIFO0新消息中断, 这里中断中第 0 word加1后, 返回:

IFX_INTERRUPT(can22IsrRxHandler, 0, ISR_PRIORITY_CAN22_RX);
void can22IsrRxHandler(void)
{
    IfxCan_Node_clearInterruptFlag(g_mcmcan22.canNode.node, IfxCan_Interrupt_rxFifo0NewMessage);
    //IfxCan_Node_clearRxBufferNewDataFlag(g_mcmcan22.canNode.node, g_mcmcan22.canFilter.rxBufferOffset);
    IfxCan_Can_readMessage(&g_mcmcan22.canNode, &g_mcmcan22.rxMsg, g_mcmcan22.rxData);

    ++g_mcmcan22.rxData[0];
    can22_send_fd(g_mcmcan22.rxMsg.messageId, g_mcmcan22.rxMsg.dataLengthCode, g_mcmcan22.rxData);
}

测试

每10ms发送20帧, 发送1000次共20000帧:

void core0_main(void)
{
    ...

    uint32 t_data1[16] = {0x0,        0x9ABCDEF0,
                          0x12345678, 0x9ABCDEF0,
                          0x12345678, 0x9ABCDEF0,
                          0x12345678, 0x9ABCDEF0,
                          0x12345678, 0x9ABCDEF0,
                          0x12345678, 0x9ABCDEF0,
                          0x12345678, 0x9ABCDEF0,
                          0x12345678, 0x98765430};

    while(1)
    {
        if(time_flag && t_data1[0]<1000) {
            time_flag = 0;
            ++t_data1[0];

            can22_send_fd(0x110, IfxCan_DataLengthCode_64, t_data1);
            can22_send_fd(0x109, IfxCan_DataLengthCode_64, t_data1);
            can22_send_fd(0x108, IfxCan_DataLengthCode_64, t_data1);
            can22_send_fd(0x107, IfxCan_DataLengthCode_64, t_data1);
            can22_send_fd(0x106, IfxCan_DataLengthCode_64, t_data1);
            can22_send_fd(0x105, IfxCan_DataLengthCode_64, t_data1);
            can22_send_fd(0x104, IfxCan_DataLengthCode_64, t_data1);
            can22_send_fd(0x103, IfxCan_DataLengthCode_64, t_data1);
            can22_send_fd(0x102, IfxCan_DataLengthCode_64, t_data1);
            can22_send_fd(0x101, IfxCan_DataLengthCode_64, t_data1);

            can22_send_fd(0x12345679, IfxCan_DataLengthCode_64, t_data1);
            can22_send_fd(0x12345678, IfxCan_DataLengthCode_64, t_data1);
            can22_send_fd(0x12345677, IfxCan_DataLengthCode_64, t_data1);
            can22_send_fd(0x12345676, IfxCan_DataLengthCode_64, t_data1);
            can22_send_fd(0x12345675, IfxCan_DataLengthCode_64, t_data1);
            can22_send_fd(0x12345674, IfxCan_DataLengthCode_64, t_data1);
            can22_send_fd(0x12345673, IfxCan_DataLengthCode_64, t_data1);
            can22_send_fd(0x12345672, IfxCan_DataLengthCode_64, t_data1);
            can22_send_fd(0x12345671, IfxCan_DataLengthCode_64, t_data1);
            can22_send_fd(0x12345670, IfxCan_DataLengthCode_64, t_data1);

            //will lost
            //can22_send_fd(0x12345671, t_data1);

        }
    }
}

把TC397的的CAN22连到Xavier的CAN0上, Xavier CAN0设置:

#!/bin/sh

sudo modprobe can
sudo modprobe can_raw
sudo modprobe mttcan

sudo ip link set down can0
sudo ip link set can0 type can bitrate 500000 sample-point 0.8 dbitrate 2000000 dsample-point 0.75 fd on restart-ms 100
sudo ip link set up can0 
sudo ifconfig can0 txqueuelen 1000

Xavier也是仲裁段500Kbit/s, 采样点0.8, 数据段2Mbit/s, 采样点0.75.

restart-ms 100设置总线Bus-Off时, 100ms后重启.

设置完后查看设置状态 ip -details -statistics link show can0.

使用 candump -ta -x can0 >50.dat, 这里-ta显示绝对时间, 然后下载程序运行, 上面的20000帧数据全部存到50.dat文件中了, 共计20000行这里截取首尾部分显示:

 (1614240518.371442)  can0  RX B E  110  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240518.371720)  can0  RX B E  109  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240518.372054)  can0  RX B E  108  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240518.372375)  can0  RX B E  107  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240518.372724)  can0  RX B E  106  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240518.373140)  can0  RX B E  105  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240518.373401)  can0  RX B E  104  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240518.373743)  can0  RX B E  103  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240518.374080)  can0  RX B E  102  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240518.374469)  can0  RX B E  101  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240518.374806)  can0  RX B E  12345679  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240518.375181)  can0  RX B E  12345678  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240518.375562)  can0  RX B E  12345677  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240518.375943)  can0  RX B E  12345676  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240518.376318)  can0  RX B E  12345675  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240518.376696)  can0  RX B E  12345674  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240518.377076)  can0  RX B E  12345673  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240518.377457)  can0  RX B E  12345672  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240518.377831)  can0  RX B E  12345671  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240518.378210)  can0  RX B E  12345670  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240518.381356)  can0  RX B E       110  [64]  02 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240518.381692)  can0  RX B E       109  [64]  02 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 
 ...

 (1614240528.360043)  can0  RX B E  12345670  [64]  E7 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240528.363191)  can0  RX B E       110  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240528.363530)  can0  RX B E       109  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240528.363872)  can0  RX B E       108  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240528.364214)  can0  RX B E       107  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240528.364589)  can0  RX B E       106  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240528.364922)  can0  RX B E       105  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240528.365249)  can0  RX B E       104  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240528.365582)  can0  RX B E       103  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240528.365922)  can0  RX B E       102  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240528.366264)  can0  RX B E       101  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240528.366642)  can0  RX B E  12345679  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240528.367020)  can0  RX B E  12345678  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240528.367398)  can0  RX B E  12345677  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240528.367776)  can0  RX B E  12345676  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240528.368154)  can0  RX B E  12345675  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240528.368532)  can0  RX B E  12345674  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240528.368909)  can0  RX B E  12345673  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240528.369289)  can0  RX B E  12345672  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240528.369666)  can0  RX B E  12345671  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
 (1614240528.370065)  can0  RX B E  12345670  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98

Xavier发送脚本, ##后面的3表示开启BRS和ESI:

#!/bin/sh

while true; do
    cansend can0 18FF0001##3.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16
    cansend can0 18FF0002##3.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16
    cansend can0 18FF0003##3.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16  
    cansend can0 18FF0004##3.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16
    cansend can0 18FF0005##3.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16
    cansend can0 18FF0006##3.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16  
    cansend can0 123##3.00.02
    cansend can0 123##1.00.00
    sleep 1
done

运行后查看接收:

$ candump -ta -x can0
 (1614241024.270962)  can0  TX B E  18FF0001  [64]  01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
 (1614241024.271395)  can0  RX B E  18FF0001  [64]  02 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
 (1614241024.273719)  can0  TX B E  18FF0002  [64]  01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
 (1614241024.274188)  can0  RX B E  18FF0002  [64]  02 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
 (1614241024.276424)  can0  TX B E  18FF0003  [64]  01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
 (1614241024.276864)  can0  RX B E  18FF0003  [64]  02 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
 (1614241024.280558)  can0  TX B E  18FF0004  [64]  01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
 (1614241024.281040)  can0  RX B E  18FF0004  [64]  02 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
 (1614241024.286257)  can0  TX B E  18FF0005  [64]  01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
 (1614241024.286719)  can0  RX B E  18FF0005  [64]  02 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
 (1614241024.289169)  can0  TX B E  18FF0006  [64]  01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
 (1614241024.289623)  can0  RX B E  18FF0006  [64]  02 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
 (1614241024.291607)  can0  TX B E       123  [02]  00 02
 (1614241024.291688)  can0  RX B E       123  [02]  01 02
 (1614241024.293145)  can0  TX B -       123  [02]  00 00
 (1614241024.293243)  can0  RX B E       123  [02]  01 00

收到后立即返回.

微信公众号

欢迎扫描二维码关注本人微信公众号, 及时获取或者发送给我最新消息:
在这里插入图片描述

你可能感兴趣的:(Infineon,AURIX,TC397,AURIX,TRICORE,TC397,CANFD,FDCAN)