Hi,
I'm trying to read UART messages of any length on a KL03 (does not support DMA).
I use fnRead in my task, and every time a new character is received the task is triggered.
My code is very simple
QUEUE_TRANSFER length;
while ( (length = fnRead(SerialPortID, uartMessage, MEDIUM_MESSAGE)) != 0 ){
counter++;
//fnDelayLoop(600);
}
Now, here is the problem, if I do not use that fnDelayLoop, the while is entered for each character, one at a time. So, for a message of n chars, there will be n interrupts to my task and n while loops. If, instead, I use the fnDelayLoop, the while is executed only one time for the whole message (which I prefer). My understanding is that without the delay, the while terminates because the characters are too slow with respect the the execution of the while loop and the uart rx buffer is empty, so the delay allows waiting for the whole message to arrive while still in the loop.
But in this way the delay to to be used depends on the length of the message that I don't know beforehand and it is not constant. And if the delay is not enough for a long messages, then its last part will come with the initial part of the next message.
Is there a better way to do this?