cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F205 - UART5 Interrupt handler fail to receive interrupt

DA.1115
Associate II

Hi all, Thanks for the support and sharing the experience.

I have generated the code using STM32 CubeMx and using UART5 in interrupt mode. UART5 interrupt is configured to receive interrupt for every 1byte of data reception. Snap of the code is below.

Observation : UART interrupt handler function call stop after start some time

Kindly verify that UART interrupt function is implemented without any violation.

int main(void)
{
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_CAN1_Init();
  MX_CAN2_Init();
  MX_I2C1_Init();
  MX_I2C2_Init();
  MX_SPI1_Init();
  MX_TIM4_Init();
  MX_UART4_Init();
  MX_UART5_Init();
  MX_TIM10_Init();
  MX_USART6_UART_Init();
  MX_TIM14_Init();
  MX_RTC_Init();
  MX_TIM3_Init();
  /* USER CODE BEGIN 2 */
  
  HAL_UART_Receive_IT (&huart4, &g__MAIN_UART4_RxByte, DEF_MAIN_UART4_RX_BUFFER_SIZE);
  HAL_UART_Receive_IT (&huart6, &g__MAIN_UART6_RxByte, DEF_MAIN_UART6_RX_BUFFER_SIZE);
 
  //This method is to configure the UART5 Receiver in the non-blocking mode
  HAL_UART_Receive_IT(&huart5, &g__MAIN_UART5_RxByte, DEF_MAIN_UART5_RX_BUFFER_SIZE);
 
}
 
void UART5_IRQHandler(void)
{
  HAL_UART_IRQHandler(&huart5);
}
 
void HAL_UART_RxCpltCallback (UART_HandleTypeDef * huart)
{
 
  if(huart->Instance == UART4) 
  {
    //<Function call to store the received data>
 
    HAL_UART_Receive_IT (&huart4, &g__MAIN_UART4_RxByte, DEF_MAIN_UART4_RX_BUFFER_SIZE);
  }
  
  if(huart->Instance == USART6) 
  {
    //<Function call to store the received data>
	
    HAL_UART_Receive_IT (&huart6, &g__MAIN_UART6_RxByte, DEF_MAIN_UART6_RX_BUFFER_SIZE);
  }
  
  if(huart->Instance == UART5) 
  {
    //<Function call to store the received data>
	
    HAL_UART_Receive_IT (&huart5, &g__MAIN_UART5_RxByte, DEF_MAIN_UART5_RX_BUFFER_SIZE);
  }
}
 
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
{
  if(huart->Instance == USART6)
  {
 
  }else if(huart->Instance == UART4)
  {
 
  }else if(huart->Instance == UART5)
  {
    if(HAL_UART_GetError(huart) != HAL_UART_ERROR_NONE)
    {
      nErrorCode = HAL_UART_GetError(huart);
      State = HAL_UART_GetState(huart);
    }
  }
}

Additional Info:

I required to receive GPS data over UART (\r\n+QGPSGNMEA: $GPGGA,060418.00,1257.506345,N,07744.637410,E,1,03,3.0,889.6,M,-85.0,M,,*4F\r\n) periodically every 500millisecond and other messages as well.

5 REPLIES 5

Perhaps it is not receiving anything?

You're going to have to review functionality of all code, check peripheral and GPIO settings in the debugger. Make sure UART and pins are properly set up and clocked.

Try sending patterns with interrupts, confirm other aspects of the plumbing.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
DA.1115
Associate II

Hi Clive1, Thanks for the support and response.

Perhaps it is not receiving anything?

No, UART interrupt works for some time (5 bytes length data packet in the interval of 200millisecond is received) then stops receiving the interrupt.

I came across the this thread https://community.st.com/s/question/0D50X00009XkfrW/cubemx-uart-receive-complete-interrupt . Will this help me in resolving the issue.

>then stops receiving the interrupt

How do you know?

What are exactly the symptoms?

JW

DA.1115
Associate II

Dear waclawek.jan, Thanks for the support.

How do you know?

What are exactly the symptoms?

//Interrupt is cofigured to trigger on reception of 1 Byte of data
 
#define DEF_MAIN_UART5_RX_BUFFER_SIZE     1
uint8_t g__MAIN_UART5_RxByte  =  0;
 
 
void HAL_UART_RxCpltCallback (UART_HandleTypeDef * huart)
{
   if(huart->Instance == UART5) 
  {
    //<Function call to store the received data>
	
      /*****        TOGGLING LED HERE        *******/
	
    HAL_UART_Receive_IT (&huart5, &g__MAIN_UART5_RxByte, DEF_MAIN_UART5_RX_BUFFER_SIZE);
  }
}

Note : I am able to see LED blinking for some time and then stops even data is received in the UART Rx line

Piranha
Chief II

You have a simple choice:

  1. Continue debugging/fixing HAL non-working bloatware endlessly and never make a stable device.
  2. Develop an actually working driver on your own.

For the latter here are good instructions:

https://github.com/MaJerle/stm32-usart-uart-dma-rx-tx