Skip to main content
Steven Bébin
Associate III
May 14, 2018
Question

HAL_UART_Receive_IT timeout

  • May 14, 2018
  • 2 replies
  • 3947 views
Posted on May 14, 2018 at 15:24

Hello,

I plan to take the data from a meter. It works.

I would now like to create a timeout on the HAL_UART_Receive_IT in case the wire connected to the meteris cut.

Is it possible to create a timeout for this function or are there other methods to achieve what I want to do?

do // Start of frame detection

{

HAL_UART_Receive_IT (& huart2, data, 1); // We recover a data

} while (data [0]! = 0x02);

#timeout #uart
This topic has been closed for replies.

2 replies

Joris COLLOMB
Associate
August 6, 2018

Hi everyone,

I have the same question as Steven, so if somebody know how to achieve the timeout in interrupt uart reception, please help us.

Thanks,

Joris

Tesla DeLorean
Guru
August 6, 2018

The above code seems to totally misunderstand the concept of using an interrupt and callbacks. Grinding in a loop and blocking seems to miss the point.

If you use HAL_UART_Receive_IT() in this way you need to use HAL_Ticks() to evaluate if the timeout expires, or use the HAL_UART_Receive() form. For Tasks have a semaphore that gets set on successful UART callback, or on a TIM/SysTick based timeout.

Also if the mechanics of the HAL, and the USART stack don't fit the paradigm of your existing code/methodology you are at liberty to implement something better.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..