AnsweredAssumed Answered

How does FlexCAN CAN-ID matching mechanism work ?

Question asked by Johannes Bruder on Apr 30, 2019
Latest reply on May 6, 2019 by Mark Butcher

Hi All,

 

I followed the provided SDK examples for CAN and I initialized the FlexCAN-Driver in my own example like shown below:

 

...

    flexcan_config_t flexcanConfig;
    flexcan_rx_mb_config_t mbConfig;



    txIdentifier = 0x080;
    rxIdentifier = 0x0A0;


    /* Get FlexCAN module default Configuration. */
    /*
     * flexcanConfig.clkSrc = kFLEXCAN_ClkSrcOsc;
     * flexcanConfig.baudRate = 1000000U;
     * flexcanConfig.maxMbNum = 16;
     * flexcanConfig.enableLoopBack = false;
     * flexcanConfig.enableSelfWakeup = false;
     * flexcanConfig.enableIndividMask = false;
     * flexcanConfig.enableDoze = false;
     * flexcanConfig.timingConfig = timingConfig;
     */

    FLEXCAN_GetDefaultConfig(&flexcanConfig);
    flexcanConfig.baudRate = 500000U;
    flexcanConfig.clkSrc = kFLEXCAN_ClkSrcPeri;


    /* Init FlexCAN module. */
    FLEXCAN_Init(PE900_CAN, &flexcanConfig, PE900_CAN_CLK_FREQ);


    /* Create FlexCAN handle structure and set call back function. */
    FLEXCAN_TransferCreateHandle(PE900_CAN, &flexcanHandle, flexcan_callback, NULL);


    /* Set Rx Masking mechanism. */
    FLEXCAN_SetRxMbGlobalMask(PE900_CAN, FLEXCAN_RX_MB_STD_MASK(rxIdentifier, 0, 0));


    /* Setup Rx Message Buffer. */
    mbConfig.format = kFLEXCAN_FrameFormatStandard;
    mbConfig.type = kFLEXCAN_FrameTypeData;
    mbConfig.id = FLEXCAN_ID_STD(rxIdentifier);
    FLEXCAN_SetRxMbConfig(PE900_CAN, RX_MESSAGE_BUFFER_NUM, &mbConfig, true);


    /* Setup Tx Message Buffer. */
    FLEXCAN_SetTxMbConfig(PE900_CAN, TX_MESSAGE_BUFFER_NUM, true);


    txframe.dataByte0 = 0x0F;
    txframe.dataByte1 = 0xFF;
    txframe.dataByte2 = 0x0F;
    txframe.dataByte3 = 0xFF;
    txframe.dataByte4 = 0x01;


    /* Start receiving and wait for can messages */
    rxXfer.mbIdx = RX_MESSAGE_BUFFER_NUM;
    rxXfer.frame = &rxframe;
    FLEXCAN_TransferReceiveNonBlocking(PE900_CAN, &flexcanHandle, &rxXfer);
...

 

I would expect that now only frames with CAN-ID 0x0A0 will be received but instead a lot of other ID's will be received all from 0xA0 to 0xBF.  I think relevant steps are:

    /* Set Rx Masking mechanism. */
    FLEXCAN_SetRxMbGlobalMask(PE900_CAN, FLEXCAN_RX_MB_STD_MASK(rxIdentifier, 0, 0));

and

    mbConfig.id = FLEXCAN_ID_STD(rxIdentifier);

 

The second step is clear, nothing can be done wrongly here. But I would think the first step enables generally ID's but its usage is really clear to me. At this point the source code is also not documented well, no comment explains the meaning of rtr, ide.  See:

/*! @brief FlexCAN Rx Message Buffer Mask helper macro. */
#define FLEXCAN_RX_MB_STD_MASK(id, rtr, ide)

Fall back to the reference manual helps me also not really.

 

How to setup the flexCAN driver to receive messages only from one CAN-ID ?

 

Any help is welcome !

Outcomes