Skip to main content
duybienle
Associate II
August 4, 2016
Question

HAL_UART_Receive_IT returns error

  • August 4, 2016
  • 1 reply
  • 501 views
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

    This topic has been closed for replies.

    1 reply

    Walid FTITI_O
    Visitor II
    August 22, 2016
    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-