cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_UART_Receive_IT timeout

Steven Bébin
Associate III
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
2 REPLIES 2
Joris COLLOMB
Associate II

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

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
Up vote any posts that you find helpful, it shows what's working..