2014-05-28 11:13 AM
I have basic RS-232 Tx/Rx running between the Discovery board and TeraTerm. I am successfully invoking HAL_UART_Receive_IT() in main with a fixed Rx message size.
My question is - what is the method for receiving, unblocked, messages where the length of the message is unknown? Basically the message will be terminated with a line feed, but various Rx'd command messages will have different lengths. Additionally, is there a way to set an inter-character timeout in the driver so as not to get hung up on incomplete messages? Thanks!2014-05-28 11:52 PM
> My question is - what is the method for receiving, unblocked, messages where the length of the message is unknown?
> Basically the message will be terminated with a line feed, but various Rx'd command messages will have different lengths. In pseudocode: int main(void) { InitializeUart; while(1) { if (Uart_RxIsNotEmpty) { byte = Uart_ReadByte(); if (byte != EndOfLine) { PutByteIntoBuffer(byte); } else { ProcessBuffer(); } } } } This can go into the UART ISR of course - or just the buffering part of it, passing a flag to ''main'' when the end-of-line character is received. > Additionally, is there a way to set an inter-character timeout in the driver so as not to get hung up on incomplete messages? When the first character of the message arrives, set up one of the timers to fire an interrupt (e.g. and update interrupt) when a given time elapses. When a character arrives, reset the timer. Stop the timer when the complete message arrives. If the timer ISR fires, it should stop the timer and set a flag for main to indicate that timeout occured, main should check it and process the portion of message accordingly. JW2014-05-29 04:43 AM
Hello Jan,
Thank you so much. That's just what I needed. Best regards, Mark