{"id":135,"date":"2017-06-19T21:45:26","date_gmt":"2017-06-19T19:45:26","guid":{"rendered":"http:\/\/blog.ilialex.gr\/?p=135"},"modified":"2017-06-21T09:29:23","modified_gmt":"2017-06-21T07:29:23","slug":"decoding-serial-busses-from-digital-oscilloscope","status":"publish","type":"post","link":"http:\/\/blog.ilialex.gr\/?p=135","title":{"rendered":"Decoding Serial Busses from Digital Oscilloscope"},"content":{"rendered":"<p><b><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">Introduction<\/span><\/span><\/b><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">\u00a0<\/span><\/span><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">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.<\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">\u00a0<\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">In today\u2019s 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.<\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">\u00a0<\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">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\u2019s NIVISA, or the Tektronix TekVISA (see below for links). <\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">\u00a0<\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">For those unfamiliar with SCPI\u00a0(<a href=\"https:\/\/en.wikipedia.org\/wiki\/Standard_Commands_for_Programmable_Instruments\"><u><span style=\"color: #0066cc;\">Standard Commands for Programmable Instruments<\/span><\/u><\/a>), 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.<\/span><span style=\"color: #000000; font-family: Times New Roman;\">\u00a0\u00a0 <\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">\u00a0<\/span><\/span><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">Examples of SCPI commands:<\/span><\/span><\/p>\n<pre><code>*IDN?\r\nACQUIRE:STATE STOP\r\n<\/code><\/pre>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">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. <\/span><\/span><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">For this reason I wrote a python script to capture signals from the oscilloscope and decode them.<\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">In summary to access the SCPI port of a connected instrument you need the following:<\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">1. Python Interpreter (code is written in 2.7 generation) (<\/span><a href=\"https:\/\/www.python.org\/downloads\/\"><u><span style=\"color: #0000ff; font-family: Times New Roman;\">https:\/\/www.python.org\/downloads\/<\/span><\/u><\/a><span style=\"color: #000000; font-family: Times New Roman;\"> ) <\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">2. TekVISA\/NIVISA (or any other corresponding VISA library) package (<\/span><a href=\"https:\/\/www.ni.com\/visa\/\"><u><span style=\"color: #0000ff; font-family: Times New Roman;\">https:\/\/www.ni.com\/visa\/<\/span><\/u><\/a><span style=\"color: #000000; font-family: Times New Roman;\"> , <\/span><a href=\"http:\/\/uk.tek.com\/oscilloscope\/tds7054-software\"><u><span style=\"color: #0000ff; font-family: Times New Roman;\">http:\/\/uk.tek.com\/oscilloscope\/tds7054-software<\/span><\/u><\/a><span style=\"color: #000000; font-family: Times New Roman;\"> )<\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">3. PyVISA module (<\/span><a href=\"https:\/\/pyvisa.readthedocs.io\/en\/stable\/\"><u><span style=\"color: #0000ff; font-family: Times New Roman;\">https:\/\/pyvisa.readthedocs.io\/en\/stable\/<\/span><\/u><\/a> <span style=\"color: #000000; font-family: Times New Roman;\">\u00a0<\/span><span style=\"color: #000000; font-family: Times New Roman;\">)<\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">4. The Capture\/decode python <a href=\"https:\/\/bitbucket.org\/ialexo\/tds3012\/overview\">script<\/a>.<\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">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).<\/span><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">How it works<\/span><\/span><\/b><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">\u00a0<\/span><\/span><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">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. <\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">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?<\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">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.<\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">\u00a0<\/span><\/span><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">After the signals are captured, the script performs a thresholding according to the set logic standard like TTL, CMOS, LVCMOS etc. <\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">\u00a0<\/span><\/span><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">Then it decodes the signal according to the requested protocol and displays the decoded output on screen.<\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">To keep the script simple, we setup the oscilloscope manually to capture the signals fully (with the required time-span, sampling etc) and we leave it running. Triggering should be to Normal mode (not Auto). When we need to capture the waveform we can either run the script which stops acquisitions or we can stop manually and still use the script to acquire and decode the signals.<\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">\u00a0<\/span><\/span><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">Let\u2019s see some examples.<\/span><\/span><\/p>\n<p><strong>RS-232 Decoding<\/strong><\/p>\n<p>Running the command:<\/p>\n<pre><code>\r\nDSOCapture.py -b RS232 -l TTL -a 115200 -i CaptureRS422_LVCMOS.csv -n 0\r\n<\/code><\/pre>\n<p>We decode a file with data already acquired to a file.<\/p>\n<p>We need to define the baud rate, the voltage level and polarity (positive or reversed).<\/p>\n<figure id=\"attachment_142\" aria-describedby=\"caption-attachment-142\" style=\"width: 559px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/RS232_DOS_Capture.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-142\" src=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/RS232_DOS_Capture-300x158.jpg\" alt=\"RS232 Capture\" width=\"559\" height=\"295\" srcset=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/RS232_DOS_Capture-300x158.jpg 300w, http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/RS232_DOS_Capture-768x404.jpg 768w, http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/RS232_DOS_Capture.jpg 975w\" sizes=\"auto, (max-width: 559px) 100vw, 559px\" \/><\/a><figcaption id=\"caption-attachment-142\" class=\"wp-caption-text\">RS232 Command Prompt Capture Example<\/figcaption><\/figure>\n<p>The decoder displays the resulted characters along with the Start-Stop and Parity bits. In addition a VCD file is exported that we can view with GTKWave.<span lang=\"EN-US\">\u00a0<\/span><\/p>\n<figure id=\"attachment_143\" aria-describedby=\"caption-attachment-143\" style=\"width: 507px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/RS232_Wave.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-143\" src=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/RS232_Wave-300x42.jpg\" alt=\"rs232_wave\" width=\"507\" height=\"71\" srcset=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/RS232_Wave-300x42.jpg 300w, http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/RS232_Wave-768x107.jpg 768w, http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/RS232_Wave-1024x143.jpg 1024w, http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/RS232_Wave.jpg 1584w\" sizes=\"auto, (max-width: 507px) 100vw, 507px\" \/><\/a><figcaption id=\"caption-attachment-143\" class=\"wp-caption-text\">RS232 Waveform Capture Example<\/figcaption><\/figure>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">\u00a0<\/span><\/span><\/p>\n<p><strong><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">TWI Decoding<\/span><\/span><\/strong><\/p>\n<p>In TWI mode the parameters are more simple as TWI is clocked so we do not need to define sampling period for each character.<\/p>\n<pre><code>\r\nDSOCapture.py -v -b I2C -i CaptureI2C.csv\r\n<\/code><\/pre>\n<figure id=\"attachment_136\" aria-describedby=\"caption-attachment-136\" style=\"width: 531px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/TWI_DOS_Capture.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-136\" src=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/TWI_DOS_Capture-300x148.jpg\" alt=\"twi_dos_capture\" width=\"531\" height=\"262\" srcset=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/TWI_DOS_Capture-300x148.jpg 300w, http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/TWI_DOS_Capture.jpg 633w\" sizes=\"auto, (max-width: 531px) 100vw, 531px\" \/><\/a><figcaption id=\"caption-attachment-136\" class=\"wp-caption-text\">TWI Command Prompt Capture Example<\/figcaption><\/figure>\n<p>Again the results are shown in the Command Prompt, showing Start-ACK-Stop conditions.<br \/>\nIn addition the VCD file provides a graphical view.<\/p>\n<figure id=\"attachment_137\" aria-describedby=\"caption-attachment-137\" style=\"width: 528px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/TWI_Wave01.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-137\" src=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/TWI_Wave01-300x58.jpg\" alt=\"twi_wave01\" width=\"528\" height=\"102\" srcset=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/TWI_Wave01-300x58.jpg 300w, http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/TWI_Wave01-768x148.jpg 768w, http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/TWI_Wave01-1024x197.jpg 1024w, http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/TWI_Wave01.jpg 1287w\" sizes=\"auto, (max-width: 528px) 100vw, 528px\" \/><\/a><figcaption id=\"caption-attachment-137\" class=\"wp-caption-text\">TWI Waveform Capture Example<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_138\" aria-describedby=\"caption-attachment-138\" style=\"width: 518px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/TWI_Wave02.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-138\" src=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/TWI_Wave02-300x51.jpg\" alt=\"twi_wave02\" width=\"518\" height=\"88\" srcset=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/TWI_Wave02-300x51.jpg 300w, http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/TWI_Wave02-768x132.jpg 768w, http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/TWI_Wave02-1024x176.jpg 1024w, http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/TWI_Wave02.jpg 1399w\" sizes=\"auto, (max-width: 518px) 100vw, 518px\" \/><\/a><figcaption id=\"caption-attachment-138\" class=\"wp-caption-text\">TWI Waveform Capture Example Detail<\/figcaption><\/figure>\n<p><span lang=\"EN-US\">\u00a0<\/span><\/p>\n<p><strong><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">SPI Decoding<\/span><\/span><\/strong><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">\u00a0<\/span><\/span><br \/>\nIn this example we acquire the signal from the instrument (which is the more common way to do it). Every acquisition will store the .csv file with the data, if you need it. However you will need to copy it since the next acquisition will overwrite it.<\/p>\n<pre><code>DSOCapture.py -v -b SPI -t 3 -visa -i TCPIP::192.168.2.226::INSTR -f\u00a0capture.csv\r\n<\/code><\/pre>\n<figure id=\"attachment_140\" aria-describedby=\"caption-attachment-140\" style=\"width: 513px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/SPI_DOS_Capture.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-140\" src=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/SPI_DOS_Capture-300x155.jpg\" alt=\"spi_dos_capture\" width=\"513\" height=\"265\" srcset=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/SPI_DOS_Capture-300x155.jpg 300w, http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/SPI_DOS_Capture-768x396.jpg 768w, http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/SPI_DOS_Capture.jpg 987w\" sizes=\"auto, (max-width: 513px) 100vw, 513px\" \/><\/a><figcaption id=\"caption-attachment-140\" class=\"wp-caption-text\">SPI Command Prompt Capture Example<\/figcaption><\/figure>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">\u00a0<\/span><\/span><\/p>\n<figure id=\"attachment_141\" aria-describedby=\"caption-attachment-141\" style=\"width: 499px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/SPI_SD_Wave.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-141\" src=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/SPI_SD_Wave-300x143.jpg\" alt=\"spi_sd_wave\" width=\"499\" height=\"238\" srcset=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/SPI_SD_Wave-300x143.jpg 300w, http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/SPI_SD_Wave-768x367.jpg 768w, http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/SPI_SD_Wave-1024x489.jpg 1024w, http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/SPI_SD_Wave.jpg 1315w\" sizes=\"auto, (max-width: 499px) 100vw, 499px\" \/><\/a><figcaption id=\"caption-attachment-141\" class=\"wp-caption-text\">SPI Waveform Capture Example<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">\u00a0<\/span><\/span><b><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">\u00a0<\/span><\/span><\/b><\/p>\n<p><b><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">Development Methodology<\/span><\/span><\/b><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">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.<\/span><\/span><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">\u00a0<\/span><\/span><\/p>\n<figure id=\"attachment_145\" aria-describedby=\"caption-attachment-145\" style=\"width: 589px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/pytddmon.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-145\" src=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/pytddmon-300x184.jpg\" alt=\"PyTDDmon Example\" width=\"589\" height=\"361\" srcset=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/pytddmon-300x184.jpg 300w, http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/pytddmon-768x472.jpg 768w, http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/pytddmon.jpg 815w\" sizes=\"auto, (max-width: 589px) 100vw, 589px\" \/><\/a><figcaption id=\"caption-attachment-145\" class=\"wp-caption-text\">PyTDDmon View<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_146\" aria-describedby=\"caption-attachment-146\" style=\"width: 548px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/pytddmon02.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-146\" src=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/pytddmon02-300x285.jpg\" alt=\"Python Test Code\" width=\"548\" height=\"521\" srcset=\"http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/pytddmon02-300x285.jpg 300w, http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/pytddmon02-768x729.jpg 768w, http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/pytddmon02-1024x972.jpg 1024w, http:\/\/blog.ilialex.gr\/wp-content\/uploads\/2017\/03\/pytddmon02.jpg 1044w\" sizes=\"auto, (max-width: 548px) 100vw, 548px\" \/><\/a><figcaption id=\"caption-attachment-146\" class=\"wp-caption-text\">Python Test Code<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">You may download pytddmon from <a href=\"http:\/\/pytddmon.org\/\">here<\/a>. Alternatively you may use:<\/span><\/span><\/p>\n<pre><code>pip install pytddmon<\/code><\/pre>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">\u00a0<\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">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). <\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">\u00a0<\/span><\/span><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">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.<\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">\u00a0<\/span><\/span><\/p>\n<p><strong>Limitations<\/strong><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">The script does work well but there are limitations mainly due to the hardware (Digital Oscilloscope) which is worth to mention.<\/span><\/span><\/p>\n<p><em><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">RS232<\/span><\/span><\/em><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">The problem with RS-232 is that it is an asynchronous transmission. To better state the problem, there is no clock transmitted or derived from the data. It is assumed that the receiver has a similar clock within a certain range to capture and decode the transmission.<\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">If you need to capture a long stream of bytes and the scope does not have big memory you will find yourself limited on what can be captured. As the scope&#8217;s memory is not sufficient to hold a longer time period with much detail the decoded data may be scrambled (usually after a few bytes). To overcome this you may need to decrease the time span of the data or use an instrument with sufficient memory capacity to hold accurately the signal transitions.<\/span><\/span><\/p>\n<p><em><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">TWI<\/span><\/span><\/em><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">This kind of bus uses edge signalling to determine certain protocol states (like Start\/Stop conditions). If the sampling of the scope is not sufficient you may get bad decoding of the signals. Although not so severe as RS-232 protocol, this will happen only if you stress the instrument.<\/span><\/span><\/p>\n<p><em><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">SPI<\/span><\/span><\/em><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">SPI bus is a clocked transmission so sampling is not much an issue as in the other protocols. However because you usually need\u00a0three lines (SCK, MISO, MOSI), you need extra effort to read all lines with a two channel scope. As this script was built around TDS3012B, it captures only two channels. If you have an instrument with more channels available I would recommend to modify the script and capture the extra channels. <\/span><\/span><\/p>\n<p><strong><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">\u00a0Summary<\/span><\/span><\/strong><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">Improvements to the script can be performed, but as I am busy doing other things, I currently do not plan to do any additions. In any case any ideas are welcome and at some point may integrate them.<\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">I created this script some time ago, initially for TWI, then I added RS232 and finally the easiest part SPI.\u00a0I completed the whole script in about a two week time (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.\u00a0<\/span><\/span><\/p>\n<p><span lang=\"EN-US\"><span style=\"color: #000000; font-family: Times New Roman;\">\u00a0You may find a compiled Python executable <a href=\"http:\/\/ilialex.gr\/index.php?topic=Projects&amp;subtopic=DSOCapture&amp;lang=en\"><u><span style=\"color: #0066cc;\">here<\/span><\/u><\/a><\/span><\/span><\/p>\n<p>You may find the source tree in <a href=\"https:\/\/bitbucket.org\/ialexo\/tds3012\/overview\"><u><span style=\"color: #0066cc; font-family: Times New Roman;\">BitBucket<\/span><\/u><\/a>.<\/p>\n<p>&nbsp;<\/p>\n<div id=\"CodeProject\" style=\"display: none;\"><a href=\"https:\/\/www.codeproject.com\" rel=\"tag\">CodeProject<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Introduction \u00a0Using 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. \u00a0 In today\u2019s world of microcontrollers and IoT, it is not uncommon to debug &hellip; <a href=\"http:\/\/blog.ilialex.gr\/?p=135\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Decoding Serial Busses from Digital Oscilloscope<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[17,13,16,15,18,12,14],"class_list":["post-135","post","type-post","status-publish","format-standard","hentry","category-methods","tag-decode","tag-python","tag-rs232","tag-spi","tag-tds3012","tag-tektronix","tag-twi"],"_links":{"self":[{"href":"http:\/\/blog.ilialex.gr\/index.php?rest_route=\/wp\/v2\/posts\/135","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.ilialex.gr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.ilialex.gr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.ilialex.gr\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.ilialex.gr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=135"}],"version-history":[{"count":20,"href":"http:\/\/blog.ilialex.gr\/index.php?rest_route=\/wp\/v2\/posts\/135\/revisions"}],"predecessor-version":[{"id":194,"href":"http:\/\/blog.ilialex.gr\/index.php?rest_route=\/wp\/v2\/posts\/135\/revisions\/194"}],"wp:attachment":[{"href":"http:\/\/blog.ilialex.gr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.ilialex.gr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=135"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.ilialex.gr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}