Sub topic 2
Anatomy of a UART Frame
Assume you know Arduino’s setup() and loop() functions, bytes and binary numbers, basic C++ syntax, and the difference between digital HIGH and LOW. This chapter focuses on how UART turns one byte into a timed sequence of bits.
UART stands for Universal Asynchronous Receiver/Transmitter. It sends data without a shared clock. The receiver determines when to sample each bit from an agreed baud rate and from the frame’s start bit.
The frame layout
A UART line is usually idle at logic HIGH. A sender begins a frame by pulling the line LOW for one bit period. This is the start bit. It tells the receiver to begin timing.
The sender then transmits the data bits. A common UART format sends eight data bits, least significant bit first. For example, the byte 0b01000001 is transmitted as:
- Bit 0:
1 - Bit 1:
0 - Bit 2:
0 - Bit 3:
0 - Bit 4:
0 - Bit 5:
0 - Bit 6:
1 - Bit 7:
0
The optional parity bit follows the data. Parity is a simple error check. With even parity, the sender chooses the parity bit so that the total number of 1 bits in the data and parity is even. With odd parity, the total is odd.
One or more stop bits finish the frame. Stop bits are logic HIGH. They return the line to its idle state and give the receiver a clear boundary before the next frame.
| Format | Start bits | Data bits | Parity | Stop bits | Bits per frame |
|---|---|---|---|---|---|
| 8N1 | 1 | 8 | None | 1 | 10 |
| 8E1 | 1 | 8 | Even | 1 | 11 |
| 7O2 | 1 | 7 | Odd | 2 | 11 |
The name 8N1 means eight data bits, no parity, and one stop bit. It is the usual default for Arduino serial communication.
Reading the waveform
A receiver normally samples near the middle of each expected bit period. Sampling in the middle allows some tolerance for small timing differences between the two devices.
For an 8N1 frame, the receiver sees this logical sequence:
idle start data bits, least significant bit first stop
HIGH LOW d0 d1 d2 d3 d4 d5 d6 d7 HIGHFor the byte A, which is hexadecimal 0x41 or binary 01000001, the data portion is sent as 1 0 0 0 0 0 1 0. The wire does not carry a separate clock signal. Both devices use their local baud-rate settings to predict when each bit should occur.
Frame formats must match
Both ends must agree on the frame format. The settings commonly written as 9600 8N1 mean:
9600: baud rate8: eight data bitsN: no parity1: one stop bit
If one device expects parity and the other does not, the receiver may interpret a parity bit as a stop bit or as part of the next frame. The result can include framing errors, incorrect bytes, or no useful data.
Arduino lets you select a non-default format with the second argument to Serial.begin():
void setup() {
Serial.begin(115200, SERIAL_8E1);
}
void loop() {
}This configures 115200 baud, eight data bits, even parity, and one stop bit. The default is usually SERIAL_8N1.
Timing and useful throughput
At 9600 baud with 8N1, each frame occupies ten bit periods: one start bit, eight data bits, and one stop bit. The bit time is:
1 / 9600 seconds ≈ 104.2 microsecondsThe approximate byte rate is therefore:
9600 bits per second / 10 bits per frame = 960 bytes per secondThe useful data rate is lower than the baud rate because start and stop bits take time. With parity or additional stop bits, each byte needs more bit periods.
Exercise
Exercise
For a UART link configured as 7E1, how many bit periods does one complete frame occupy, and what is the purpose of the parity bit?
Show answer
The frame occupies 10 bit periods: one start bit, seven data bits, one parity bit, and one stop bit. The parity bit provides a simple check for some single-bit errors.