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.

This discussion is locked. Please start a new topic to ask your question.
3 REPLIES 3
Karl Yamashita
Principal

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 FIFO doesn't work, then it's called GIGO.
TimerCallback tutorial! | UART and DMA Idle with multiple UART instances tutorial!

If you find my solution useful, please click the Accept as Solution so others 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
Principal

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 FIFO doesn't work, then it's called GIGO.
TimerCallback tutorial! | UART and DMA Idle with multiple UART instances tutorial!

If you find my solution useful, please click the Accept as Solution so others see the solution.