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

A Cheap Logic Analyser and Finally Seeing the Bus

A twenty-pound logic analyser turned a guessing game over a dead I2C sensor into ten minutes of actually watching the bytes go past.

A soldering iron and electronics on a bench

I'd been fighting an I2C sensor for the better part of an evening. It wasn't responding, the code looked right, the wiring looked right, and I was at the stage of debugging where you start suspecting cosmic rays. The problem with a bus like I2C is that it's completely invisible. Two wires, a fast handshake, and either it works or it sullenly doesn't, and you've no way to see which side is at fault.

So I finally bought a logic analyser. Not a fancy one, one of the little eight-channel clones that costs about twenty quid and shows up as a generic clone of a much pricier device. I clipped two channels onto SDA and SCL, told the software they were an I2C bus, and ran a capture.

Ten minutes later I had my answer, and it was humbling. The bus was alive, the clock was ticking, my code was dutifully sending out the address I'd configured. The sensor just wasn't at that address. I'd transposed two bits in the hex and been politely shouting into the void all evening. The decoder showed the address byte going out and nothing acknowledging it, which is the bus equivalent of knocking on the wrong door.

What got me wasn't fixing the bug, it was how much guessing the tool removed. For years I'd debugged this stuff by reasoning about what should be on the wire. Now I could just look. The difference between inferring and seeing is the whole game, and I'd been playing it half-blind. Twenty pounds is an absurd price for that. Buy the cheap analyser. It pays for itself the first evening it saves.