Ramblings of an aging IT geek
← Ramblings of an aging IT geek
hardware

a cheap logic analyser, and finally seeing the bus

Using a sub-£10 logic analyser with sigrok to decode an I2C sensor that would not talk, and what the captured frames revealed.

A soldering iron and a part-finished board

I had a BME280 sensor that would not answer on I2C, and I had spent an embarrassing amount of an evening poking at it with print statements. The Arduino sketch scanned the bus, found nothing, and that was that. No device, no clue why. So I did the thing I should have done an hour earlier and bought a logic analyser.

Not a real one. One of those little blue eight-channel clones off the usual sites, the ones that pretend to be a Saleae and cost about a fiver. It enumerates as a Cypress FX2 and sigrok talks to it happily. That is the bit that matters: the hardware is throwaway, but PulseView and sigrok are properly good software, and they decode protocols for you.

clipping onto the bus

The wiring is trivial. Ground to ground, then two channels onto SDA and SCL, the same two pins the microcontroller is shouting at.

Probe wires clipped onto a small circuit board

In PulseView I set the sample rate to 1 MHz, which is plenty for a 100 kHz bus, added the I2C decoder, told it which channel was which, and hit run. Then I triggered the scan from the Arduino and watched.

And there it was. The master sent the start condition, clocked out the address, and got nothing back. No ACK. The line just sat high where the device should have pulled it low. That single missing low pulse told me more than an evening of Serial.println ever did.

the actual fault

The address being driven was 0x76. The sensor on my board, it turns out, has its SDO pin tied high, which puts it at 0x77. My scanner code was hard-coded to the wrong one. A one-bit difference, and the device was politely ignoring me the entire time because I was knocking on the wrong door.

What I love about this is that the analyser does not lie to you and it does not have a bug in its firmware. The microcontroller's view of the world is a story it tells you. The captured waveform is just what happened on the wire. When the two disagree, the wire wins, and you go and fix the story.

The capture itself is the keeper, though. Here is roughly what the decoded line read:

Start | Address write 0x76 | (no ACK) | Stop

One missing acknowledge bit. That is the whole bug, sat there in black and white.

For under ten quid this thing has already paid for itself, and it has changed how I debug anything with two or more wires between it and a sensor. I should have bought one years ago. If you do anything with I2C or SPI and you have been guessing, stop guessing. Clip on and look.