100nF

Baud rate error

Every standard baud rate at your clock, with the integer divisor the UART will actually load and the error that results. Pick a crystal before you pick a rate.

ST01234567SPreceiver sample pointsideal bit centresmarginal
Fig 1 — Where the receiver samples each bit of a 115200 baud frame. Drift at the stop bit: 35 % of a bit.
BaudDivisorActualErrorUsable
120083312000.04 %pass
24004172398-0.08 %pass
480020848080.16 %pass
960010496150.16 %pass
1920052192310.16 %pass
3840026384620.16 %pass
5760017588242.12 %FAIL
1152009111111-3.55 %FAIL
23040042500008.51 %FAIL
46080025000008.51 %FAIL
921600110000008.51 %FAIL

What it computes

A classic UART does not generate the baud rate directly. It divides the peripheral clock by an integer to get a sampling clock that runs at 16× (or 8×) the bit rate, then counts 16 samples per bit and reads the middle ones. The divisor has to be an integer, so most clock and baud rate combinations cannot be hit exactly. This is the calculation from any 8250/16550-style datasheet, and from the AVR (ATmega328 datasheet section 19.3), STM32 (RM0008 section 27.3.4) and PIC USART chapters:

divisor = round( f_clk / (oversample × baud) )
actual  = f_clk / (oversample × divisor)
error   = (actual − baud) / baud × 100 %

Register conventions differ. AVR loads UBRR = divisor − 1; 16550 and most PICs load the divisor itself. The tool shows the divisor; subtract one for UBRR. It also checks the divisor against 16 bits, because at low rates on a fast clock it will not fit even when the error is zero.

Usable is defined as |error| ≤ 2 %. That is not a UART specification, it is a budget, and the next section says where it comes from.

Worked example

ATmega328 on the stock 16 MHz crystal, 115200 baud, normal (16×) mode.

ideal   = 16 000 000 / (16 × 115 200) = 8.681
divisor = 9                    (UBRR = 8)
actual  = 16 000 000 / (16 × 9) = 111 111 baud
error   = (111 111 − 115 200) / 115 200 = −3.55 %   → FAIL

The tool gives divisor 9, actual 111111, −3.55 %, FAIL. The AVR datasheet table says the same thing in its "−3.5 %" column. Switch to double-speed (U2X, 8× sampling):

ideal   = 16 000 000 / (8 × 115 200) = 17.36
divisor = 17                   (UBRR = 16)
actual  = 16 000 000 / (8 × 17) = 117 647 baud
error   = +2.12 %              → still FAIL at the 2 % line

The Arduino core uses this U2X setting. It works against a PC because the USB bridge on the far end has almost zero error of its own; against a second 16 MHz AVR at normal speed it is 5.7 % relative and fails.

Now why the budget is about 2 %.

frame     = start + 8 data + stop = 10 bits
receiver  samples at the middle of each bit, resynchronised only at the start edge
drift at the last bit = 10 × error   (error accumulates, no resync mid-frame)
half a bit of margin   = 50 % / 10 = 5 % if the sampler were perfect
16× sampler quantisation costs ~1/16 = 6 % of a bit, majority vote a bit more
practical one-end limit ≈ ±3 %; shared between transmitter and receiver ≈ ±2 % each

So −3.55 % at one end is at the edge even against a perfect partner; add a crystal at ±50 ppm and an RC oscillator at ±1 % and it is gone. That is the whole reason 115200 on a 16 MHz AVR is unreliable, and why 9600 (divisor 104, +0.16 %) never is.

Same rate on a serial-friendly crystal:

11.0592 MHz: 11 059 200 / (16 × 115 200) = 6      exact
 7.3728 MHz:  7 372 800 / (16 × 115 200) = 4      exact
14.7456 MHz: 14 745 600 / (16 × 921 600) = 1      exact, every standard rate below it too

These frequencies are integer multiples of 115200 × 16 = 1.8432 MHz. Pick one of them and the whole table reads 0.00 %.

Where it stops being valid

Common mistakes

Further reading