Skip to main content
Blas Cabrera
Visitor II
March 23, 2018
Question

STM32F0 Callback function

  • March 23, 2018
  • 1 reply
  • 855 views
Posted on March 23, 2018 at 13:19

I am new to embedded world. I am activating the CANBUS peripheral of a STM32F0. I started from the example code of the device given by ST. In the example code there is a callback function that it is executed when the CAN peripheral receive a message (The device is interrupt mode, setup by CubeMX).:

void HAL_CAN_RxCpltCallback(CAN_HandleTypeDef *hcan)

{

// Read CANBUS Messages

StdId=hcan->pRxMsg->StdId;

Flag_CANext=hcan->pRxMsg->Data[0];

Data1=hcan->pRxMsg->Data[1];

npress = can_receive;

intcounter++;

//}

/* Receive */

if (HAL_CAN_Receive_IT(hcan, CAN_FIFO0) != HAL_OK)

{

/* Reception Error */

_Error_Handler(__FILE__, __LINE__);

}

}

The interrupt handler function is specified in the smt32f0xx_it.c file. I am getting confused between the role of the peripheral interrupt handler and the call complete function. My understanding is that the HAL_CAN_Recieive_IT has been already invoked. According to the code generated by CubeMX, which are the functions called during a CANBUS interrupt?

 CEC_CAN_IRQHandler(void) ->  HAL_CAN_RxCpltCallback(CAN_HandleTypeDef *hcan)

If I want to load the data of the CANBUS is a global variable of the main loop, where is the right place to load the data in the IRQ or Callback function? (as I am doing, shown by the code given above)

#stm32-interrupts
This topic has been closed for replies.

1 reply

Tesla DeLorean
Guru
March 23, 2018
Posted on March 23, 2018 at 13:38

The IRQHandler is what the processor goes too, it has code that calls into the HAL, and then the HAL calls your callback routine(s) as required in interrupt context. Your routine should do its work promptly, not block, and then leave.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..