MyRoboPathOpen Robotics Lab
microcontrollers16 min readUpdated 2026-03-12Beginner

Microcontroller Communication Protocols: UART, I2C, SPI & CAN Bus Explained

Master hardware serial communication buses: compare UART asynchronous serial, I2C 2-wire multi-device bus, SPI high-speed synchronous streaming, and industrial CAN bus.

MyRoboPath Engineering Lab
Peer-Reviewed Open-Source Hardware & Firmware Guide

Key Engineering Takeaways

  • •UART is an asynchronous point-to-point protocol requiring only 2 wires (TX and RX) and a shared Baud rate (e.g. 115200).
  • •I2C is a synchronous 2-wire multi-device bus (SDA and SCL) where up to 127 sensor breakout boards share the same two pins via unique 7-bit hexadecimal addresses.
  • •SPI is a synchronous 4-wire high-speed master-slave protocol (MOSI, MISO, SCK, CS) capable of 10MHz - 80MHz speeds for displays and SD cards.
  • •I2C requires 4.7kΩ pull-up resistors on both SDA and SCL lines because devices use open-drain outputs.
Prerequisites
  • • Basic Microcontroller GPIO and Digital logic
Required Hardware / Tools
  • • ESP32 / Arduino
  • • I2C OLED Display (SSD1306) or MPU6050 IMU
  • • SPI SD Card Module

Why Serial Communication? Parallel vs Serial Buses

In early computing, chips communicated over Parallel buses—sending 8, 16, or 32 bits simultaneously across 32 physical copper wires. However, parallel buses suffer from wire congestion and clock skew at high speeds.

Modern embedded systems use Serial Communication, streaming bits sequentially one after another over 1 to 4 wires at megahertz frequencies.

Parallel vs serial bus communication diagram
Figure 8.1: Parallel communication (multiple wires) vs Serial communication (single bit stream).Visual Guide

I2C (Inter-Integrated Circuit 2-Wire Bus)

Invented by Philips (NXP), I2C (I-squared-C) is the most popular bus for robotics sensors (IMUs, barometers, OLED displays):

  • Wires: Only 2 lines: SDA (Serial Data) and SCL (Serial Clock).
  • Topology: Multi-device bus. You can connect up to 127 different sensor modules to the exact same two pins on your microcontroller!
  • Addressing: Every I2C sensor has a factory hardcoded 7-bit address (e.g. 0x68 for MPU6050 gyroscope). The MCU broadcasts the target address before sending data.
  • Pull-Up Resistors: Both SDA and SCL are open-drain lines and require $4.7\,\text{k}\Omega$ pull-up resistors to $3.3\,\text{V}$.
I2C multi slave bus architecture diagram
Figure 8.2: I2C multi-device bus topology: Master MCU controlling multiple sensor modules on shared SDA/SCL lines.Visual Guide

SPI (Serial Peripheral Interface High-Speed Bus)

When high throughput is required (such as color TFT LCD screens, SD card data loggers, or 1000Hz IMUs), SPI is the protocol of choice:

  • Wires (4 lines):
  • MOSI (Master Out Slave In): MCU transmits data to sensor.
  • MISO (Master In Slave Out): Sensor transmits data back to MCU.
  • SCK (Serial Clock): Synchronous clock generated by MCU.
  • CS / SS (Chip Select): Dedicated pin pulled LOW by MCU to select which slave device is currently active.
  • Speed: $10\,\text{MHz}$ to $80\,\text{MHz}$ (over $100\times$ faster than standard I2C!).
SPI bus master slave chip select diagram
Figure 8.3: SPI 4-wire high-speed bus topology showing dedicated Chip Select (CS) lines for multiple slaves.Visual Guide

Frequently Asked Questions

How do I know what I2C address my sensor is using?

You can flash a simple "I2C Scanner" sketch in Arduino IDE. The MCU scans all 127 possible addresses from 0x01 to 0x7F and prints the detected device address to the Serial Monitor.

Tags:#Basic Microcontrollers#UART#I2C#SPI#CAN Bus#Serial Protocols#Sensors