Dear all,
I am having some trouble with the UART module where UART_FRAMING_ERROR occurs very frequently that only 20% of the payload is received successfully.
The project uses freeRTOS and the S32 SDK. A task receives UART packets from another chip (iMX6). The UART packet starts with 0xAE and has a fixed length of 88 bytes (RX_BUFF_LEN). It is sent to S32K148 at 100Hz with a baud rate of 460800.
I have used similar tasks to receive data from other devices before, which worked fine. The code also works when I send data from a Raspberry Pi to an S32K148_EVB (same data format as memtioned above). But when switching to the actual project, LPUART_DRV_GetReceiveStatus frequently returns UART_FRAMING_ERROR (as sample from FreeMaster). As a result, only 20% of the payload is received: a counter increases upon successful reception, and FreeMaster shows this counter only increases by 20 each second, instead of the expected 100Hz.
To add a few points:
1. The S32K148 uses CLK_SRC_SPLL_DIV2 as the clock source, process expert shows an actual baudrate of 465116, which doesn't look ridiculous;
2. I have also tried reducing the baudrate to 115200 with no success;
3. The iMX6 chip seems to receive data from S32K148 OK, at least much more smoothly;
I have inserted part of the code below. I wonder if you could share your thoughts on this issue.
Many thanks!
Zitong
LPUART_DRV_ReceiveData(INST_LPUART1, &u8RxBuffer[0], RX_BUFF_LEN);
for (;;) {
/* poll rx status */
eRxStat = LPUART_DRV_GetReceiveStatus(INST_LPUART1, &u32BytesLeft);
if ( eRxStat == STATUS_BUSY ) { /* if rx in progress */
u16BytesReceived = RX_BUFF_LEN - (uint16_t)u32BytesLeft;
if ( u16BytesReceived > 0 ) { /* if at least one byte received */
if (0xAE != u8RxBuffer[0]) { /* if packet header missed */
/* abort current receive since the packet is incomplete */
LPUART_DRV_AbortReceivingData(INST_LPUART1);
/* restart receive after 2ms so that the current packet is flushed */
vTaskDelay(2);
LPUART_DRV_ReceiveData(INST_LPUART1, u8RxBuffer, RX_BUFF_LEN);
}
}
} else if ( eRxStat == STATUS_SUCCESS ) { /* if transfer successful */
/* handle received data */
/* restart receive */
LPUART_DRV_ReceiveData(INST_LPUART1, u8RxBuffer, RX_BUFF_LEN);
vTaskDelay(1);
} else { /* if error occurs */
/* restarts receive */
LPUART_DRV_ReceiveData(INST_LPUART1, u8RxBuffer, RX_BUFF_LEN);
}
vTaskDelay(1);
}
Hello Zitong,
Since the Framing Error is reported when the received char has 0 where a stop bit should be,
I would double check the baudrate.
Can you please scope the signal both from the S32K148 and the iMX6?
Please have a look at Section 53.4.2 Baud rate generation in the RM, rev12.1
Depending on the over sampling ratio, the receiver has an acquisition rate of 4 to 32 samples per bit time.
Regards,
Daniel