Skip to content
Ilias edited this page Nov 8, 2022 · 1 revision

Welcome to the tds3012b wiki!

Decoding Serial Busses from Digital Oscilloscope

github_serdecode

Introduction

Using a Digital Oscilloscope was a premium tool in the past; although professional equipment is still a high cost if considered for amateur use, the cost of equipment has fallen the last years allowing more people to get these instruments.

In today’s world of microcontrollers and IoT, it is not uncommon to debug serial low-speed buses, like RS232, SPI and TWI (I2C). Hobbyists and professionals need to decode manually each bit knowing the protocol. This is natural to do if you are at the first debugging stages where you need to check electrical integrity on a new design, but it gets tedious if you need to concentrate on the protocol. Purchasing a decoding module for these oscilloscopes increase the cost and many times is not an option for a one off project.

The good thing with such instruments is that they usually provide some connectivity with serial, ethernet or USB connection. Usually apart from any web based control you have the option to program the instrument through the SCPI interface. You may use any language you want if you want to access the instrument as long as you have installed the relevant VISA libraries/drivers (like National Instrument’s NIVISA, or the Tektronix TekVISA). ( Links )

For those unfamiliar with SCPI ( acronym ), it is a standard protocol to access instruments initially based on IEEE-488 connection. Later on as more instruments used serial or ethernet connection, the required GPIB card has became obsolete and made things easier and more straight forward. The instructions available are mostly universal, but each instrument can complement these with any extensions needed to support the features unique on it.

Examples of SCPI commands:

*IDN?

ACQUIRE:STATE STOP

I started programming many instruments that way in the past using C/C++ but after switching to python I forgot about any other language in the host machine. Scripting languages offer an easy go process especially for string manipulation etc.

For this reason I wrote a python script to capture signals from the oscilloscope and decode them.

In summary to access the SCPI port of a connected instrument you need the following:

  1. Python Interpreter (code is written in 2.7 generation) (https://www.python.org/downloads/ )
  2. TekVISA/NIVISA (or any other corresponding VISA library) package (https://www.ni.com/visa/ , http://uk.tek.com/oscilloscope/tds7054-software )
  3. PyVISA module (https://pyvisa.readthedocs.io/en/stable/ )
  4. The Capture/decode python script found here.

Now under Windows you may use the executable which is a compiled python script (with GUI2Exe). In this case you will need only the VISA installation and the tool itself (no need for python+pyvisa as these are included in the compiled program).

How it works

The tool captures the signals from the oscilloscopes in a CSV file. As I use an old TDS3012B DPO from Tektronix, I only have 2 available channels to capture. This is fine for capturing RS232 or TWI signals, but for SPI you may need to perform multiple runs to capture 2 data lines and CS along with the clock, with you ending up changing probes for each run, but this is better from nothing.

Oscilloscopes with more channels would of course capture more signals and avoid this hick-up. The script is made and tested on this particular oscilloscope, but it should work in most other instruments maybe with slight modifications. If you need to capture more channels then you still need to modify the script to save the extra channels on the CSV and in addition to add to the SPI decode module the extra traces to decode. But this is why we have open source right?

Keep in mind that the script decodes from the CSV file (and not directly from the instrument). Thus if you have old (or test) captures you may instruct it to use these instead of accessing an instrument. This helps for off-line decoding or testing the script.

After the signals are captured, the script performs a thresholding according to the set logic standard like TTL, CMOS, LVCMOS etc.

Then it decodes the signal according to the requested protocol and displays the decoded output on screen.

Let’s see some examples next.

RS232 Decoding

Command Line image

RS232 Plot image

TWI Decoding

Command Line image

TWI Plot image

image

SPI Decoding

Command Line image

SPI Plot image

Development Methodology

Now the interesting thing is that I used TDD (Test Driven Development) methods to create this script. To help me in this process I used the pytddmon.py script. So when developing you just need a command prompt or shell in the directory holding the script and run pytddmon.py (should be at the same directory). See picture below.

Picture pyTDDMon.py image

image

You may download pytddmon from ( Link )

Next thing is that I created the test cases for each module. Initially I used real data captured on my oscilloscope or used similar values to test the various cases. For example thresholding the incoming stream is more challenging than just compare and output a logic value. As you pass through the transition phase from 0-1 or 1-0 then some values may trigger multiple transitions on each edge. In this case you need to perform hysteresis ( link ) to avoid it (as the electronics do as well).

The after the signals have been interpreted to logic levels (or edges as well, as TWI uses the edges), then the thresholded outputs are passed to the corresponding serial bus analyzer.

RS232 State problem with sampling and accuracy

TWI State problem with edges

SPI State problem with less than 4 lines

I created this script some time ago, initially for TWI, then I added RS232 and finally the easiest part SPI. What I discovered was that using TDD methods, the script worked almost instantly when finished without any problems. I completed the whole script in about a week (with full functionality) and it was pretty easy. If I had to work without TDD, I would need to capture all the possible variations on my scope and debug a much larger codebase at the time.