cancel
Showing results for 
Search instead for 
Did you mean: 

How to receive CAN messages inside Timer interrupt.

SPeri.1
Associate II

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.

3 REPLIES 3
Karl Yamashita
Lead II

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 you find my answers useful, click the accept button so that way others can see the solution.

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
Lead II

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 you find my answers useful, click the accept button so that way others can see the solution.