Hardware Debugging with a Logic Analyzer: Stop Guessing, Start Seeing

When a sensor does not respond correctly, the instinctive approach is to add more print statements and change one thing at a time. A logic analyser replaces that process with direct observation: you see exactly what signals are present on the wire, when they transition, and what data they encode. Guessing becomes optional.

What a Logic Analyser Does

A logic analyser samples each input as 0 or 1 at high rate — 24MHz for the common USB models — and records the sequence of transitions. Protocol decoders interpret those transitions as I2C frames, SPI bytes, UART characters, or any other digital protocol. The result is a layered view: raw timing waveform on the bottom, decoded protocol data above it. A missing ACK, a wrong address byte, or a baud rate mismatch is immediately visible.

Debugging I2C

I2C is a two-wire protocol used by the majority of MEMS sensors, display controllers, and I/O expanders. Connect channel 0 to SDA and channel 1 to SCL. In PulseView, apply the I2C protocol decoder. Capture a transaction. The decoder shows the address byte, read/write bit, ACK or NACK, and every data byte exchanged. If your device address is 0x76 but the decode shows 0x77, you found your bug in 30 seconds instead of an hour of guessing.

Debugging SPI

SPI uses four lines: SCLK (clock), MOSI (master-out), MISO (master-in), and CS (chip select). Assign channels 0 through 3 to these four signals and apply the SPI decoder. Common problems are inverted CPOL/CPHA mode setting, where the clock idles at the wrong level, and CS polarity errors. The decoded transaction immediately shows which bytes the master sent and what the slave returned.

Debugging UART

Connect one channel to the TX line. In the decoder, specify the baud rate, data bits (usually 8), parity (usually none), and stop bits (usually 1). Garbled output that looks like noise becomes immediately readable ASCII or hex data in the decoded view. Baud rate mismatch is almost always the cause of garbled UART output, and the logic analyser shows the actual symbol duration, making the correct baud rate arithmetically obvious.

Setup

  1. Install sigrok from sigrok.org. Available for Windows, Mac, and Linux.
  2. Plug in your USB logic analyser. Linux and Mac usually enumerate without additional drivers.
  3. Launch PulseView. Select your device from the dropdown.
  4. Assign channel names. Set sample rate: 4MHz for I2C and SPI, 1MHz for UART.
  5. Click Run. Trigger on a falling edge of CS or the I2C Start condition.
  6. Right-click any channel, select Add Protocol Decoder, choose your protocol.

At approximately $35 CAD, a USB logic analyser with 8 channels at 24MHz is one of the highest return-on-investment purchases in a hardware development toolkit. The difference between debugging by print statement and debugging by direct observation is measured in hours per session.