I have this simple CAN send and receive routine running every 100ms:
if (STATUS_SUCCESS == FLEXCAN_DRV_Send(INST_HSCAN, 8, &data_info, 0x123, txBuff))
FLEXCAN_DRV_RxFifoBlocking(INST_HSCAN, &rxBuff, 100);
This works fine on a stable, active CAN bus network. But I need to be able to recover and continue communication if the CAN bus is temporarily physically disconnected and then reconnected.
When I pull the connector to my CAN bus, the routine keeps running, but when I reconnect the CAN bus connector, the program triggers CAN0_ORed_0_15_MB_IRQHandler() and gets caught inside FLEXCAN_DRV_IRQHandler().
Any idea why this is happening and either how I can prevent it or break out of it?
You get CAN0_ORed_0_15_MB_IRQHandler triggered because the message is already in internal MB and set to send when you reconnect the bus it will send it and trigger the interrupt for complete action of the MB.
You can install the rutine for error of the BUS with FLEXCAN_DRV_InstallErrorCallback and get the status of the bus with FLEXCAN_DRV_GetErrorStatus. More details can be found in this thread s23k144 CAN_ESR1 is not working properly
You can get the status of the bus with FLEXCAN_DRV_GetErrorStatus which will return the value of ESR1 and if is not idle and sync you can issue an transfer abort FLEXCAN_DRV_AbortTransfer on the MB configured to send.
This functionality is available on the latest release for S32 SDK K14x BETA 1.9.0.