Topics A–Z

MCU

UART, one bit at a time

Two wires, no shared clock, and yet the bytes arrive. Type a character and watch its frame go out: start bit, eight data bits LSB first, stop bit.

LVL 52 min read

For Makers who have used a serial monitor and know what a bit and a byte are.

LVL 4

A simpler explanation with fewer formulas.

If you’ve ever opened the serial monitor in the Arduino IDE and printed “Hello”, you’ve used UART. It sends data over one wire in each direction, with no clock wire at all. Both sides agree on a speed, the baud rate (like the 9600 or 115200 in your sketch), and trust each other to keep time.

UART is the first protocol most people meet on a microcontroller, usually as the “serial monitor”. It sends data over one wire in each direction, with no clock wire at all. Both sides simply agree in advance how fast the bits will come.

UART frame · 8N1
Baud rate
1idle0start1D00D10D20D30D40D51D60D71stop1idle← LSB first
0x41Hex
01000001Binary (MSB→LSB)
8.68 µsOne bit
86.8 µsWhole frame
Change the character or the baud rate. The highlight steps through the frame the way a receiver samples it: once per bit, in the middle.

Anatomy of a frame

The most common format is called 8N1: 8 data bits, no parity bit, 1 stop bit.

  1. Idle. The line rests high (logic 1).
  2. Start bit. The transmitter pulls the line low for one bit time. This falling edge is the receiver’s signal to start its timer.
  3. Data bits. Eight bits follow, least significant bit first. The letter A is 0x41, binary 0100 0001, so on the wire you see 1 0 0 0 0 0 1 0.
  4. Stop bit. The line goes high for at least one bit time, which guarantees the next start bit has a clean falling edge.

That’s 10 bit times to send 8 bits of data.

8N1 is only the default. An optional parity bit (even or odd) can follow the data and catch any single-bit error. Formats like 7E1 still appear on older equipment, and two stop bits give a slow receiver more time between frames. Holding the line low for longer than a whole frame is a break condition, which some protocols (LIN, for example) use as a sync marker.

Doing the timing

At 115 200 baud, one bit lasts 1 / 115 200 s, about 8.68 µs, so a whole frame takes about 86.8 µs. That puts the ceiling at 11 520 bytes per second, not 14 400, because the start and stop bits are overhead.

Why the clocks must agree

Imagine two people clapping along to the same song without hearing each other. If one claps slightly faster, they slowly drift apart. UART has the same problem, but each frame is short and the start bit lets the receiver re-sync on every letter. So a small timing difference is fine. A big one scrambles the letters, which is why garbled text in the serial monitor usually means the baud rate is set wrong.

The receiver re-synchronises on every start bit, then samples each following bit in the middle of where it expects it to be. If the two sides’ baud rates differ, the sampling point drifts a little further with every bit. By the stop bit it must still land inside the right bit, so small errors are fine and big ones garble data. As a rule of thumb, keep each side within about 2% of the nominal rate, and check your MCU datasheet’s baud-rate error table when you pick a clock.

Most UART peripherals oversample the line, typically at 16× the baud rate. They find the start edge to within 1/16 of a bit, then take a majority vote of three samples near the middle of each bit. The theoretical limit is that the sample point drifts no more than half a bit across about 9.5 bit times, roughly 5% of combined error between the two ends. Edge detection, rise times and noise eat into that, so practical budgets are tighter.