HomeAbout UsContact Us

Debugging UART Framing Errors: Baud Rate Tolerance

By Jithin Tom
Published in Embedded Concepts
December 03, 2026
6 min read
Debugging UART Framing Errors: Baud Rate Tolerance

Table Of Contents

01
The UART Frame and Where Framing Errors Happen
02
Deriving the Baud Rate Tolerance from First Principles
03
Common Causes of Baud Rate Mismatch
04
Production-Ready Fixes
05
Systematic Debugging Checklist
06
Advanced: Mid-Frame Re-synchronization
07
Summary
08
Related Reading
09
References
10
Frequently Asked Questions

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).

The UART Frame and Where Framing Errors Happen

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 Sample
Edge Center Center Center Center Center Center Center Center Center Center
Detected of of of of of of of of of of
Start 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.

Deriving the Baud Rate Tolerance from First Principles

Let’s derive the tolerance mathematically so you can calculate it for any frame format and oversampling ratio.

Timing Model

  • Bit period (Tbit): 1 / baud_rate seconds per bit
  • Frame bits (N): Total bits per frame (10 for 8N1, 11 for 8E1, 12 for 8N2)
  • Receiver sampling point: Nominally at the center of each bit (0.5 × Tbit from bit start)
  • Transmitter actual bit period: Tbit × (1 + ε_tx) where ε_tx is the transmitter’s fractional frequency error
  • Receiver actual bit period: Tbit × (1 + ε_rx) where ε_rx is the receiver’s fractional frequency error

The relative mismatch between transmitter and receiver is:

E = ε_tx - ε_rx (expressed as fraction, e.g., 0.02 = 2%)

Accumulated Drift

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-World Tolerance: Oversampling and Synchronization

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:

  • Start bit detected at sample 8 of 16 (half bit period)
  • Each data bit sampled at sample 8 of its 16-sample window
  • The receiver re-synchronizes on the start bit falling edge only — no mid-frame re-sync

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 = 10
TOL_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 FormatCombined TolerancePer-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.

Crystal Oscillator Selection

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 4
Actual baud = 8,000,000 / (16 × 4) = 125,000
Error = (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 ← exact
7,372,800 / (16 × 9,600) = 48.0 ← exact

Measuring Actual Baud Rate on the Wire

Never trust the register settings — measure the actual signal.

With an oscilloscope:

  1. Trigger on the falling edge of the start bit
  2. Measure the width of one bit (time between two consecutive edges)
  3. Calculate actual baud = 1 / measured_bit_period
  4. Compare to expected baud

With a logic analyzer (Saleae, DSLogic, etc.):

  1. Capture a frame at high sample rate (≥ 4× baud rate)
  2. Use the UART protocol analyzer
  3. It will report the measured baud rate and any framing errors

Example measurement:

Expected: 115200 baud (8.68 µs/bit)
Measured bit period: 8.72 µs
Actual baud: 114,678
Error: (114678 - 115200) / 115200 = -0.45%

If the measured error exceeds ±1.5%, you have a clock configuration problem.

Common Causes of Baud Rate Mismatch

1. Integer BRR Rounding (Most Common)

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 error
uint32_t pclk = 8000000; // 8 MHz
uint32_t baud = 115200;
uint32_t brr = pclk / (16 * baud); // = 4
uint32_t actual_baud = pclk / (16 * brr); // = 125000
float error_pct = 100.0f * (actual_baud - baud) / baud; // = 8.5%

Fix: Use a clock frequency that divides evenly, or use fractional BRR (see Solutions).

2. Clock Source Mismatch

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.

3. PLL Configuration Error

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.

4. Different Oversampling Modes

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.

Production-Ready Fixes

Fix 1: Enable 2 Stop Bits (Simplest, Immediate)

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 edge
8N2: 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 HAL
huart.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.

Fix 2: Use Fractional Baud Rate Generator

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%.

Fix 3: Auto-Baud Detection

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 enable
huart.Init.AutoBaudRate = UART_AUTOBAUDRATE_ON;
huart.Init.AutoBaudRateMode = UART_AUTOBAUDRATEMODE_STARTBIT; // or other modes
HAL_UART_Init(&huart);
// Send 0x55 from the other end during initialization
HAL_UART_Transmit(&huart, (uint8_t[]){0x55}, 1, 100);

Use case: Bootloaders, field firmware updates, systems where the peer’s clock is unknown.

Fix 4: Select Crystal for Baud-Friendly Frequencies

If you control the hardware design, choose a crystal that divides cleanly.

Crystal (MHz)9600192003840057600115200230400460800921600
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.

Fix 5: Reduce Baud Rate (When All Else Fails)

If you cannot change hardware or clock configuration, drop the baud rate.

115200 → 57600: 2× bit period, 2× tolerance margin
115200 → 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 robustness
static 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 pattern
if (uart_test_link()) break;
}
}

Systematic Debugging Checklist

When you see framing errors, follow this order:

Step 1: Verify Physical Layer

  • TX ↔ RX cross-connected (not TX→TX)
  • GND connected between both devices
  • Voltage levels compatible (3.3V ↔ 3.3V, or level shifter for 5V ↔ 3.3V)
  • No floating lines (pull-up on RX if needed)

Step 2: Verify Configuration Match

  • Same baud rate on both sides
  • Same data bits (8), parity (None), stop bits (1 or 2)
  • Same oversampling mode (16× vs 8×)
  • Flow control both enabled or both disabled

Step 3: Loopback Test

  • Connect TX to RX on the suspect device (disconnect peer)
  • Transmit known pattern (0x55, 0xAA, 0x00, 0xFF)
  • Verify received data matches exactly
  • If loopback fails → local UART config/driver problem
  • If loopback works → wiring or peer device problem

Step 4: Measure Actual Bit Timing

  • Scope/logic analyzer on TX line
  • Measure bit period of start bit and data bits
  • Calculate actual baud rate
  • Compare to expected; error >1.5% → clock problem

Step 5: Check Error Flags

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 flags
if (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++;
}
  • FE (framing) → baud rate mismatch or format mismatch
  • ORE (overrun) → software not reading DR fast enough
  • PE (parity) → electrical noise or parity setting mismatch
  • NE (noise) → signal integrity, marginal timing

Advanced: Mid-Frame Re-synchronization

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.

Summary

ProblemRoot CauseQuick FixRobust Fix
Framing errors at 115200BRR integer rounding2 stop bitsFractional BRR
Works at 9600, fails at 115200Clock error % too high at short bit periodReduce baud rateCrystal selection
Intermittent FE under loadClock drift with temperatureAdd sync chars (0x55)Auto-baud + crystal
FE only on specific dataD7=0 mimics stop bit error2 stop bitsParity + checksum

Key takeaways:

  1. Measure, don’t guess — scope the TX line, verify actual baud rate
  2. Fractional BRR is the single most effective firmware fix
  3. 2 stop bits costs 10% throughput but buys significant margin
  4. Crystal selection at design time prevents the problem entirely
  5. Auto-baud handles unknown peer clocks in field-upgradable systems

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.

References

  1. NXP Semiconductors, “AN14458: How to reach LPUART maximum baud rate of 24 Mbit/s on MCX A series”, Rev. 1.0, October 2024. https://www.nxp.com/docs/en/application-note/AN14458.pdf
  2. Renesas Electronics, “What is the allowable baud rate error in UART reception? How is this error calculated?”, FAQ No. 1006449, April 2006. https://en-support.renesas.com/knowledgeBase/16980169
  3. Microchip Technology, “TB3331: Debugging Serial Interfaces in Embedded Systems”, DS90003331. https://ww1.microchip.com/downloads/aemDocuments/documents/MCU08/ApplicationNotes/ApplicationNotes/TB3331-Debug-SerialInterf-EmbeddedSystems-DS90003331.pdf
  4. STMicroelectronics, “STM32F4 Series Reference Manual”, RM0090, Rev. 18. https://www.st.com/content/ccc/resource/technical/document/reference_manual/3d/6d/5a/66/b4/99/40/d4/DM00031020.pdf/files/DM00031020.pdf/jcr:content/translations/en.DM00031020.pdf
  5. Texas Instruments, “UART Baud Rate Tolerance and Clock Accuracy”, Application Report SPRA887, 2013. https://www.ti.com/lit/an/spra887/spra887.pdf
  6. Valvano, J.W., “Embedded Systems: Introduction to ARM Cortex-M Microcontrollers”, Chapter 9: Serial Communication, 5th ed., 2020.

Frequently Asked Questions

What causes a UART framing error?

A framing error occurs when the receiver samples the stop bit and finds logic LOW instead of the expected HIGH. The most common cause is baud rate mismatch between transmitter and receiver, where accumulated timing drift pushes the stop-bit sample into the previous data bit's time slot. Other causes include incorrect frame format (data bits, parity, stop bits) and electrical noise on long cables.

How do I calculate the allowable baud rate tolerance for my UART link?

For 8N1 frames (1 start + 8 data + 1 stop = 10 bits), the theoretical tolerance is approximately 3% per device. The combined mismatch between both endpoints must stay under ~2% total. With oversampling (16x), the formula is: slow tolerance = ((SAM/2)-1) / ((SAM×BIT)-(SAM/2)+2), fast tolerance = ((SAM/2)-2) / (SAM×BIT), where SAM is samples per bit and BIT is total bits per frame.

Why does my UART work at 9600 baud but fail at 115200 baud with the same clock?

Higher baud rates have shorter bit periods, so the same absolute clock error represents a larger percentage of the bit time. At 115200 baud (8.68 µs/bit), a 1% clock error shifts sampling by 87 ns per bit — by the stop bit this accumulates to ~870 ns drift, exceeding the noise margin. At 9600 baud (104 µs/bit), the same 1% error is only 1 µs per bit, well within tolerance.

How can I fix framing errors without changing hardware?

First, verify both sides use identical frame format (8N1, 8E1, etc.). Enable 2 stop bits instead of 1 to increase the sampling margin for the stop bit. Reduce the baud rate if possible. If your MCU supports it, use fractional baud rate generators or auto-baud detection. Add a small delay between continuous frames to let the receiver re-synchronize on each start bit.

What tools should I use to debug UART framing errors?

Start with a logic analyzer or oscilloscope to measure the actual bit period on the TX line and verify it matches the expected baud rate. Check the UART status register for FE (framing error), ORE (overrun), and NE (noise error) flags. Use loopback testing (TX to RX on the same device) to isolate whether the problem is local configuration or the link partner.

Tags

uartbaud-rateframing-errordebuggingembedded-c

Share


Previous Article
Fixing ThreadX Preemption Threshold Priority Inversion
Jithin Tom

Jithin Tom

A Closer Look at C/C++, RTOS, and Embedded Systems

Related Posts

Fixing I2C Stuck Bus: SDA/SCL Recovery in Multi-Device Sys
Fixing I2C Stuck Bus: SDA/SCL Recovery in Multi-Device Sys
November 29, 2026
9 min
© 2026, All Rights Reserved.
Powered By Netlyft

Quick Links

Advertise with usAbout UsContact Us

Social Media