Debugging With A Logic Analyzer

When an I2C bus misbehaves, the fastest route to the truth usually leads through a logic analyzer. Two channels are enough – one on SDA, one on SCL – and with I2C decoding enabled, the analyzer shows address frames, data bytes and ACK bits as plain numbers instead of a wall of edges.

Unlike an oscilloscope, a logic analyzer records only the digital states – but that is precisely what I2C is about: the protocol is defined by the sequence of levels on two lines. The analog details such as rise time, ringing and crosstalk remain the oscilloscope’s territory. Everything else, from a silent device to a bus pulled low by someone, can be answered with an inexpensive USB analyzer.

What you need

The ubiquitous inexpensive USB stick analyzers with eight channels and a 24 MHz sampling rate are fully sufficient for Standard Mode and Fast Mode. On the software side there are two common candidates: sigrok with its PulseView GUI (open source) and the commercial Saleae Logic. Both decode I2C out of the box.

  • Channel 0 to SDA, channel 1 to SCL – the assignment is free as long as the decoder knows it.
  • Connect the analyzer’s ground to the ground of the board; without a common ground, the recording is just noise.
  • If it is unclear which line is which: SCL pulses constantly during transfers, while SDA only ever changes while SCL is low.

Sampling rate, trigger and memory depth

Rule of thumb: sample with at least ten times the SCL frequency, preferably more. For Fast Mode (400 kHz) that means at least 4 MSa/s, and 16 MSa/s is a comfortable value that still shows edge details. Standard Mode would get by with 1 MSa/s, but there is rarely a reason to go that low.

Triggers save memory and nerves. Simple analyzers trigger on a level or an edge; better is a trigger on the START condition – a falling edge on SDA while SCL is high – or, where the tool supports it, directly on a specific address. Memory depth decides how many transfers fit into one capture. For long sequences such as a boot process or a sensor stream, it pays to reduce the sample rate to what is really needed.

Typical error patterns in the decoder

  • The address frame ends with NACK: no device answered. Either the device is missing, it has no supply, or the address is wrong – 7-bit versus 8-bit notation strikes here particularly often.
  • The bus stays LOW after a transfer, nothing decodes any more: a slave is stuck in the middle of a byte and keeps SDA pulled down. Causes and rescue: Blocked I2C Bus.
  • Gaps on SCL in the middle of a byte: the slave is clock stretching. Usually legitimate – but the maximum allowed stretch time of the device is worth a look.
  • Single glitches on SDA or SCL that the decoder flags as errors: picked-up crosstalk from neighbouring lines. Check the wiring, add ground return paths, soften the edges: Crosstalk.
  • SDA anomalies while two masters transmit: arbitration lost events. Normal in multi-master systems, but the firmware has to handle them: Master Reports Arbitration Lost.

A systematic approach

  • 1. Check the voltage levels: with the bus idle, SDA and SCL must sit at VDD through the pull-ups. If they do not, the problem lies before any protocol analysis.
  • 2. Enable I2C decoding and assign the channels correctly (SDA and SCL; the bit order is fixed for I2C).
  • 3. Look at the address frame: does the expected address appear, and is it acknowledged?
  • 4. Search for ACK gaps: NACKs mark the failed transfers – and show whether the address, a data byte or the read access is the problem.
  • 5. Measure the timing: rise times, clock stretching gaps and the clock frequency against the limits of the mode.

Two classic patterns are common enough to have their own pages on this site: No Acknowledge and 0xFF Data Bytes. Both look cryptic in the decoder window at first glance – and are explained there bit by bit.