cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_UART_Receive_IT returns error

duybienle
Associate II
Posted on August 04, 2016 at 09:48

Hi, I want to transmit something from PC to uC and I put UART in receive mode. However HAL_UART_Receive_IT keeps returning error, and I don't know why?

My code is really simple:

int main(void)

{

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */

HAL_Init();

SystemClock_Config();

MX_GPIO_Init();

MX_USART2_UART_Init();

while (1)

{

uartStatus = HAL_UART_Receive_IT(&huart2, (uint8_t *)aRxBuffer, 10);

if(uartStatus != HAL_OK)

{

Error_Handler();

}

}

}

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)

{

/* Set transmission flag: transfer complete */

}

I let the code rund and did not send anything from PC. After a few loop cycles, the

uartStatus becomes

BUSY and

error_handle() occurs.

How to solve this problem ?

Thanks

Bien

1 REPLY 1
Walid FTITI_O
Senior II
Posted on August 22, 2016 at 13:16

Hi Le.bien,

It seems you have an overrun error due to pending interrupt.

In order to clear the pending interrupts we provide a specific macros in stm32f4xx_hal_uart.h file that can be used directly by the application (when needed).

Please refer to the Exported macro section in stm32f4xx_hal_uart.h file. The specific macro to clear the overrun pending interrupt is

__HAL_UART_CLEAR_OREFLAG()

Thus you can perform this to avoid overrun issue:

__HAL_UART_CLEAR_OREFLAG(…)
HAL_UART_Receive_IT(…)

-Hannibal-