Tuesday, 19 July 2016

oscilloscope - reverse engineering a serial protocol with a scope


In lieu of a serial capture device are we able to look at the output of an rs-232 feed and correlate what we see on the scope with ASCII/hex representations (do certain voltages tend to correspond with this character representation or that character representation? Line feeds and carriage returns come to mind) or are there too many variable to reverse engineer a serial protocol in this manner?



Answer




The difficulty in capturing and analyzing RS-232 signals on a scope is that the start pulse -- where the voltage first drops from a high logic level to a low one (if one is looking at UART levels), or rises from a negative voltage to a positive one (if one is looking at RS-232 levels) -- looks the same as any other bit, so it can be difficult to trigger on the first edge (whether trailing or leading) of the start pulse of the first character.


If you do trigger on one of the beginning edges of of the bits (whether the start bit or another one, if your sweep set so that you can capture more than one character, then you will be able to see any complete characters after the trigger -- the signal should break up into characters since the stop bit is longer than the others. Look at the start bit, and then from the middle of the start bit, the middle of the bits that follow it will be dependent on the baud rate. At 9600 baud, that is 104 µS, and at 115,200 baud it is 8.68 µS for example.


enter image description here


The data in the two bytes (0x3D and 0x68) could either be hex data with the values as shown, or ASCII characters, also given. Without other context it is impossible to tell.


The top diagram shows the RS-232 levels that you would see on a PC COM port (seldom seen anymore) or a USB to RS-232 cable. The spacing or idle condition (0) is a negative voltage between -5 and -12v, and a marking condition (1) is a positive voltage between +5 and +12.


This bottom diagram shows the logic levels that you would see on the TX and RX leads of a UART. Note that the bits are inverted -- a high logic level is a 0 (called spacing) and a low logic level is a 1 (called marking).


Here is a table to convert the bits to ASCII.


That said, many scopes now come with protocol analyzers for UART, I2C and SPI either standard or an optional module you can buy. Or you can buy a stand-along logic analyzer that display the waveform on using a PC as the the display.


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...