Decode I2C and SPI with a Logic Analyzer

A logic analyzer records many digital lines at once and its protocol decoders turn the ones and zeros into bytes: START, address 0x68, write, ACK, and so on. To decode I2C or SPI you connect a ground and one probe per bus wire, sample at least four times faster than the bus clock (ten or more is comfortable), and tell the decoder which channel is which and, for SPI, which clock mode the bus uses. When a sensor will not answer, the decode usually shows why within a minute.

Learning objectives

  • Wire a logic analyzer to an I2C and an SPI bus
  • Choose a sample rate and a trigger
  • Configure the I2C and SPI decoders
  • Read a decoded transaction and spot the usual faults

Prerequisites

Logic analyzer or oscilloscope?

QuestionUse
Which bytes went over the bus, and in what order?Logic analyzer
Is the address ACKed?Logic analyzer
Are the edges clean, is the high level high enough?Oscilloscope
Is a pull-up too weak (slow rising edges)?Oscilloscope

Wiring

  • Ground first: connect the analyzer's ground to the board's ground. Without it, nothing decodes reliably.
  • I2C: one channel on SCL, one on SDA. The analyzer only listens, so the pull-ups stay as they are.
  • SPI: one channel each on SCK, MOSI (or COPI), MISO (or CIPO) and the chip select of the device you care about.
  • Check the analyzer's input voltage range and threshold against your logic level (3.3 V or 5 V).

Sample rate

The analyzer samples each line at fixed intervals, so it can only place an edge to within one sample. Saleae's rule of thumb is to sample digital signals at least four times faster than their bandwidth, and to record SPI at least four times faster than the clock; the same margin or more suits I2C. For a 400 kHz I2C bus that is at least 1.6 MS/s, and 10 MS/s or more gives clean timing. For SPI at 10 MHz it is at least 40 MS/s. Digital captures use memory per edge, not per sample, so a higher rate costs little on most analyzers.

Trigger

Set the trigger on the falling edge of SDA while SCL is high for I2C (that is a START), or on the falling edge of chip select for SPI. Then start the capture and make the firmware talk to the device. The capture begins exactly where the transaction does.

Worked example 1: an I2C register write

A microcontroller writes 0x00 to register 0x6B of a sensor at 7-bit address 0x68, at 400 kHz. With the I2C decoder on SCL and SDA, the analyzer shows:

DecodedByte on the wireMeaning
STARTSDA falls while SCL is high
Address 0x68, write, ACK0xD00x68 shifted left, R/W bit 0; the sensor pulls SDA low
Data 0x6B, ACK0x6Bthe register number
Data 0x00, ACK0x00the value
STOPSDA rises while SCL is high

That is 1 + 9 + 9 + 9 + 1 = 29 bit times, 72.5 us at 400 kHz. If the address shows NACK, the device is not answering at that address: check the address (some tools show 0xD0, the 8-bit form, where the datasheet says 0x68), the power and the pull-ups.

Worked example 2: reading an SPI flash ID

Many SPI flash chips answer command 0x9F with a three-byte JEDEC ID. A Winbond W25Q128JV answers 0xEF (Winbond), 0x40 (memory type) and 0x18 (capacity, 2 to the 24th bytes, 16 MB). Set the SPI decoder to mode 0 (CPOL 0, CPHA 0), MSB first, 8 bits, chip select active low.

SPI waveform: command 0x9F on MOSI, then ID bytes 0xEF, 0x40 and 0x18 on MISO, with decoded labels
Chip select low, command 0x9F on MOSI, then the three ID bytes on MISO. The decoder lane labels each byte.

The whole read is 4 bytes, 32 clocks, 3.2 us at 10 MHz. If MISO decodes as 0xFF every time, the chip is not driving it: check chip select, power and the MISO wire. If the bytes look shifted by one bit, the decoder's mode does not match the bus; try the other CPHA.

Free and paid tools

Saleae's Logic 2 software decodes I2C, SPI, UART and many more with its own analyzers. PulseView, the open-source front end of the sigrok project, works with many inexpensive analyzers and has protocol decoders for the same buses. Either is enough for these examples.

Common mistakes

  • No common ground between the analyzer and the board.
  • Sampling too slowly, so edges land in the wrong place and bytes decode wrong.
  • Reading the 8-bit address byte (0xD0) as a 7-bit address.
  • SPI decoder in the wrong mode, so every byte is shifted by a bit.
  • Watching the wrong chip select on a bus with several devices.

Quick check

1. A sensor's 7-bit address is 0x68. What byte does the analyzer show for a write?

0xD0: the address shifted left one bit, with R/W = 0.

2. What sample rate is the minimum for SPI at 8 MHz by the four-times rule?

32 MS/s.

3. Every MISO byte decodes as 0xFF. What is the likely cause?

Nothing drives MISO, so the line idles high: chip select, power or wiring.

Summary

  • Ground first, one channel per bus wire.
  • Sample at least four times the clock; ten or more is comfortable.
  • Trigger on START for I2C, chip select for SPI.
  • Match the decoder to the bus: address format for I2C, mode and bit order for SPI.

Related

Sources

Last verified

Checked against the Saleae, sigrok and NXP documents on 28 November 2026. Bus timing figures are bit counts at the stated clock rates.