Table of Contents

Electronics Reference: Microcontroller Communication Buses (UART, SPI & I2C)

SERIAL BUS FUNDAMENTALS: UART, SPI, and I2C are the three foundational hardware protocols used by microcontrollers and flight controllers to communicate with sensors, GPS modules, telemetry radios, memory chips, and displays. Always verify logic voltage compatibility (`3.3 V` vs. `5.0 V`) and a common ground (`GND`) reference before connecting any two devices.

1. Protocol Comparison Matrix

Select the appropriate serial protocol based on required data throughput, wiring simplicity, distance, and device count:

Feature UART (Universal Asynchronous Receiver-Transmitter) SPI (Serial Peripheral Interface) I2C (Inter-Integrated Circuit)
Communication Type Asynchronous (no shared clock wire) Synchronous (dedicated `SCLK` wire) Synchronous (shared `SCL` wire)
Duplex Mode Full-Duplex (simultaneous TX & RX) Full-Duplex (simultaneous MOSI & MISO) Half-Duplex (bidirectional single `SDA` line)
Required Signal Wires 2 wires: `TX`, `RX` (+ `GND`) 4+ wires: `MOSI`, `MISO`, `SCLK`, `CS` (+ `GND`) 2 wires: `SDA`, `SCL` (+ `GND` + Pull-up resistors)
Typical Data Speed 9,600 bps – 1 Mbps (up to 4+ Mbps on modern MCUs) 1 MHz – 50+ MHz (fastest board-level bus) Standard: 100 kHz / Fast: 400 kHz / Fast+: 1 MHz
Maximum Devices Point-to-point (2 devices only per port) 1 Master + Multiple Slaves (1 `CS` pin per slave) Up to 127 devices (7-bit addressing) on 2 wires
Hardware Pull-Ups Not required (push-pull drivers) Not required (push-pull drivers) Mandatory (`2.2 kΩ – 10 kΩ` on `SDA` and `SCL`)
Max Cable Distance Moderate (~1–3 m TTL; up to 1,200 m via RS-485) Very Short (< 15–30 cm on PCB/harnesses) Short (< 0.5–1 m; limited by 400 pF bus capacitance)
Common Applications GPS/GNSS, telemetry radios, RC receivers (CRSF/SBUS), USB-to-Serial debug IMUs (gyros/accelerometers), SD cards, flash memory, high-speed TFT displays Barometers, magnetometers (compasses), OLED displays, EEPROMs, BMS monitors

2. UART (Universal Asynchronous Receiver-Transmitter)

UART transmits data asynchronously byte-by-byte without a shared clock signal. Both devices must be pre-configured to the exact same timing parameters.

2.1 Wiring & Crossover Rule

2.2 Frame Structure & Baud Rate

A standard UART packet (`8N1` configuration) consists of:

  1. Idle State: Line held `HIGH` (`3.3 V` or `5.0 V`).
  2. Start Bit: 1 bit pulled `LOW` to alert the receiver that data is starting.
  3. Data Bits: 8 bits (1 byte), transmitted Least Significant Bit (LSB) first.
  4. Parity Bit: None (`N`), Even (`E`), or Odd (`O`) for basic error checking.
  5. Stop Bit(s): 1 bit (or 2 bits) driven `HIGH` to mark the end of the frame.
  6. Baud Rate: Both sides must match within ±2% (standard rates: `9600`, `57600`, `115200`, `420000` for CRSF, `921600`).

2.3 Logic-Level UART vs. RS-232 vs. RS-485

3. SPI (Serial Peripheral Interface)

SPI is a high-speed synchronous master-slave bus ideal for real-time sensors (such as flight controller IMUs) and bulk memory transfers.

3.1 Signal Lines & Addressing

3.2 SPI Clock Modes (CPOL & CPHA)

Master and Slave must match one of four clock timing modes defined by Clock Polarity (`CPOL`) and Clock Phase (`CPHA`):

SPI Mode CPOL (Idle Clock State) CPHA (Data Sampling Edge)
Mode 0 (Most Common) `0` (Clock idles `LOW`) `0` (Sampled on rising edge, shifted on falling edge)
Mode 1 `0` (Clock idles `LOW`) `1` (Sampled on falling edge, shifted on rising edge)
Mode 2 `1` (Clock idles `HIGH`) `0` (Sampled on falling edge, shifted on rising edge)
Mode 3 `1` (Clock idles `HIGH`) `1` (Sampled on rising edge, shifted on falling edge)

4. I2C (Inter-Integrated Circuit)

I2C allows up to 127 peripheral devices to share just two wires—`SDA` (Serial Data) and `SCL` (Serial Clock)—using unique 7-bit hardware addresses.

4.1 Open-Drain Architecture & Pull-Up Resistors

4.2 I2C Addressing & Transaction Flow

  1. START Condition: Master pulls `SDA` `LOW` while `SCL` stays `HIGH`.
  2. 7-Bit Address + R/W Bit: Master clocks out the 7-bit slave address (e.g., `0x68` for MPU6050 IMU, `0x76` for BMP280 barometer) followed by a `0` (Write) or `1` (Read) bit.
  3. ACK / NACK Bit: The matching slave pulls `SDA` `LOW` on the 9th clock pulse to send an Acknowledge (`ACK`). If no device responds, the line stays `HIGH` (`NACK`).
  4. Data Bytes & STOP Condition: Data bytes follow (each followed by an `ACK`), ending when the Master releases `SDA` from `LOW` to `HIGH` while `SCL` is `HIGH` (STOP).

5. Voltage Level Shifting Between `3.3 V` and `5.0 V`

Connecting a `5.0 V` device to a `3.3 V` microcontroller without level translation can permanently damage non-5V-tolerant GPIO pins:

6. Serial Bus Troubleshooting & Debugging Checklist

When a sensor or peripheral fails to communicate, diagnose the bus systematically:

  1. [ ] Verify Power & Common Ground: Measure $V_{CC}$ at the peripheral pin and confirm `0.0 Ω` continuity between Master `GND` and Slave `GND`.
  2. [ ] Check UART `TX` / `RX` Polarity: Swap `TX` and `RX` wires if no data arrives; verify matching Baud Rate (`115200` vs. `9600`).
  3. [ ] Run an I2C Address Scanner: Flash an I2C scanner sketch to verify the peripheral responds with an `ACK` and confirm whether its 7-bit address matches your code (e.g., `0x76` vs. `0x77` depending on the `SDO`/`ADDR` pin state).
  4. [ ] Measure Idle I2C Bus Voltage: Both `SDA` and `SCL` should read steady `3.3 V` (or `5.0 V`) when idle. If either line is stuck at `0 V`, a device is holding the bus low or pull-up resistors are missing.
  5. [ ] Inspect Waveforms with a Logic Analyzer / Oscilloscope:
    • On I2C, rounded “shark-fin” rising edges on `SCL`/`SDA` indicate excessive bus capacitance or pull-up resistor values that are too high—lower pull-ups from `10 kΩ` to `2.2 kΩ – 4.7 kΩ`.
    • On SPI, confirm `CS` drops `LOW` before `SCLK` begins pulsing and returns `HIGH` after the final byte.

Electronics Reference: 1. Diodes & Transistors | 2. Integrated Circuits (ICs) | 3. Communication Buses (UART, SPI & I2C)