Skip to content

6. Communication

Time: 2 weeks · Board: Pico 2, a logic analyzer, one I2C sensor and one SPI device · Prerequisites: Module 5

Why this matters

Almost nothing useful happens inside one chip. Sensors, memories, displays, radios, and other processors all talk over a handful of serial buses, and every embedded job involves bringing up a device from its datasheet over one of them. UART, SPI, and I2C cover most of the board-level work. RS-485 and CAN cover most of the between-boards work in industrial and automotive systems. USB is how everything talks to a computer.

Buy the Phase 2 add-ons from the gear list now. A logic analyzer turns this module from frustrating to fun.

You will be able to

  • Explain framing, baud rate, and flow control for UART, and configure one from the registers.
  • Drive an SPI device: clock polarity and phase, chip select, and full-duplex transfers.
  • Drive an I2C device: addressing, register reads and writes, ACK/NACK, and why the pull-ups matter.
  • Read all three on a logic analyzer and decode them by eye.
  • Say what RS-232, RS-485, CAN, and USB are for and how they differ from the on-board buses.

Learn

The three on-board buses

  • Video Serial Communications Explained: UART, I2C, and SPI by Rohde & Schwarz ~15 min
    All three in one clear overview, with real waveforms.
  • Article Serial Communication by SparkFun ~30 min
    Asynchronous serial and UART framing, start and stop bits, baud rate, and the TX/RX crossover everyone gets backwards once.
  • Article Serial Peripheral Interface (SPI) by SparkFun ~30 min
    Clock, MOSI, MISO, chip select, and the four clock modes.
  • Article I2C by SparkFun ~30 min
    Addressing, start and stop conditions, ACK, and multi-device buses.
  • Article I2C in a Nutshell by Memfault Interrupt ~30 min
    The engineer's version: clock stretching, bus recovery, common failure modes, and how to debug them.
  • Article Understanding the I2C Bus (SLVA704) by Texas Instruments ~30 min
    Sizing pull-up resistors from bus capacitance and rise time. The electrical side of I2C in eight pages.
  • Docs RP2350 datasheet: UART, SPI, and I2C chapters in the RP2350 datasheet ~3 h
    For the checkpoints. Note which are Arm PrimeCell or Synopsys blocks; you will see the same IP on other vendors' chips.

Seeing the signals

  • Video EEVblog #44: Logic Analyzer Tutorial parts 1 and 2 by Dave Jones ~40 min
    What a logic analyzer is for, and how it differs from a scope. Old, still right.
  • Tool PulseView by the sigrok project Setup ~30 min
    Free software that works with $10 logic analyzers and decodes UART, SPI, I2C, and dozens more. If you bought a Saleae, its Logic 2 documentation is excellent.

Between boards and to the world

Do

  • Checkpoint 6.1: UART from the registers. Configure a UART from the RP2350 registers: baud divisor, 8N1 framing, FIFOs. Echo characters back to the terminal. Then hook the logic analyzer to TX, capture one byte, and measure the bit period. Check it against your baud rate. Change to 7E1 framing and see the difference in the capture.
  • Checkpoint 6.2: I2C sensor from its datasheet. Wire an I2C sensor breakout (a BME280 or similar). From its datasheet find the 7-bit address, the "who am I" register, and the registers for a measurement. Write a driver with sensor_read_reg() and sensor_write_reg() built on the RP2350 I2C registers, read the ID, then read and print a real temperature. Capture one transaction on the logic analyzer and label the address, the R/W bit, each ACK, and the data bytes by hand.
  • Checkpoint 6.3: SPI device from its datasheet. Drive an SPI device (a flash chip, a display, or the SPI mode of your sensor). Determine the required clock mode from its datasheet. Read its ID register. Capture the transfer and confirm the clock polarity and phase match what you configured.
  • Checkpoint 6.4: Break it and fix it. Remove one I2C pull-up and observe the bus on the analyzer. Swap MOSI and MISO on SPI. Set the wrong baud on UART. For each, write down what the capture looked like, because you will see each of these on a real board someday and want to recognize them in seconds.

Check yourself

  • A UART is set to 115200 baud, 8N1. How long does one byte take on the wire, and how many bits are that?
  • Why does SPI need a chip select line and I2C does not?
  • What does an I2C NACK after the address byte mean? After a data byte?
  • Why can you not just connect an RS-485 transceiver to a UART and forget about it? What does firmware have to control?
  • Two nodes on a CAN bus transmit at the same instant. Who wins, and how is that decided without a master?

Go deeper

Optional extras