Skip to main content
SPeri.1
Associate II
May 30, 2023 4:22 AM UTC
Question

How to receive CAN messages inside Timer interrupt.

I use STM32F105RCT6, Where I need to receive CAN data inside a timer interrupt. Also, the IRQ number of the CAN is lower than that of the timer. CAN message is filled to the FIFO0 but "HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan1)" is not called back. I can get data by calling "HAL_CAN_GetRxMessage(hcan1, CAN_RX_FIFO0,&RxHeader1, RxData1)" inside the code.

This topic has been closed for replies.

3 replies

Karl Yamashita
Super User
May 31, 2023 2:09 AM UTC

It's not clear why you want to receive CAN data inside of a timer interrupt? Are you trying to request data from another node at a specific time?

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
SPeri.1
SPeri.1Author
Associate II
Jun 4, 2023 5:43 PM UTC

I'm transmitting two CAN messages inside a timer. After the first one is transferred, wait for a reply from another device to go to the subsequent transmission.

Karl Yamashita
Super User
Jun 4, 2023 5:58 PM UTC

You need to set a flag in the timer interrupt then exit it. Then in main while loop you check the flag then send your first message. When you receive a CAN interrupt you save the data, set a flag indicating you have a new CAN message. Then in main while loop you parse the CAN message and if it's a match you send the 2nd CAN message.

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source