Notes / Test & Debug Instruments
Logic analyzer: seeing the communication as it is
It records several digital signals at once and decodes UART, SPI and I2C into bytes. The first tool for debugging communication.
An oscilloscope looks at the shape of the voltage; a logic analyzer records the flow of 0s and 1s for a long time. It captures 8 to 16 channels at once for seconds or minutes, so you see the whole exchange.
Protocol decoding
Connect channels to SCL and SDA, turn on the I2C decoder, and it reads out as "write to address 0x68 ACK, 0x3B, repeated start, read 6 bytes". It tells you at once whether the problem is on the board side or the code side.
Settings
| Item | Guideline |
|---|---|
| Sampling rate | At least 4 times the fastest frequency in the signal (10 times if possible) |
| Logic threshold | About 1.5 V for a 3.3 V circuit |
| Trigger | For example, when CS falls LOW |
Tips
- Toggle a debug GPIO in the firmware and record it alongside, and you can see on the time axis how the moment of interrupt entry relates to the communication. It is also good for measuring the execution time of a control loop.
- A low-cost USB analyzer (Saleae compatible) with the open-source PulseView/sigrok handles most debugging.
- When a signal fails because of marginal levels or ringing, a logic analyzer does not show it. Then look at the analog shape with an oscilloscope.