Hi.
I have a problem using the UART with a Kinetis microcontroller using MCUXpresso.
I use this function to receive data in an array of 2 elements:
UART_ReadBlocking (DEMO_UART, & rxbuff, 2);
The problem is that the Kinetis communicates with a Raspberry by serial port, and when starting both at the same time there is always a little interference that causes incorrect data to be read. In fact this is detected well by the function and returns error code 1011.
The point is that if when detecting the error, I run the same function again, it no longer receives correct data, only zeros. I have tried to restart the UART but then incomprehensibly the Rasbperry does not start.
This is the source code:
while(1)
{
int32_t leo_uart = UART_ReadBlocking(DEMO_UART, &rxbuff, 2);
if (rxbuff[1] == 7)
{
printf("\nData received is OK... %d %d %d\r\n", rxbuff[0], rxbuff[1], leo_uart);
break;
}
else {
delay(15);
printf("\nError... %d %d %d\r\n", rxbuff[0], rxbuff[1], leo_uart);
}
In the first data reception that is the result of interference when starting the Raspberry, it returns data to 0 and error code 1011. And in the second data reception that is already with correct data, it returns data to 0 and error code to 0. The correct data to receive would be 42 and 7, and as an error code 0 that indicates that the received data is correct, but it is not.
I tried to restart the UART with this source code, but then the Raspberry won't start, this I don't understand why it happens.
// Stop UART
UART_Deinit(DEMO_UART);
delay(25); // Espera 25ms, para evitar problemas en la UART en el Raspberry
// Config UART
uart_config_t config;
UART_GetDefaultConfig(&config);
config.baudRate_Bps = BOARD_DEBUG_UART_BAUDRATE;
config.enableTx = true;
config.enableRx = true;
// Start UART
UART_Init(DEMO_UART, &config, DEMO_UART_CLK_FREQ);