Skip to main content
KMew
Senior III
September 15, 2022
Question

Enable RX0 Interrupts

  • September 15, 2022
  • 1 reply
  • 633 views

Hello,

I apologize for any obvious questions, but I am new to CAN and STM32 programming.

I have written a code that successfully sends CAN messages to a CANalyzer for data interpretation, so I believe I have enabled the CAN portion correctly. My next objective is to send a message from a CANalyzer to the MCU and have it turn an LED on when it properly received the message.

I am using an evaluation board (STM32H7B3I-EVAL).

I attached a copy of my main.c file.

What I would like to know is how to enable an RX interrupt handler so that I can receive CAN data.

What do I have to add to the main.c to make that happen?

This topic has been closed for replies.

1 reply

mƎALLEm
ST Technical Moderator
September 23, 2026

Hello,

In the attached main.c you’re receiving the CAN frames not in interrupt mode.

To do so you need to:

1- Enable one of the FDCAN NVIC interrupt lines (IT0 or IT1):

HAL_NVIC_SetPriority(FDCANx_IT0_IRQn, 0, 1);

HAL_NVIC_EnableIRQ(FDCANx_IT0_IRQn);

2- Activate the interrupt/notification for the RX FIFO 0:

HAL_CAN_ActivateNotification(&hfdcan1, CAN_IT_RX_FIFO0_MSG_PENDING)

3- Use the callback to read the received message:

void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
{
/* Get RX message */
if (HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &RxHeader, RxData) != HAL_OK)
{
/* Reception Error */
Error_Handler();
}
}

You can either refer to the examples in the H7 CubeHAL package over this link: https://github.com/STMicroelectronics/STM32CubeH7/tree/master/Projects/STM32H743I-EVAL/Examples/FDCAN/FDCAN_Com_IT

Or refer to this article: 

and its related Github hotspot: 

https://github.com/stm32-hotspot/CKB-STM32-FDCAN-8Mbs

Hope that helps you as well as others ..
 

 

 

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.