Embedded firmware

Communication Protocols on STM32 (Part 0): Overview and roadmap

A series on microcontroller communication protocols (UART, SPI, I²C, CAN, LIN, RS-485, Modbus, 1-Wire, USB, Ethernet), each to be wired up and measured on an STM32. This part introduces the series and compares the protocols.

2 min read
Communication Protocols on STM32 (Part 0): Overview and roadmap

An embedded product rarely consists of a microcontroller on its own. It reads sensors, writes to memory, draws on a display, and talks to another MCU, a computer or a network. Every link needs a protocol, and many of the hardest bugs (lost packets, noise, latency, works on the bench but not in the field) come from choosing the wrong protocol or configuring it badly.

This series goes through the protocols you will meet most often. Each part has a short piece of theory, STM32 configuration, and a plan for measurements on real hardware.

What each part covers

Each part starts with the principles: signals, frame format and the parameters you need to know. Then comes STM32 configuration with STM32CubeIDE and HAL, down to registers where needed, in polling, interrupt and DMA modes, along with a wiring diagram and a table of common faults and fixes.

The measurements use a logic analyzer and an oscilloscope to capture waveforms, real throughput and error rates. The articles currently contain calculated figures; the measured columns will be filled in once the code runs on hardware. Photos of the test setup and full source code will be added at the same time.

Quick comparison

Protocol Signal wires Topology Key traits
UART 2 (TX, RX) Point-to-point, asynchronous Simple, ubiquitous, moderate speed
SPI 4 (SCK, MOSI, MISO, CS) One master, many slaves Fast, full-duplex, one CS line per slave
I²C 2 (SCL, SDA) Addressed multi-device bus Few wires, slower than SPI, needs pull-ups
CAN / FDCAN 2 (CANH, CANL) Multi-master, message based Robust against noise, error checking, automotive and industrial
LIN 1 data wire One master, many slaves Cheap, low speed, used for auxiliary automotive devices
RS-485 2 (A, B) Many nodes on a long bus Differential, long distance, physical layer for many industrial protocols
Modbus (RTU, TCP) Runs over RS-485 or Ethernet Master - slave (client - server) Application protocol common in automation
1-Wire 1 data wire One master, many slaves Minimal wiring, low speed, used for sensors
USB CDC 2 (D+, D−) Host - device Virtual COM port straight to a PC
Ethernet / TCP-IP PHY + twisted pairs TCP/IP network Networking built in, needs a protocol stack

Roadmap

  1. Overview and roadmap (this post)
  2. UART
  3. SPI
  4. I²C
  5. CAN / FDCAN
  6. LIN
  7. RS-485
  8. Modbus (RTU and TCP)
  9. 1-Wire
  10. USB CDC
  11. Ethernet and TCP/IP

The order and list may change depending on instruments and hardware. Parts not yet published are marked "Coming soon" in the series box at the top of each article.

Test setup

This section will be updated once the setup is settled: the STM32 family and board used throughout the series, the logic analyzer, the oscilloscope, and the peripheral modules used for measurements.

Next

Part 1 starts with UART. It is the simplest protocol, but there are quite a few traps once you move to interrupts and DMA.