Embedded Systems8 min read

UART vs SPI vs I2C: Understanding Communication Protocols

Md Shahed Alam
Md Shahed Alam
March 12, 2025
UART vs SPI vs I2C: Understanding Communication Protocols

Every embedded developer needs to know these three protocols. They are how chips talk to each other. Here is a clear explanation of each one and when to use them.

UART (Universal Asynchronous Receiver-Transmitter)

UART is the simplest protocol. Two wires — TX (transmit) and RX (receive). No clock signal. Both devices agree on a baud rate (e.g., 115200 bits per second) beforehand.

UART is point-to-point: one transmitter, one receiver. It is ideal for debug output, GPS modules, GSM modules, and communication between two microcontrollers.

// Initialize UART at 115200 baud
UART_Init(UART1, 115200);

// Send a byte
UART_SendByte(UART1, 'A');

// Receive a byte (blocking)
uint8_t data = UART_ReceiveByte(UART1);

SPI (Serial Peripheral Interface)

SPI uses four wires: MOSI (master out), MISO (master in), SCLK (clock), and CS (chip select). The master generates the clock. Multiple slaves can share MOSI/MISO/SCLK but each needs its own CS line.

SPI is fast — up to tens of MHz. It is great for displays, SD cards, ADCs, and DACs where speed matters.

CS_Low();           // Select the device
SPI_Transfer(0x01); // Send command
uint8_t response = SPI_Transfer(0x00); // Receive data
CS_High();          // Deselect

I2C (Inter-Integrated Circuit)

I2C uses only two wires: SDA (data) and SCL (clock). Multiple devices share the same two wires — each device has a unique 7-bit address. This makes it excellent when you have many sensors but limited pins.

I2C is slower than SPI (typically 100kHz to 400kHz) but the low pin count makes it the default choice for sensors: temperature sensors, IMUs, OLEDs, RTCs.

// Read from an I2C sensor at address 0x68
I2C_Start();
I2C_WriteByte(0x68 << 1 | 0); // address + write bit
I2C_WriteByte(0x3B);            // register to read from
I2C_Repeated_Start();
I2C_WriteByte(0x68 << 1 | 1); // address + read bit
uint8_t data = I2C_ReadByte(NACK);
I2C_Stop();

Which to choose?

Use I2C when you have many devices and limited pins. Use SPI when you need speed. Use UART for point-to-point communication and debugging. Many embedded projects use all three simultaneously for different peripherals.

Embedded Systems

Ready to build something great?

Let's talk about your project. We will give you honest advice, a clear plan, and a fair price. No pressure, no sales pitch.