Using an LPC55S16 to communicate via UART. Unfortunately, the system has some noise, and the RX line is occasionally pulled low momentarily, which the UART interprets as a start bit. This ultimately leads to a framing error.
What is the suggested methodology for recovering from a framing error? I'd was thinking just vector on a framing error, reset some flags, and throw out the byte. But this is just a high level concept. Can I please get a detailed description of what should be done in this situation?
Thanks!
Hi @JK_265
This means that the received frame is incorrect.
I suggest you use this example to automatically discard frames when they are received incorrectly, and receive frames when they are received correctly.
BR
Harry
Hi @JK_265
I think you can refer to lpc55s16_usart_interrupt example.
But you need change some code.
USART_EnableInterrupts(DEMO_USART, kUSART_RxLevelInterruptEnable | kUSART_RxErrorInterruptEnable);
change to
USART_EnableInterrupts(DEMO_USART, kUSART_RxLevelInterruptEnable | kUSART_RxErrorInterruptEnable | kUSART_FramingErrorInterruptEnable);
.
And you also need to change DEMO_USART_IRQHandler function.
void DEMO_USART_IRQHandler(void)
{
uint8_t data;
/* If new data arrived. */
if ((kUSART_RxFifoNotEmptyFlag | kUSART_RxError) & USART_GetStatusFlags(DEMO_USART))
{
data = USART_ReadByte(DEMO_USART);
/* If ring buffer is not full, add data to ring buffer. */
if (((rxIndex + 1) % DEMO_RING_BUFFER_SIZE) != txIndex)
{
demoRingBuffer[rxIndex] = data;
rxIndex++;
rxIndex %= DEMO_RING_BUFFER_SIZE;
}
}
if (kUSART_FramingErrorInterruptEnable & USART_GetStatusFlags(DEMO_USART))
{
uint8_t discard = USART_ReadByte(DEMO_USART);
errorCounter++;
}
SDK_ISR_EXIT_BARRIER;
}
BR
Hang