Using a $10 Logic Analyzer for Debugging Serial Interfaces
2018-02-17 19:11:49 by Tim
Why You Need a Logic Analyzer
At some point when working with serial interfaces such as SPI and I2C you are going to run into issues and need to do some debugging. A logic analyzer is the tool you want to use to be able to decode the serial data and see what’s really going on.From Wikipedia:
EETimes has a good article on the differences between a logic analyzer and an oscilloscope:
Low Cost < $10 Logic Analyzer Hardware
High-end logic analyzers from test equipment makers can be very expensive with features and accuracy levels not needed to do simple microcontroller serial interface debugging. Over the past few years there has been a lot of advancements on the hardware front with making cheaper logic analyzers using cheap FPGA based designs mostly based on the Cypress CY7C68013A (a.k.a. FX2) chip. There are a lot of FX2 based logic analyzers that can be purchase for less than $10.
One option is an open-source design called fx2grok-tiny by the logic analyzer Sigrok software developers (also open source by the way)
You can purchase a version of this type of design online from Hobby Components for less than 10 pounds. You can also look at a huge list of logic analyzers available at various prices and features.
Open-Source Logic Analyzer Software – Sigrok
The logic analyzer hardware is only part of the equation here – you also need the software to read the signals and decode them for you.
Right now the best logic analyzer software out there in my opinion is Sigrok which is open-source and has actually expanded support to more than logic analzyers so it can work with lots of different test equipment. You can run Sigrok on Linux, Windows, and Mac so you’re pretty much covered.
Sigrok comes with a GUI front-end called PulseView that contains the logic analyzer interface:
You can go to Sigrok website and get the download installers for Windows here (you need to install both PulseView GUI and the sigrok-cli which is command line interface to sigrok application) Follow the instructions to get all of the drivers and software installed for your specific logic analyzer.
Tips on Getting Sigrok to Work with Generic FX2 Based Logic Analyzer:
- I purchased a generic FX2 based logic analyzer so we will use the fx2law firmware in Sigrok to talk to it
- Make sure to install the WinUSB driver using the Zadig tool
- You should see the open source driver fx2lafw show up in Device Manger
- The device might be recognized as a Saleae device as that seems to be generic driver/firmware associated with these generic FX2 logic analyzers
Debugging Arduino Serial Port with Logic Analyzer Sigrok Software
For a quick test I used the built-in Arduino UNO blink led code and modified it to turn pin 4 on and off at 1000ms intervals:
Then I went into Pulse and set the sample rate and measured the cursor:
For this example I turned on the Guess bitrate encoder and overlaid it just so you can see what the interface decoders look like.
So now we have a cheap logic analyzer that can be used to debug serial interfaces!