Serial Communication Protocols
Introduction
Serial communication sends bits one after another on a few wires — not eight parallel data lines like old printer ports. That saves pins on a small MCU and works over cables from centimetres to kilometres, depending on the protocol.
You use serial every day in embedded work: UART for debug console and GPS modules, I²C for OLED displays and environmental sensors, SPI for fast ADCs and SD cards, RS-485 for factory floors. This article explains how each works, what can go wrong, and points to videos if you learn better by watching waveforms move.
What every serial link must agree on
Before bytes make sense, both sides (or all devices on a bus) must share rules:
| Question | UART example | Bus example (I²C) |
|---|---|---|
| How fast? | Baud rate 115200 | 100 kHz / 400 kHz |
| How does a frame start/end? | Start + stop bits | Start / stop conditions |
| Who generates clock? | Nobody (async) | Master on SCL |
| Byte order? | Often MSB first per byte | Same; multi-byte registers in datasheet |
| Who talks when? | Two-party turn-taking | Master addresses one slave |
In plain terms
Serial is like one-lane traffic: cars (bits) pass in single file. Everyone must agree on speed limit and whose turn it is, or you get a crash of misread data.
UART (asynchronous serial)
UART has no shared clock wire. Both sides run crystal oscillators and sample at the agreed baud rate (bits per second): 9600, 115200, etc.
One byte on the wire:
1 | |
| Setting | Common lab value |
|---|---|
| Data bits | 8 |
| Parity | None |
| Stop bits | 1 |
| Baud | 115200 |
If the MCU clock is off by more than ~2% from the USB adapter's clock, you get framing errors — garbage characters. Fix baud divider or use a better crystal.
Wiring: TX of device A → RX of device B, RX → TX, GND ↔ GND. Classic student mistake: TX–TX and no common ground.
Handshaking: RTS/CTS hardware flow control or XON/XOFF software flow control when the receiver cannot keep up. Debug UART often uses none — keep messages short or use a ring buffer.
Videos — UART
Fun and Easy UART - How the UART Serial Communication Protocol Works
SPI (Serial Peripheral Interface)
SPI uses a shared clock (SCK). The master (usually your MCU) clocks data in and out simultaneously on two data lines:
| Line | Direction (from master view) |
|---|---|
| MOSI | Master out, slave in |
| MISO | Master in, slave out |
| SCK | Clock |
| CS / SS | Chip select — one per slave |
Full duplex: while you send a byte, you receive one. Mode 0–3 (CPOL/CPHA) defines which clock edge shifts data — must match the slave datasheet.
Pros: Fast, simple logic. Cons: More pins; no built-in addressing (extra CS line per chip); distance limited to PCB scale.
Videos — SPI
What is SPI? Basics for beginners!
Electronic Basics #36: SPI and how to use it
I²C (Inter-Integrated Circuit)
I²C uses only two wires shared by many devices:
| Line | Role |
|---|---|
| SDA | Data |
| SCL | Clock (master drives) |
Open drain and pull-ups
I²C devices only pull lines low or release them. Pull-up resistors (often 4.7 kΩ on 3.3 V) pull SDA and SCL high when nobody pulls low. That is open drain — multiple devices can share the bus without fighting.
If pull-ups are missing or too weak, edges look rounded and timing fails. If too strong, power waste and sharp edges cause reflections on long cables.
Master, slaves, and addresses
- Master starts transactions, clocks SCL, sends addresses.
- Slaves respond only when addressed.
- 7-bit address is common (128 possibilities; some addresses reserved).
- R/W bit after address: read or write direction.
- ACK: receiver pulls SDA low for one clock to say "got it".
- NACK: line stays high — error or end of read.
Speed: Standard 100 kHz, Fast 400 kHz, Fast-mode Plus 1 MHz. Check longest cable and slave limits.
Start and stop
- Start: SDA falls while SCL is high.
- Stop: SDA rises while SCL is high.
Without proper start/stop, slaves lose byte alignment.
When to choose I²C
Many sensors and small displays on one bus, few pins, moderate speed. Not for megabytes per second — use SPI or parallel.
Videos — I²C
What is I2C, Basics for Beginners
Tech Note 075 - How to connect and get I2C devices working
RS-232 vs RS-485
| RS-232 | RS-485 | |
|---|---|---|
| Electrical | Single-ended ± voltages | Differential A/B pair |
| Distance | Short (~15 m) | Up to ~1200 m |
| Topology | Point-to-point | Multi-drop bus |
| Embedded today | USB–serial adapter to PC | Modbus, BACnet, industrial |
RS-485 tips: termination resistor at both ends of long bus (~120 Ω), bias resistors so idle state is defined, half vs full duplex transceiver choice.
Videos — RS-232 and RS-485
What is RS232 and What is it Used for?
What is RS485 and How it's used in Industrial Control Systems?
Application framing above the wire
UART/I²C/SPI deliver bytes. Your product still needs meaning:
| Technique | Example |
|---|---|
| Newline-terminated text | printf debug lines |
| Length prefix | Byte 0 = payload length |
| CRC | Modbus CRC16, custom packet tail |
| COBS / SLIP | Framing with reserved bytes |
Example binary packet:
1 | |
Validate CRC before driving actuators on safety-related commands.
Other protocols (overview)
| Protocol | Physical | Typical use |
|---|---|---|
| Modbus RTU | RS-485 | PLCs, VFDs |
| CAN | Differential | Automotive, robotics |
| USB | D+/D− | PC connection |
| MQTT | TCP/IP | Cloud — see MQTT and IoT messaging |
See Connectivity architecture and PLCs and industrial control.
Debugging serial issues
- Logic analyzer — decode I²C/UART/SPI (Lab tools for prototyping).
- Loopback — TX to RX on same board.
- Common GND — always.
- 3.3 V vs 5 V — level shifter if needed.
- I²C scan — discover addresses before blaming library.
Relevant topics
- Input/output and DMA
- Computer networks
- MQTT and IoT messaging
- Hardware architecture
- I2C specification (NXP UM10204)
Starting points
- Echo UART in interrupt + ring buffer.
- I²C scan sketch or tool — list addresses on bus.
- Capture SPI with logic analyzer — verify mode and CS timing.
- Parse Modbus RTU frame with CRC in Python.
Focus points
- Baud and SPI mode must match datasheet — software cannot fix wrong wiring.
- I²C pull-ups on every bus — on module or on main board.
- ISRs store bytes only — parse in main loop or task.
- CRC on anything that moves motors or safety outputs.
Key points
- UART is async with agreed baud; SPI/I²C use a shared clock from the master.
- I²C needs open-drain lines and pull-ups; master sends address + R/W.
- RS-485 carries industrial buses over long differential links.
- Use videos + logic analyzer when text alone does not click — see waveforms.