2018-05-14 06:24 AM
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 #uart2018-08-06 07:58 AM
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
2018-08-06 08:40 AM
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.