Electronic – Handling of UART Errors

uart

I am not concentrating on a Specific MCU as UART of most controllers has similar architecture. They have FIFOs for Both Tx and Rx.

Most common errors generated by UART are:-
1. Framing Error
2. Parity Error
3. Over-run Error (Overflow of Tx/Rx FIFOs)
4. Receive Break Error (Some Error with Stop Bits)

How one should handle these Error Conditions to maintain communication properly?

I do understand it's a vague question but most of the time people get confused about what one should do when such errors occur and end up in just clearing the error bits.

Best Answer

To actually answer your question, I usually discard anything received with error. That may include re-initializing the UART hardware, depending on what error it is and the details of the UART hardware.

The only exception is if you want to deliberately receive breaks. Those show up as framing errors. In that case you pass framing errors up to the higher levels as special conditions. However, that requires out of band information to be passed to the higher levels and therefore the UART receiver interface can't be seen as something quite as simple as getting a stream of bytes. I think I've done this exactly once in many microcontroller projects because it had to be compatible with a old system where breaks were used deliberately.

Steven has given you some good ideas what to do about this at the higher level. When you think there is a real chance of errors and data integrity is important, then you usually encapsulate chunks of data into packets with checksums. The receiver sends a ACK for every correctly received checksum.

However, the vast majority of the time UART errors are so unlikely and not absolutely critical that you can just ignore them at the high level. The kind of errors the UART hardware can catch are usually due to operator stupidity, not line noise. Most like noise will cause bad data, which the UART won't detect. So the low level UART driver throws out anything immediately associated with a UART error, but otherwise continues to pass the stream of received bytes up to the next level. In fact it does this even if you are using packets and checksums since that is done at a higher level than where individual bytes are received.