Hi all,
I am using the s32k118 MCU and need to interface with a CAN bus. I've been polling the CAN bus every 100ms with the CAN_Receive() function to retrieve any messages from the bus, but unfortunately I do miss a lot of messages, since there are more than one message on the bus every 100ms.
My end goal is to asynchronously add all received messages to a Queue of CAN messages, which I can parse periodically. I was hoping to accomplish this with a CAN Rx Interrupt, which would be triggered whenever the MCU detects a message on the bus. Unfortunately, I'm not able to set up such an ISR.
I've tried setting up an ISR with the interrupt_manager component, on the CAN0_ORed_0_31_MB_IRQn IRQ. But it seems my ISR is being triggered only after I call CAN_Receive() in my main() function. This does not meet my requirements, as I was hoping to all the CAN_Receive() function exclusively in the ISR. Furthermore, after being triggered once, the code appears to get stuck in continuously calling the ISR over and over.
I tried installing a callback function with CAN_InstallEventCallback(), but again, the callback function is only called after I call CAN_Receive() or CAN_Send(). So again, it doesn't seem like I can depend on the Callback to catch all messages from the bus.
Finally, I used the Rx FIFO feature, which does successfully add all messages to a the Mailbox 0 in a buffer-type format. This is what I need... except it's limited to a maximum of 6 messages.
I'm anticipating a need for ~16 messages to be buffered at a time.
To illustrate the issues I've faced with Polling, ISR and Callback, I've attached a "CAN_Example" project. Hope it serves to further clarify the problem.
How do I accomplish this task, of buffering incoming CAN messages for future parsing?
Solved! Go to Solution.
You can refer to the demo in the link below which shows how to receive or transmit CAN frames using MB or FIFO interrupts.
https://community.nxp.com/t5/S32K-Knowledge-Base/S32K1xx-FlexCAN-Mask-Setting-Demo/ta-p/1519753
You can refer to the demo in the link below which shows how to receive or transmit CAN frames using MB or FIFO interrupts.
https://community.nxp.com/t5/S32K-Knowledge-Base/S32K1xx-FlexCAN-Mask-Setting-Demo/ta-p/1519753
Thanks, that solves the issue!
Seems like the key point I'd missed was to call FLEXCAN_DRV_Receive(), FLEXCAN_DRV_RxFifo() or CAN_Receive() at least once on each Mailbox, for the Callback to work properly.