cancel
Showing results for 
Search instead for 
Did you mean: 

CAN-BUS Rx callback triggered infinitely many times.

KMoe.1
Associate

Dear community,

I have setup a can-bus system between two devices where: the first transmits a message on button press using HAL_CAN_AddTxMessage, the other one receives the message using a callback interrupt. However, the following problem arises: once the second device receives the message the callback gets called infinitely many times. I would expect the callback function to be called once to read the message and then stop. What am I doing wrong?

This is how I initialize my can-bus on both devices:

MX_CAN_Init();
CAN_FilterConfig();
HAL_CAN_Start(&hcan);
HAL_CAN_ActivateNotification(&hcan, CAN_IT_TX_MAILBOX_EMPTY | CAN_IT_RX_FIFO0_MSG_PENDING); 

Inside the MX_CAN_Init I also initialize the MSP with HAL_CAN_MspInit(&hcan)

I enable the can-bus interrupts so that I have RX0_IRQHandler in the interrupt file.

In the main file I override the weak function callback so that it looks as follows:

void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) {
   if (HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &header_rx, msg_rx) == HAL_OK) { 
    // do something
   } 
}

Now the issue comes from the Rx message pending callback. This function is being triggered infinitely many times after receiving a message. However, I simply want it to read the message once and then stop so that it can read another message. Do I have to reset a specific interrupt flag or is this not the correct callback to receive messages? I tried searching for documentations but none of it is very clear.

Thank you for any help

0 REPLIES 0