HAL_UARTEx_ReceiveToIdle_IT - meaning of idle ?
Dear ST/reader,
I’m currently implementing a uart receive interrupt function for use with the STM32H743 specifically using HAL_UART_Receive_IT(). This is straightforward when the receive length (number of bytes to receive) is just 1 in which case it either receives and notifies via the callback, or I timeout.
In another application the number of bytes to receive can vary. I don’t like the idea of using HAL_UART_Receive_IT() for each and every byte, so am considering other options for example HAL_UARTEx_ReceiveToIdle_IT().
What are the “idle�? conditions associated with HAL_UARTEx_ReceiveToIdle_IT() ? Is it a set period of time during which if no reception is detected then idle is considered to have happened ? If for example I set the length to 250, when I initially call this routine, but only 100 bytes are received then what happens and when ? And how do I determine how many bytes were actually received ?
In the same way that HAL_UART_Receive_IT() causes HAL_UART_RxCpltCallback() to be called will this same callback be called either when HAL_UARTEx_ReceiveToIdle_IT() receives its full quota of bytes or if it detects idle ? If it’s due to an idle condition then can whatever bytes were received previous to this still be read normally ? If so then this might be a good way to implement the new application; ie, I set the length to some much higher-than-expected value and rely on the idle for the receiving process to end.
Another option is to still use HAL_UART_Receive_IT(), but to use it twice – once for the first four bytes, from which I can calculate the remaining number expected, and then a second time for that remainder, but in this application this would be very difficult to do hence the interest in the other hal function.
And for HAL_UART_Receive_IT() … if less than the expected length of data was received can these bytes still be read ? This is still the preferred option for when the received length is known beforehand, but what if for some unknown/unexpected reason the transmitter sends one byte less ? Would just like to know the proper way to proceed in that case.
