Topics / Communication Protocols / Q5
What are UART framing, parity and overrun errors?
Short answer: A framing error means the stop bit was sampled as 0 (baud mismatch, noise, or a break). A parity error means the parity bit does not match the data. An overrun error means a new byte arrived before software read the previous one, so data was lost. A noise error means the oversampled values within a bit disagreed.
| Error | Typical cause | Fix |
|---|---|---|
| Framing (FE) | wrong baud rate, wrong frame format, noise, break condition | check clocks and settings, add filtering, handle breaks deliberately |
| Parity (PE) | noise, wrong parity setting | check settings, cabling, use a CRC at the protocol level |
| Overrun (ORE) | ISR too slow, interrupts disabled too long, no FIFO | faster/shorter ISR, higher priority, FIFO, DMA |
| Noise (NE) | electrical noise, slow edges | better wiring, ground, shielding, RS-485 |
Handling them in firmware
- Read and clear the flags exactly as the reference manual says (e.g. on many STM32 parts, reading
SRthenDRclears ORE/FE/NE). If an overrun flag is never cleared, some UARTs stop receiving entirely. - Count errors (statistics are very useful for field diagnosis).
- Discard the corrupted byte and let the higher-level protocol (CRC, sequence numbers, timeouts) recover the message.
Overrun math: at 921600 baud a byte arrives every ~10.9 µs. If an ISR is delayed by more than one byte time (plus FIFO depth), you lose data. Using DMA into a circular buffer removes the per-byte deadline.