LPC55S16 - UART Framing Error - How To Recover?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

LPC55S16 - UART Framing Error - How To Recover?

932 次查看
JK_265
Contributor III

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!

0 项奖励
回复
3 回复数

836 次查看
JK_265
Contributor III

@Harry_Zhang  I am currently working in a polling mode where this issue occurs when using USART_READBlocking( which returns 0x5711, framing error).  What to do in this situation?  Thanks.

0 项奖励
回复

733 次查看
Harry_Zhang
NXP Employee
NXP Employee

Hi @JK_265 

This means that the received frame is incorrect.

Harry_Zhang_0-1732845613288.png

 

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

0 项奖励
回复

903 次查看
Harry_Zhang
NXP Employee
NXP Employee

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

0 项奖励
回复