Serial & Framing

# UART Baud Rate & Clock Error Calculator

Calculate exact hardware baud divider registers across STM32, AVR, ESP32, nRF52 and RP2040 clocks and catch framing-error mismatches over 2%.

MCU UART ArchitectureSTM32 USART (OVER8=0, 16x)STM32 USART (OVER8=1, 8x)AVR ATmega (U2X=0, 16x)AVR ATmega (U2X=1, 8x)ESP32 / ESP32-S3 APB UARTNordic nRF52840 UARTERP2040 PL011 UART (IBRD/FBRD)UBRR = round(F\_CPU / (16 \* baud)) - 1

UART peripheral clock (Hz)16.000 MHz

Target baud rate (bps)Common: 9600, 57600, 115200, 921600

UBRR (U2X=0) 8 (0x008) Exact hardware divider setting

Actual Baud 111,111 Target: 115,200 bps

Clock Error \-3.55% Exceeds 2% framing threshold

Framing-error risk (>2% mismatch) — at -3.55% error, the stop bit of an 8N1 frame drifts by more than 20% of a bit period before receiver tolerances are added. Switch to U2X=1 / 8x oversampling, pick a baud-friendly crystal (e.g. 14.7456 MHz), or lower the baud rate.

| Target Baud | UBRR (U2X=0) | Actual Baud | Error % | 8N1 Status |
| ----------- | ------------ | ----------- | ------- | ---------- |
| 9,600       | 103 (0x067)  | 9,615       | +0.16%  | Safe       |
| 19,200      | 51 (0x033)   | 19,231      | +0.16%  | Safe       |
| 38,400      | 25 (0x019)   | 38,462      | +0.16%  | Safe       |
| 57,600      | 16 (0x010)   | 58,824      | +2.12%  | Risk (>2%) |
| 115,200     | 8 (0x008)    | 111,111     | \-3.55% | Risk (>2%) |
| 230,400     | 3 (0x003)    | 250,000     | +8.51%  | Risk (>2%) |
| 460,800     | 1 (0x001)    | 500,000     | +8.51%  | Risk (>2%) |
| 921,600     | 0 (0x000)    | 1,000,000   | +8.51%  | Risk (>2%) |
| 1,000,000   | 0 (0x000)    | 1,000,000   | +0.00%  | Safe       |

## Why 2% is the practical UART error ceiling

An 8N1 frame runs 10 bit times from the falling edge of the start bit to the middle of the stop bit (9.5 bit periods to the stop-bit sample point). A combined TX + RX clock mismatch above roughly 4.5% pushes the sample point past the stop-bit boundary and raises a Framing Error (`FE`). Splitting the budget evenly leaves about 2% per side, before subtracting HSI/RC oscillator drift over temperature.

## Classic MCU baud pitfalls

| Target               | Failure mode                                                            | Fix                                                                    |
| -------------------- | ----------------------------------------------------------------------- | ---------------------------------------------------------------------- |
| AVR @ 16 MHz, 115200 | U2X=0 yields UBRR=8 and \-3.55% error (corrupt bytes).                  | Enable U2X=1 (UBRR=16, +2.12%) or use a 14.7456 MHz crystal.           |
| STM32 APB1 vs APB2   | Passing APB2 clock into an APB1 USART init halves the actual baud rate. | Read HAL\_RCC\_GetPCLK1Freq() for USART2/3/4/5 and PCLK2 for USART1/6. |
| STM32 OVER8=1        | Writing raw USARTDIV into BRR\[3:0\] shifts the fractional nibble.      | Right-shift bits \[3:0\] by 1 and clear bit 3 per RM0090 / RM0410.     |
| Internal RC drift    | Factory HSI can sit 1–2% off over voltage/temperature.                  | Use HSE crystal for ≥230400 bps or enable auto-baud detection.         |

[Guide: UART baud mismatch debugging](https://circuittwin.ai/guides/uart-baud-mismatch-debugging) [Board: Arduino Uno (ATmega328P)](https://circuittwin.ai/boards/arduino-uno) [Board: NUCLEO-F446RE](https://circuittwin.ai/boards/nucleo-f446re) [Board: Raspberry Pi Pico (RP2040)](https://circuittwin.ai/boards/rpi-pico) [Tool: Cortex-M HardFault Decoder](https://circuittwin.ai/tools/cortex-m-hardfault-decoder)

> ## Catch UART framing errors and clock bugs in CI
>
> CircuitTwin checks configured baud dividers against attached UART peers and flags mismatches or framing errors on every run.
>
> [Start now](https://app.circuittwin.ai/try) [UART debugging guide](https://circuittwin.ai/guides/uart-baud-mismatch-debugging) [Connect a coding agent](https://circuittwin.ai/docs/agents)
