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¶
- Video RS-232, RS-422, RS-485: What Are the Differences? ~10 min
Single-ended vs differential signaling, and why factories run RS-485 over hundreds of meters. - Article RS-422 and RS-485 Standards Overview and System Configurations (SLLA070) by Texas Instruments ~45 min
Termination, biasing, and half-duplex direction control, which is the part firmware has to get right. - Article CAN Bus Explained: A Simple Intro by CSS Electronics ~30 min
Frames, arbitration, identifiers, and why every car and many machines use it. CAN and CAN FD are on most job descriptions in automotive and industrial. - Article USB in a NutShell by Craig Peacock Chapters 1 to 4, ~1.5 h
Descriptors, endpoints, and enumeration. Old and still the clearest. Then use TinyUSB rather than writing your own stack.
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()andsensor_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
- Video What is RS232 and What is it Used for? and What is RS485 and How it's Used in Industrial Control Systems? by RealPars ~20 min
Plant-floor context for the two serial standards you will find on industrial equipment. - Video How to Test Automotive Serial Buses with Oscilloscopes ~30 min
CAN, LIN, and FlexRay on a scope. Useful once you own one (Module 11). - Docs TinyUSB on GitHub Reference
The USB stack the Pico SDK uses. Make your board show up as a USB serial port, a keyboard, and a mass-storage device. - Modbus, in one line: a 1979 protocol that runs over RS-485 (Modbus RTU) or TCP, still everywhere in industrial equipment. If a job mentions PLCs, learn it.