I am using S32DS 2.2 with S32K116. Occasionally FLEXCAN does not receive messages but transmitting works fine. This occurs when there is a lot of bus traffic (10% to 50%) during initialization. Initializing twice does not fix the problem. But de-initializing FLEXCAN and then re-initializing fixes the problem. I have traced the problem to the order in which mailbox mask and id are set.
The following causes the problem:
/* Initialize CAN driver as configured by processor expert */
FLEXCAN_DRV_Init(INST_CANCOM1, &canCom1_State, &canCom1_InitConfig0);
/*enabling individual mask types sets all mailboxes to accept all CAN IDs */
FLEXCAN_DRV_SetRxMaskType(INST_CANCOM1, FLEXCAN_RX_MASK_INDIVIDUAL);
FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1, MAILBOX_0, &dataInfo, DM13_RX_ID);
FLEXCAN_DRV_SetRxIndividualMask(INST_CANCOM1, FLEXCAN_MSG_ID_EXT, MAILBOX_0, ACCEPT_ANY_PRIORITY);
The following fixes the problem:
/* Initialize CAN driver as configured by processor expert */
FLEXCAN_DRV_Init(INST_CANCOM1, &canCom1_State, &canCom1_InitConfig0);
/*enabling individual mask types sets all mailboxes to accept all CAN IDs */
FLEXCAN_DRV_SetRxMaskType(INST_CANCOM1, FLEXCAN_RX_MASK_INDIVIDUAL);
/*must set mask first. Otherwise, an unexpected Rx message will kill initialization. */
FLEXCAN_DRV_SetRxIndividualMask(INST_CANCOM1, FLEXCAN_MSG_ID_EXT, MAILBOX_0, ACCEPT_ANY_PRIORITY);
FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1, MAILBOX_0, &dataInfo, DM13_RX_ID);
Is this the correct solution? What is causing the problem? Why does CAN activity cause a problem when FLEXCAN_DRV_Receive hasn't been invoked yet?