cancel
Showing results for 
Search instead for 
Did you mean: 

UART overrrun error while using STM32L476RG nucleo Board

PPati.18
Associate II

I am running my code on an STM32L476RG which generates a UART interrupt every time it receives data. I am using UART2 for this purpose and USART1_IRQHandler is called after I send data from my terminal. But inside  HAL_UART_IRQHandler, my code gets stuck on an overrun error interrupt. What is the reason for this? I've been pulling my hair trying to figure out the source of the problem.

Here is my code - UART configuration -

static void MX_USART1_UART_Init(void)

{

 huart1.Instance = USART1;

 huart1.Init.BaudRate = 9600;

 huart1.Init.WordLength = UART_WORDLENGTH_8B;

 huart1.Init.StopBits = UART_STOPBITS_1;

 huart1.Init.Parity = UART_PARITY_NONE;

 huart1.Init.Mode = UART_MODE_TX_RX;

 huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;

 huart1.Init.OverSampling = UART_OVERSAMPLING_8;

 huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;

 huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

 if (HAL_UART_Init(&huart1) != HAL_OK)

 {

  Error_Handler();

 }

 /* Peripheral interrupt init*/

 HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);

 HAL_NVIC_EnableIRQ(USART1_IRQn);

}

Main .c

int main(void)

{

 HAL_Init();

 SystemClock_Config();

 MX_GPIO_Init();

 MX_I2C1_Init();

 HAL_I2C_MspInit(&hi2c1);

 MX_USART1_UART_Init();

 HAL_UART_Receive_IT(&huart1,rx_data,sizeof(rx_data));

while(1){}

}

void USART1_IRQHandler(void)

{

  HAL_UART_IRQHandler(&huart1);

}

///* This callback is called by the HAL_UART_IRQHandler when the given number of bytes are received */

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

{

  if (huart->Instance == USART1)

 {

 if(strlen(rx_data) > 3){

   /* Transmit one byte with 100 ms timeout */

   HAL_UART_Transmit(&huart1, rx_data, strlen(rx_data), 100);

 }

  /* Receive one byte in interrupt mode */

  HAL_UART_Receive_IT(&huart1, rx_data, strlen(rx_data));

 }

 rx_data[0]= '\0';

}

1 REPLY 1
PPati.18
Associate II

Interrupt handler-