
UART framing errors are the silent killer of serial communication in embedded systems. You connect two devices, both configured for 115200-8N1, and instead of clean data you get garbage — or worse, intermittent corruption that only appears under load or after hours of operation. The UART status register shows the FE (framing error) bit set, but the baud rate registers look correct on both sides.
The root cause is almost always baud rate mismatch — not a configuration mistake, but the accumulated timing drift between two independent clock sources. Because UART has no shared clock line, each endpoint generates its own bit timing from its local oscillator. Even when both sides request the same nominal baud rate, crystal tolerances, PLL rounding, and integer baud rate divisors create a mismatch that grows with every bit in the frame.
This article derives the baud rate tolerance math from first principles, shows how to measure actual timing on the wire, and gives you a checklist of fixes that work in production — from the simple (enable 2 stop bits) to the robust (fractional BRR, auto-baud, crystal selection).
A UART frame in the ubiquitous 8N1 format consists of 10 bits: one start bit (logic 0), eight data bits (LSB first), and one stop bit (logic 1). The line idles HIGH. The receiver detects the falling edge of the start bit, waits 1.5 bit periods to sample near the center of the start bit, then samples each subsequent bit at 1-bit-period intervals.
+-----------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+| IDLE | START | D0 | D1 | D2 | D3 | D4 | D5 | D6 | D7 | STOP || (1) | (0) | (LSB) | | | | | | | (MSB) | (1) |+-----------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+^ ^ ^ ^ ^ ^ ^ ^ ^ ^| | | | | | | | | |Falling Sample Sample Sample Sample Sample Sample Sample Sample Sample SampleEdge Center Center Center Center Center Center Center Center Center CenterDetected of of of of of of of of of ofStart D0 D1 D2 D3 D4 D5 D6 D7 Stop
The framing error triggers when the receiver samples the stop bit position and reads logic 0 instead of the expected logic 1. This happens when the receiver’s sampling point has drifted far enough that it falls into the last data bit (D7) instead of the stop bit. If D7 happens to be 0, the stop bit sample reads 0 → framing error. If D7 is 1, the error goes undetected — silent data corruption.
Let’s derive the tolerance mathematically so you can calculate it for any frame format and oversampling ratio.
The relative mismatch between transmitter and receiver is:
E = ε_tx - ε_rx (expressed as fraction, e.g., 0.02 = 2%)
The receiver starts sampling at the center of the start bit (t = 0.5 × Tbit_rx). The k-th bit (0-indexed: start=0, D0=1, …, stop=N-1) is sampled at:
t_sample(k) = (0.5 + k) × Tbit_rx
The transmitter’s actual bit boundary for bit k occurs at:
t_tx_boundary(k) = Σ(i=0 to k) Tbit_tx = (k + 1) × Tbit × (1 + ε_tx)
The drift at the sampling instant of bit k is:
Drift(k) = t_sample(k) - t_tx_boundary(k-1) (for k ≥ 1)= (0.5 + k) × Tbit × (1 + ε_rx) - k × Tbit × (1 + ε_tx)= Tbit × [0.5 + k + 0.5ε_rx + kε_rx - k - kε_tx]= Tbit × [0.5 + k(ε_rx - ε_tx) + 0.5ε_rx]≈ Tbit × [0.5 - k × E] (neglecting the small 0.5ε_rx term)
For the stop bit (k = N-1), the drift must not exceed half a bit period (0.5 × Tbit) or the sample falls into the adjacent bit:
|0.5 - (N-1) × E| < 0.5
This gives the per-device tolerance (assuming ε_tx = -ε_rx = E/2, worst case):
E < 1 / (N - 1)
For 8N1 (N=10): E < 1/9 ≈ 11% — but this is the theoretical limit with perfect center sampling.
Real UARTs use oversampling (typically 16×) to detect the start bit edge and sample near the center. The receiver’s internal counter divides the peripheral clock by a baud rate divisor (BRR). The start bit detection has quantization error from the oversampling counter, and the sampling point is not exactly at the center.
With 16× oversampling:
The NXP LPUART application note AN14458 gives the practical formulas:
SAM = samples per bit = OSR + 1 (typically 16 for 16× oversampling)BIT = total bits per frame (10 for 8N1, 11 for 8E1/8O1, 12 for 8N2)Slow data rate tolerance (tx slower than rx):TOL_slow = ((SAM/2) - 1) / ((SAM × BIT) - (SAM/2) + 2)Fast data rate tolerance (tx faster than rx):TOL_fast = ((SAM/2) - 2) / (SAM × BIT)
For standard 16× oversampling, 8N1:
SAM = 16, BIT = 10TOL_slow = (8 - 1) / (160 - 8 + 2) = 7 / 154 = 4.55%TOL_fast = (8 - 2) / 160 = 6 / 160 = 3.75%
But both clocks have error. The combined mismatch is E_total = ε_tx - ε_rx. In worst case, ε_tx = +E/2, ε_rx = -E/2, so each device contributes E/2. The per-device budget is half the combined tolerance:
| Frame Format | Combined Tolerance | Per-Device Budget |
|---|---|---|
| 8N1 (16× OSR) | ~3.75% | ~1.87% |
| 8E1/8O1 (16× OSR) | ~3.4% | ~1.7% |
| 8N2 (16× OSR) | ~4.1% | ~2.05% |
This is why the industry rule of thumb is ±2% per device, ±1% for high baud rates.
A typical crystal has ±20-50 ppm tolerance. At 115200 baud:
115200 × 50 ppm = 5.76 baud error = 0.005% ← negligible
But the baud rate divisor (BRR) introduces quantization error. For STM32 with 16× oversampling:
BRR = f_PCLK / (16 × baud_rate)
If f_PCLK = 8 MHz and baud = 115200:
BRR = 8,000,000 / (16 × 115,200) = 4.34 → rounded to 4Actual baud = 8,000,000 / (16 × 4) = 125,000Error = (125000 - 115200) / 115200 = 8.5% ← TOO HIGH
This is why 7.3728 MHz crystals are popular — they divide evenly into common baud rates:
7,372,800 / (16 × 115,200) = 4.0 ← exact7,372,800 / (16 × 9,600) = 48.0 ← exact
Never trust the register settings — measure the actual signal.
With an oscilloscope:
With a logic analyzer (Saleae, DSLogic, etc.):
Example measurement:
Expected: 115200 baud (8.68 µs/bit)Measured bit period: 8.72 µsActual baud: 114,678Error: (114678 - 115200) / 115200 = -0.45%
If the measured error exceeds ±1.5%, you have a clock configuration problem.
The baud rate register is an integer (or fixed-point with limited fractional bits). The division rarely yields an exact integer.
// STM32 example: compute BRR and actual erroruint32_t pclk = 8000000; // 8 MHzuint32_t baud = 115200;uint32_t brr = pclk / (16 * baud); // = 4uint32_t actual_baud = pclk / (16 * brr); // = 125000float error_pct = 100.0f * (actual_baud - baud) / baud; // = 8.5%
Fix: Use a clock frequency that divides evenly, or use fractional BRR (see Solutions).
One side uses HSI (internal RC oscillator, ±1-2%), the other uses HSE (external crystal, ±20-50 ppm).
// Check your clock configuration// RCC_CFGR_SW bits: 00=HSI, 01=HSE, 10=PLL// If HSI: expect ~1% error → marginal at 115200// If HSE/PLL with crystal: expect <0.01% error → safe
Fix: Use the same clock source type on both ends, or use a crystal on both.
The PLL multiplier/divider settings may not produce the exact frequency you expect.
// STM32 PLL: f_VCO = f_HSE / PLLM * PLLN// f_PCLK = f_VCO / PLLP// Verify each step with a scope on MCO pin
Fix: Output the system clock on MCO (PA8 on STM32) and measure with a frequency counter.
One side uses 16× oversampling, the other uses 8× (for higher baud rates).
// STM32: USART_CR1_OVER8 bit// 0 = 16× oversampling (standard)// 1 = 8× oversampling (allows higher baud, lower tolerance)
Fix: Match oversampling mode on both ends. 8× oversampling halves the tolerance.
Changing from 1 stop bit to 2 stop bits (8N2) adds one extra bit period of margin before the stop bit is sampled.
8N1: stop bit sampled at 9.5 bit periods from start edge8N2: stop bit sampled at 10.5 bit periods from start edge
The tolerance formula with BIT=11 (8N2):
TOL_slow = (8 - 1) / (176 - 8 + 2) = 7 / 170 = 4.12%TOL_fast = (8 - 2) / 176 = 6 / 176 = 3.41%
Per-device budget improves to ~1.7-2.0%. This is often enough to make a marginal link reliable.
// STM32 HALhuart.Init.StopBits = UART_STOPBITS_2; // instead of UART_STOPBITS_1
Trade-off: 10% throughput reduction (11 bits vs 10 bits per byte). Negligible for most applications.
Modern MCUs (STM32, NXP, TI, Renesas) support fractional BRR with 16-bit integer + 4-bit fractional part.
// STM32 USART_BRR: DIV_Mantissa[15:4] | DIV_Fraction[3:0]// f_CK / (16 * USARTDIV) where USARTDIV = DIV_Mantissa + DIV_Fraction/16// Example: 8 MHz PCLK, 115200 baud// Ideal DIV = 8,000,000 / (16 * 115,200) = 4.340277...// Mantissa = 4, Fraction = 0.340277 * 16 = 5.44 → 5// BRR = (4 << 4) | 5 = 0x45// Actual baud = 8,000,000 / (16 * (4 + 5/16)) = 115,942// Error = (115942 - 115200) / 115200 = 0.64% ← EXCELLENT
Always use fractional BRR when available. It reduces quantization error from ~1-8% to <0.5%.
Some UART peripherals (STM32, NXP LPUART, TI) support auto-baud: send a known character (typically 0x55 = 0b01010101) at startup, and the hardware measures the bit period and configures BRR automatically.
// STM32 HAL auto-baud enablehuart.Init.AutoBaudRate = UART_AUTOBAUDRATE_ON;huart.Init.AutoBaudRateMode = UART_AUTOBAUDRATEMODE_STARTBIT; // or other modesHAL_UART_Init(&huart);// Send 0x55 from the other end during initializationHAL_UART_Transmit(&huart, (uint8_t[]){0x55}, 1, 100);
Use case: Bootloaders, field firmware updates, systems where the peer’s clock is unknown.
If you control the hardware design, choose a crystal that divides cleanly.
| Crystal (MHz) | 9600 | 19200 | 38400 | 57600 | 115200 | 230400 | 460800 | 921600 |
|---|---|---|---|---|---|---|---|---|
| 7.3728 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| 14.7456 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| 18.432 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| 8.000 | ✓ | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ |
| 12.000 | ✓ | ✓ | ✓ | ✓ | ✗ | ✗ | ✗ | ✗ |
| 16.000 | ✓ | ✓ | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ |
| 24.000 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✗ | ✗ |
| 48.000 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
✓ = exact integer BRR possible with standard 16× oversampling
Rule: For high baud rates (≥115200), use 7.3728, 14.7456, 18.432, or 48 MHz crystals. Avoid 8, 12, 16 MHz for high-speed UART.
If you cannot change hardware or clock configuration, drop the baud rate.
115200 → 57600: 2× bit period, 2× tolerance margin115200 → 38400: 3× bit period, 3× tolerance margin
The tolerance scales linearly with bit period. At 9600 baud (104 µs/bit), even a 5% clock error is often tolerable.
// Simple baud rate fallback for field robustnessstatic const uint32_t baud_rates[] = {115200, 57600, 38400, 19200, 9600};for (int i = 0; i < 5; i++) {huart.Init.BaudRate = baud_rates[i];if (HAL_UART_Init(&huart) == HAL_OK) {// Test with loopback or known patternif (uart_test_link()) break;}}
When you see framing errors, follow this order:
typedef struct {uint32_t framing_errors;uint32_t overrun_errors;uint32_t parity_errors;uint32_t noise_errors;uint32_t total_bytes;} uart_stats_t;static uart_stats_t uart1_stats = {0};void uart1_error_check(void){uint32_t sr = USART1->SR;uint32_t dr = USART1->DR; // Reading DR clears some flagsif (sr & USART_SR_FE) uart1_stats.framing_errors++;if (sr & USART_SR_ORE) uart1_stats.overrun_errors++;if (sr & USART_SR_PE) uart1_stats.parity_errors++;if (sr & USART_SR_NE) uart1_stats.noise_errors++;uart1_stats.total_bytes++;}
Some UART implementations (Linux kernel 8250 driver, NXP LPUART) re-synchronize the sampling clock on every falling edge within the frame, not just the start bit. This dramatically improves tolerance for continuous streams.
// Conceptual: re-sync on each start bit edge// Only works when there are guaranteed transitions (not all data patterns)// 0x55 (01010101) and 0xAA (10101010) provide maximum edges
If you control both ends, send periodic sync characters (0x55) in continuous streams to let the receiver re-align.
| Problem | Root Cause | Quick Fix | Robust Fix |
|---|---|---|---|
| Framing errors at 115200 | BRR integer rounding | 2 stop bits | Fractional BRR |
| Works at 9600, fails at 115200 | Clock error % too high at short bit period | Reduce baud rate | Crystal selection |
| Intermittent FE under load | Clock drift with temperature | Add sync chars (0x55) | Auto-baud + crystal |
| FE only on specific data | D7=0 mimics stop bit error | 2 stop bits | Parity + checksum |
Key takeaways:
The framing error is not a mystery — it’s a timing budget violation. Calculate your margin, measure your actuals, and apply the fix that fits your constraints.
Quick Links
Legal Stuff





