2016-08-04 12:48 AM
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 Bien2016-08-22 04:16 AM
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-