Lite / Intelligent Robotic Systems / Week 30
UART: one wire, ten bits, one byte
There is no clock wire between your laptop and a GPS module, yet not a single bit gets lost. How does the receiver know when each bit starts?
Why should I care?
Almost every microcontroller has a UART, and almost every debugging session starts with one: printing sensor values, talking to a GPS or Bluetooth module, flashing firmware. When the text comes out as garbage, the fix is nearly always in the frame: the wrong baud rate, the wrong parity, or a missing ground wire. Knowing the ten bits of a frame turns that garbage into a diagnosis.
- Draw a UART frame: idle high, start bit, 8 data bits least significant first, optional parity, stop bit.
- Convert a baud rate into bit time, frame time and maximum bytes per second.
- Decode a captured frame into a byte and its ASCII character, and check its parity.
Predict
A UART sends at 9600 baud (9600 bits per second). About how many bytes of text per second can it carry?
- 1200 bytes/s (9600 ÷ 8)
- 960 bytes/s
- 9600 bytes/s
Guess first, then reveal
About 960. Each byte travels inside a frame of 10 bits (a start bit, 8 data bits and a stop bit), so 9600 ÷ 10 = 960 bytes per second. The framing costs 20% of the line.
Discover
Pick the letter A (65) and look at the waveform: find the start bit and read the data bits from left to right. Then flip one data bit with parity off, then with even parity on. Which setting notices the damage?
What the interactive shows (text version)
The UART diagram draws one frame as a square wave. For the letter A (65 = 0x41) with even parity the line reads, in time order: start 0, data 1 0 0 0 0 0 1 0, parity 0, stop 1. Choosing a byte updates the bits; choosing a data bit to flip inverts it and the readout reports the wrongly decoded byte and whether the parity check fails (it fails for any single flip when parity is on; with no parity the error is not noticed).
Watch (optional)
Watch for: Watch for the start bit that wakes the receiver up and the order the data bits arrive in.
A short, clear explanation of UART framing and baud rate.
“Understanding UART” by Rohde & Schwarz (opens YouTube; streaming video uses a lot of data)
The video is optional. Everything you need is in this lesson's text.
Understand
Asynchronous means no shared clock
A UART line rests high (idle). To send a byte, the transmitter pulls it low for one bit time: the start bit. The receiver sees that falling edge, waits half a bit, then samples once per bit time. Both sides must agree on the baud rate in advance; each keeps its own clock, so they only have to stay in step for one short frame before the next start bit lines them up again.
The frame, bit by bit
After the start bit come 8 data bits, least significant bit first, then an optional parity bit, then a stop bit (high) that returns the line to idle. The common format 8N1 means 8 data bits, no parity, 1 stop bit: 10 bits on the wire per byte. 8E1 adds an even-parity bit (11 bits). The letter A is 0x41 = 01000001, so the data bits go out as 1 0 0 0 0 0 1 0.
Parity: a one-bit alarm
With even parity the transmitter picks the parity bit so the total number of 1s in data + parity is even. 0x41 has two 1s, so its even-parity bit is 0. If noise flips any single bit, the count becomes odd and the receiver flags the frame. Two flipped bits cancel out and slip through, so parity detects errors but cannot correct them; real protocols add checksums on top.
When the text turns to garbage
A baud-rate mismatch makes the receiver sample in the wrong places, so bytes decode as nonsense or framing errors (no high stop bit where one was expected). Other usual suspects: transmit wired to transmit instead of crossing TX→RX, no shared ground, or a 5 V device talking to a 3.3 V input. UART voltage levels are a separate choice from the frame format.
Explain it another way
Intuitive
It is like a starter's pistol at a race. Everyone is quiet (idle high), the pistol fires (start bit), and then the receiver counts: one, two, three… reading one bit on each beat. It only has to count accurately for ten beats before the next pistol shot resets everything.
Technical
A UART is a shift register plus a baud-rate generator. The receiver oversamples (often 16× the baud rate), detects the falling start edge, and samples each bit near its centre. Clock error between the two ends must stay under roughly half a bit across the whole frame, which for 10 bits means a few per cent at most.
Mathematical
Bit time T = 1/baud. Frame time = n·T for an n-bit frame (n = 10 for 8N1, 11 for 8E1 or 8N2). Maximum throughput = baud/n bytes per second. At 115200 baud 8N1: T ≈ 8.68 µs, frame ≈ 86.8 µs, throughput = 11 520 bytes/s.
Applied
A robot logging 20-byte sensor packets 100 times a second needs 2000 bytes/s. At 9600 baud 8N1 (960 bytes/s) the log falls behind; at 115200 baud (11 520 bytes/s) it uses about 17% of the link, leaving room for debug messages.
Derivation: From baud rate to bytes per second
One bit lasts T = 1/baud seconds. At 9600 baud, T = 1/9600 s ≈ 104.2 µs.
One 8N1 frame is 1 start + 8 data + 1 stop = 10 bits, so it lasts 10·T ≈ 1.042 ms.
Back to back with no idle gaps, frames per second = 1/(10·T) = baud/10 = 960.
Each frame carries one data byte, so the maximum data rate is 960 bytes/s. In general: bytes/s = baud ÷ (bits per frame).
Worked example 1
A logic analyser shows, after the start bit, the data bits 0 0 1 0 1 1 0 0 (first to last). What byte is it?
The first bit is bit 0. Reverse to read MSB first: 00110100 = 32 + 16 + 4 = 52 = 0x34, the ASCII character '4'.
Worked example 2
How long does one 8E1 frame take at 115200 baud?
11 bits × (1/115200 s) = 11 × 8.68 µs ≈ 95.5 µs.
Common mix-ups
Baud rate ÷ 8 gives bytes per second.
✓ Divide by the frame length: 10 bits for 8N1, so 9600 baud carries 960 bytes/s, not 1200.Bytes are sent most significant bit first, just as we write them.
✓ UART sends the least significant bit first; I²C and most SPI devices send the most significant bit first.Parity can fix a corrupted byte.
✓ Parity only detects an odd number of flipped bits. It cannot tell which bit flipped, and two flips go unnoticed.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
Apply it
Design the UART link for a weather station that sends a 32-byte packet every 0.1 s. Choose the slowest standard baud rate (9600, 19200, 38400, 57600, 115200) that uses under half the link with 8N1, and show the numbers. Then add even parity: does your choice still work?
Reflect
Why can a UART work with no clock wire at all, and what would go wrong if one end's clock drifted by 10%?
Write your answer on paper or in your own notes. Lite never stores what you write.