I created an infinite while loop following a Processor Expert example for UART, and read data from the serial port.
/* Initialize for UART_PAL */
error = UART_ReceiveData(&uart_pal1_instance, buffer_uart, 12UL);
if (error==STATUS_SUCCESS) //means data was received from PC
//...doing something with the data received
This function works ok, except for the first time it loops, when error=STATUS_SUCCESS. There is no data on the serial bus.
While I can fix it by ignoring the first loop data, I don't know why it happens.
*btw, same thing happens with CAN communication, not just UART.
I'm using the on board Open SDA debugger, not sure it matters.