Skip to content
Tactiverge

Textbooks/Electrical and Embedded Systems/Chapter 8Lite (plain text) version

8Talking between chips

Version 1 · Technically checked (automated checks only) · 3 source lessons · 8 practice items

Text
All chapters and search
  1. 1. Charge, current and voltage
  2. 2. Ohm's law and real components
  3. 3. Series, parallel and dividers
  4. 4. Power, energy and batteries
  5. 5. Inside a microcontroller
  6. 6. Pins, inputs and sensors
  7. 7. PWM, state machines and actuators
  8. 8. Talking between chips
  9. 9. Registers, interrupts and integration

Introduction

Sensors, displays and radios talk to the microcontroller over a handful of wires. UART sends bytes on one wire with a start bit and a stop bit at an agreed speed. I²C shares two wires among many devices, each with an address, and every byte is acknowledged. SPI uses a clock and separate data lines to swap bytes at high speed. Knowing the framing lets you calculate throughput and decode a captured signal by eye.

Start, eight data bits, stop0start1b00b10b20b30b40b51b60b71stopbyte 0x41, sent least significant bit first10 bits at 9600 baud = 1.042 ms960 bytes per second
Figure 8.1. Start, eight data bits, stop. A UART frame for the byte 0x41: a start bit 0, eight data bits sent least significant first (10000010), and a stop bit 1. Ten bits at 9600 baud take 1.042 ms, giving 960 bytes per second.

Explanation

This chapter is built from 3 School lessons. Each part below is the lesson's own explanation; open the lesson for its predict-and-discover activities.

8.1 UART: one wire, ten bits, one byte

There is no clock wire between your laptop and a GPS module, yet not a single bit gets lost. How does the receiver know when each bit starts?

Asynchronous means no shared clock

A UART line rests high (idle). To send a byte, the transmitter pulls it low for one bit time: the start bit. The receiver sees that falling edge, waits half a bit, then samples once per bit time. Both sides must agree on the baud rate in advance; each keeps its own clock, so they only have to stay in step for one short frame before the next start bit lines them up again.

The frame, bit by bit

After the start bit come 8 data bits, least significant bit first, then an optional parity bit, then a stop bit (high) that returns the line to idle. The common format 8N1 means 8 data bits, no parity, 1 stop bit: 10 bits on the wire per byte. 8E1 adds an even-parity bit (11 bits). The letter A is 0x41 = 01000001, so the data bits go out as 1 0 0 0 0 0 1 0.

Parity: a one-bit alarm

With even parity the transmitter picks the parity bit so the total number of 1s in data + parity is even. 0x41 has two 1s, so its even-parity bit is 0. If noise flips any single bit, the count becomes odd and the receiver flags the frame. Two flipped bits cancel out and slip through, so parity detects errors but cannot correct them; real protocols add checksums on top.

When the text turns to garbage

A baud-rate mismatch makes the receiver sample in the wrong places, so bytes decode as nonsense or framing errors (no high stop bit where one was expected). Other usual suspects: transmit wired to transmit instead of crossing TX→RX, no shared ground, or a 5 V device talking to a 3.3 V input. UART voltage levels are a separate choice from the frame format.

Derivation: From baud rate to bytes per second
  1. One bit lasts T = 1/baud seconds. At 9600 baud, T = 1/9600 s ≈ 104.2 µs.

  2. One 8N1 frame is 1 start + 8 data + 1 stop = 10 bits, so it lasts 10·T ≈ 1.042 ms.

  3. Back to back with no idle gaps, frames per second = 1/(10·T) = baud/10 = 960.

  4. Each frame carries one data byte, so the maximum data rate is 960 bytes/s. In general: bytes/s = baud ÷ (bits per frame).

Common mix-ups

  • Baud rate ÷ 8 gives bytes per second.
    ✓ Divide by the frame length: 10 bits for 8N1, so 9600 baud carries 960 bytes/s, not 1200.
  • Bytes are sent most significant bit first, just as we write them.
    ✓ UART sends the least significant bit first; I²C and most SPI devices send the most significant bit first.
  • Parity can fix a corrupted byte.
    ✓ Parity only detects an odd number of flipped bits. It cannot tell which bit flipped, and two flips go unnoticed.

Open the full lesson: UART: one wire, ten bits, one byte →

8.2 I²C: decoding a bus conversation

Twenty sensors share the same two wires, and none of them talk over each other. Who decides who speaks, and how does a sensor say “got it”?

Two wires, pulled up

I²C has SCL (clock, driven by the controller) and SDA (data). Devices never drive a line high: they can only pull it low or let go (open drain). Pull-up resistors bring released lines back high. So two devices can never fight, one pushing high and one low; at worst both pull low. It also means a 0 is a definite act, which is why the acknowledge is a 0.

Start, address, acknowledge

A transaction begins with START: SDA falls while SCL is high (data normally changes only while SCL is low). Then the controller sends the address byte: 7 address bits, MSB first, plus R/W (0 = write, 1 = read). On the 9th clock it releases SDA; the device with that address pulls it low: ACK. If nobody does, SDA stays high: NACK, meaning no such device (or it is busy).

Reading a register

Most sensors keep values in numbered registers. A register read is: START, address+W, register index (target ACKs both), repeated START, address+R, then the target sends data bytes. Now the controller acknowledges: ACK means “send another”, and a NACK on the last byte means “that's enough”, followed by STOP (SDA rises while SCL is high).

Counting the time

Every byte costs 9 clocks: 8 data bits and the acknowledge. Reading 2 data bytes from a register is 5 bytes on the bus, so 45 clocks: 450 µs at standard mode (100 kHz) or 112.5 µs at fast mode (400 kHz), before counting the START, repeated START and STOP. The addressing overhead is why I²C suits small, occasional reads rather than streaming video.

Derivation: How long a register read takes
  1. List the bytes: address+W, register index, address+R (after the repeated START), then n data bytes: 3 + n bytes.

  2. Each byte is 8 data clocks plus 1 acknowledge clock: 9 clocks per byte, so 9(3 + n) clocks.

  3. One clock lasts 1/f. At 100 kHz that is 10 µs; at 400 kHz, 2.5 µs.

  4. Time ≈ 9(3 + n)/f. For n = 2: 45 clocks → 450 µs at 100 kHz, 112.5 µs at 400 kHz (START/STOP conditions add a little more).

Common mix-ups

  • The address byte on the wire is the 7-bit address itself.
    ✓ It is the address shifted left with R/W in the lowest bit, so 0x48 appears as 0x90 (write) or 0x91 (read).
  • I²C devices drive the data line high and low like any output.
    ✓ They only pull low or let go; pull-up resistors make the highs. That is what makes sharing the bus safe.
  • A NACK always means an error.
    ✓ A NACK after the address usually means no device; a NACK on the last byte of a read is the normal way to finish.

Open the full lesson: I²C: decoding a bus conversation →

8.3 SPI: swapping bytes at full speed

A tiny colour screen needs over a megabyte every second. Which bus can keep up, and why does reading from it mean sending something too?

Four wires, one conversation at a time

SCLK is the clock from the controller. MOSI (controller out, peripheral in) and MISO (controller in, peripheral out) carry data. CS (chip select, active low) picks which peripheral is listening: each peripheral normally gets its own CS line, so four devices need four CS pins. There are no addresses: pulling a CS low is the address.

Two shift registers in a ring

Inside, the controller and the peripheral each hold an 8-bit shift register, joined in a ring by MOSI and MISO. On each clock, each side shifts its most significant bit out and takes the other side's bit in. After 8 clocks the bytes have swapped. That is why SPI is full duplex, and why reading always means writing something.

Modes: when to sample

Devices differ on the clock's idle level (CPOL) and on which edge data is sampled (CPHA), giving modes 0–3. Mode 0 (clock idles low, sample on the rising edge) is the most common. Controller and peripheral must use the same mode, or every bit is read half a clock off. The datasheet always states it; check it before blaming the wiring.

Choosing a bus

UART: 2 wires, point to point, no clock; 115200 baud 8N1 is about 11.5 kB/s. I²C: 2 wires shared by many addressed devices, acknowledged; 400 kHz gives at most about 44 kB/s before addressing overhead. SPI: 3 wires plus a CS per device, no addressing or acknowledge; 10 MHz moves 1.25 MB/s. Choose by data rate, number of devices and spare pins.

Derivation: SPI burst time and data rate
  1. SPI moves one bit per clock edge pair and has no start, stop, parity or acknowledge bits.

  2. So N bytes need exactly 8N clocks (with CS held low and no gaps).

  3. One clock lasts 1/f, so the burst takes t = 8N/f. With f in MHz, t comes out in microseconds.

  4. The maximum data rate is N/t = f/8 bytes per second: 8 MHz → 1 000 000 bytes/s.

Common mix-ups

  • You can read from SPI without writing.
    ✓ Every clock shifts one bit each way; reading N bytes means sending N bytes (often dummies).
  • SPI devices have addresses like I²C devices.
    ✓ SPI has none: the chip-select line picks the device, at the cost of one pin each.
  • If the wiring is right, any SPI mode will work.
    ✓ Controller and peripheral must agree on CPOL and CPHA; the wrong mode shifts every bit by half a clock.

Open the full lesson: SPI: swapping bytes at full speed →

Worked examples

UART: one wire, ten bits, one byte: example 1

A logic analyser shows, after the start bit, the data bits 0 0 1 0 1 1 0 0 (first to last). What byte is it?

Solution

The first bit is bit 0. Reverse to read MSB first: 00110100 = 32 + 16 + 4 = 52 = 0x34, the ASCII character '4'.

UART: one wire, ten bits, one byte: example 2

How long does one 8E1 frame take at 115200 baud?

Solution

11 bits × (1/115200 s) = 11 × 8.68 µs ≈ 95.5 µs.

I²C: decoding a bus conversation: example 1

A capture shows the first byte after START as SDA bits 1 1 0 1 0 0 0 1 (MSB first), then SDA low on the 9th clock. Decode it.

Solution

11010001 = 0xD1. The top 7 bits 1101000 = 0x68 are the address; the last bit 1 means read. SDA low on clock 9 is an ACK: a device at 0x68 is present and ready to send.

I²C: decoding a bus conversation: example 2

After sending address 0x3C+W, SDA stays high on the 9th clock. What does it mean and what would you check?

Solution

NACK: no device acknowledged 0x3C. Check the address in the datasheet (some quote the 8-bit form 0x78), the wiring and the pull-up resistors, and that the device is powered.

SPI: swapping bytes at full speed: example 1

How long does it take to send 64 bytes to an SD card at 4 MHz?

Solution

64 × 8 = 512 clocks. 512 / 4 MHz = 128 µs.

SPI: swapping bytes at full speed: example 2

A board has 3 SPI peripherals and 1 I²C sensor. How many microcontroller pins do the buses use?

Solution

SPI: SCLK, MOSI, MISO shared (3) plus one CS each (3) = 6. I²C: SDA and SCL = 2. Total 8 pins.

Interactive figures

Figure 8.2 from UART: one wire, ten bits, one bytePick the letter A (65) and look at the waveform: find the start bit and read the data bits from left to right. Then flip one data bit with parity off, then with even parity on. Which setting notices the damage?
Can't use the interactive? Read a description instead

The UART diagram draws one frame as a square wave. For the letter A (65 = 0x41) with even parity the line reads, in time order: start 0, data 1 0 0 0 0 0 1 0, parity 0, stop 1. Choosing a byte updates the bits; choosing a data bit to flip inverts it and the readout reports the wrongly decoded byte and whether the parity check fails (it fails for any single flip when parity is on; with no parity the error is not noticed).

Interactive figure (online). Description: The UART diagram draws one frame as a square wave. For the letter A (65 = 0x41) with even parity the line reads, in time order: start 0, data 1 0 0 0 0 0 1 0, parity 0, stop 1. Choosing a byte updates the bits; choosing a data bit to flip inverts it and the readout reports the wrongly decoded byte and whether the parity check fails (it fails for any single flip when parity is on; with no parity the error is not noticed).

Figure 8.3 from I²C: decoding a bus conversationLeave the address at 0x48 and step through the register read one byte at a time. Watch the 9th bit of each byte: who drives it, and why is the very last one different?
Can't use the interactive? Read a description instead

The I²C diagram lists a register read from address 0x48, register 0x00, with sample data 0x1A and 0xC3: byte 1 address+W 0x90 ACK by target; byte 2 register 0x00 ACK by target; byte 3 address+R 0x91 ACK by target; byte 4 data 0x1A ACK by controller; byte 5 data 0xC3 NACK by controller, then STOP. Each step shows the 8 SDA bits most significant first and the 9th acknowledge bit. The readout totals 45 clocks: 450 µs at 100 kHz and 112.5 µs at 400 kHz.

Interactive figure (online). Description: The I²C diagram lists a register read from address 0x48, register 0x00, with sample data 0x1A and 0xC3: byte 1 address+W 0x90 ACK by target; byte 2 register 0x00 ACK by target; byte 3 address+R 0x91 ACK by target; byte 4 data 0x1A ACK by controller; byte 5 data 0xC3 NACK by controller, then STOP. Each step shows the 8 SDA bits most significant first and the 9th acknowledge bit. The readout totals 45 clocks: 450 µs at 100 kHz and 112.5 µs at 400 kHz.

Figure 8.4 from SPI: swapping bytes at full speedSet the controller to 0x9F and the peripheral to 0x3C. Clock once at a time and watch both registers. After how many clocks have the two bytes completely swapped places?
Can't use the interactive? Read a description instead

The SPI diagram shows two 8-bit registers. Starting with the controller holding 0x9F (10011111) and the peripheral holding 0x3C (00111100), each press of Clock once shifts both registers left by one: the controller's top bit goes into the peripheral's bottom bit over MOSI and the peripheral's top bit goes into the controller's bottom bit over MISO. After 8 clocks the controller holds 0x3C and the peripheral holds 0x9F: the bytes have swapped.

Interactive figure (online). Description: The SPI diagram shows two 8-bit registers. Starting with the controller holding 0x9F (10011111) and the peripheral holding 0x3C (00111100), each press of Clock once shifts both registers left by one: the controller's top bit goes into the peripheral's bottom bit over MOSI and the peripheral's top bit goes into the controller's bottom bit over MISO. After 8 clocks the controller holds 0x3C and the peripheral holds 0x9F: the bytes have swapped.

Laboratory

Everything runs in your browser. No kit, nothing mains-powered. Simulations are simplified educational models.

  • Studio

    Code Lab

    Write a function that turns a byte into its ten-bit UART frame and another that decodes a frame back into a byte.

    Open Code Lab →
  • Nexus project

    Nexus: Computer-Controlled Machine

    Decide which bus each device in the machine should use and estimate the data each one needs per second.

    Open Nexus: Computer-Controlled Machine →

Guided practice

Answers are checked on the server; wrong answers get a hint and another try. Signed in, solved items also count towards the source lesson.

Practice 1

What level does a UART transmit line sit at when nothing is being sent?

Practice 2

After the start bit, a UART frame carries the data bits 0 0 1 0 1 1 0 0 (first to last, least significant bit first). What byte value is that, in decimal?

Practice 3

At 9600 baud with 8N1 framing and no gaps, what is the maximum data rate, in bytes per second?

bytes/s

Practice 4

During the acknowledge clock, what does the receiving device do to say ACK?

Practice 5

In a multi-byte read, the controller answers the final data byte with a NACK. Why?

Practice 6

In an 8-bit SPI transfer, how many clock cycles does it take for the controller's and peripheral's bytes to swap completely?

Practice 7

Which bus suits a colour display that needs about 1 MB/s, on a board with pins to spare?

Practice 8

Four SPI peripherals share SCLK, MOSI and MISO, each with its own chip select. How many microcontroller pins does the SPI bus use?

  1. What level does a UART transmit line sit at when nothing is being sent?
    • Low (0)
    • High (1)
    • It toggles at the baud rate
  2. After the start bit, a UART frame carries the data bits 0 0 1 0 1 1 0 0 (first to last, least significant bit first). What byte value is that, in decimal?
  3. At 9600 baud with 8N1 framing and no gaps, what is the maximum data rate, in bytes per second? (bytes/s)
  4. During the acknowledge clock, what does the receiving device do to say ACK?
    • Drives SDA high
    • Pulls SDA low
    • Stops the clock
  5. In a multi-byte read, the controller answers the final data byte with a NACK. Why?
    • The data was corrupted
    • To tell the target to stop sending before the STOP condition
    • Because the target sends the acknowledge on reads
  6. In an 8-bit SPI transfer, how many clock cycles does it take for the controller's and peripheral's bytes to swap completely?
  7. Which bus suits a colour display that needs about 1 MB/s, on a board with pins to spare?
    • UART at 115200 baud
    • I²C at 400 kHz
    • SPI at 10 MHz
  8. Four SPI peripherals share SCLK, MOSI and MISO, each with its own chip select. How many microcontroller pins does the SPI bus use?

Engineering applications

  • Debug consoles

    Almost every embedded board has a UART debug port. Engineers connect it to a laptop to read log messages while the device runs, the quickest way to see what firmware is thinking.

  • Choosing a bus

    A slow temperature sensor and a fast display can share a board: the sensor on I²C, which saves pins, and the display on SPI, which moves pixels fast enough. The choice is a trade between wires and speed.

Watch

Optional verified videos. Nothing loads from YouTube until you press play.

A short, clear explanation of UART framing and baud rate.

6 min 11 s · captions on YouTube · source

Nothing loads from YouTube until you press play.

An instrument maker's clear explanation of I2C addressing, acknowledges and timing.

10 min 57 s · captions on YouTube · source

Nothing loads from YouTube until you press play.

Probes a real SPI bus with a logic analyser so you can see clock, data and chip-select line by line.

32 min 59 s · captions on YouTube · source

Nothing loads from YouTube until you press play.

  • Understanding UART (Rohde & Schwarz)
  • Understanding I2C (Rohde & Schwarz)
  • SPI: The serial peripheral interface (Ben Eater)

Chapter summary

  • UART frames each byte with a start bit and a stop bit; 10 bits per byte sets the throughput.
  • I²C uses two shared wires, a 7-bit address and an acknowledge bit after every byte.
  • SPI shifts bits out and in at the same time, with one chip-select line per device.
  • Pick a bus by trading pin count, speed, distance and the number of devices.

Glossary

Bus and link bandwidth
Bandwidth is how much data a bus or link can move per second. For a UART each byte usually costs 10 bit times: one start bit, eight data bits and one stop bit.
Bits and bytes
A bit is a single binary digit, 0 or 1. A byte is 8 bits. n bits can represent 2^n different values.
Hexadecimal
Hexadecimal is base 16, using digits 0–9 and A–F. Each hex digit stands for exactly four bits, so two hex digits describe one byte.
Endianness
Endianness is the order in which the bytes of a multi-byte value are stored in memory or sent over a link: little-endian puts the least significant byte first, big-endian the most significant.

Definitions from the Field Guide.

Project: A bus plan for a sensor board

A board has a microcontroller, a temperature sensor, an accelerometer sampled at 400 Hz, a small display and a debug port. Assign each to a bus, calculate the data rate each needs, and check that every bus has headroom at the speed you choose.

Deliverables

  • A wiring plan naming the bus for each device
  • Data-rate calculations per device
  • A headroom check for every bus

Keep your work in your Engineering Journal; it stays private unless you choose to share it.

References

  • Elecia White (2011). Making Embedded Systems: Design Patterns for Great Software. O'Reilly Media.
  • Edward A. Lee and Sanjit A. Seshia (2017). Introduction to Embedded Systems: A Cyber-Physical Systems Approach, 2nd edition. MIT Press.

Publication record

Version
1
Status
Technically checked (automated checks only)
Technical review
Automated checks only, last run 2026-11-29. No human, educator or mentor review is claimed.src/content/textbooks/textbooks.test.ts: schema, every lesson, diagram, practice item, video, Field Guide entry, lab and reference resolves; figure numbers recomputed; no practice answers in client payloads.
Written by
Compiled and written by the Tactiverge team with AI assistance, from Tactiverge School lessons that were themselves written with AI assistance.
Licence
All rights reserved by the founders unless a licence is approved.
Corrections
None recorded yet.Spotted a mistake? Use “Report a problem” on any chapter, or see the corrections page.