cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_UART_Receive() timeout issue

Dick Lin
Senior
Posted on May 24, 2018 at 20:40

Hi,

I am using Nucleo-144 board connecting UART to my TI device using 250000 baudrate. I always got timeout no matter what timeout using.

Seems the issue is 

UART_WaitOnFlagUntilTimeout() failed and return HAL_TIMEOUT.

if(UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)

{

return HAL_TIMEOUT;

}

  while((__HAL_UART_GET_FLAG(huart, Flag) ? SET : RESET) == Status)

#define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))

Above are the code checking timeout. 

Reading the HAL user's manual, seems HAL_UART_Receive() need to enable FIFO mode. Is there any reference code to enable FIFO mode or DMA mode? I am using the Cube generated code, and reference to other code. Haven't found any useful example yet.

Thanks,

Dick

4 REPLIES 4
Posted on May 24, 2018 at 21:16

Suggests it's not actually receiving any usable data, or the ISR is flagging one or more receive errors that need to be cleared.

A basic test would be to loop the TX pin into the RX pin, sending data in the correct form and seeing it be received.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 24, 2018 at 21:34

I am able to transmit data using HAL_UART_Transmit() function and confirmed the tx/rx data from logic analyzer. Just not get the correct data from HAL_UART_Receive().

Posted on May 24, 2018 at 21:43

So look at the USART registers, and reported status/errors. Don't park a debugger 'peripheral view' over the USART register. Read them and print them out a different USART or SWV debug output.

Look at the pin configurations and clocks. Check the RCC and GPIO register bits.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 25, 2018 at 01:29

I got it now, need to clear some flags. Thx

__HAL_UART_CLEAR_OREFLAG(m_uart_handler);

__HAL_UART_CLEAR_NEFLAG(m_uart_handler);