Measuring and analyzing RS232 signals

Introduction

Many devices in the industrial environments are still using an RS-232 serial communication link. RS-232 uses two signal levels to distinguish between a logical "1" and a logical "0". A logical "1" is represented by -12 V and a logical "0" is represented by +12 V. RS-232 can operate on different bit rates, standard values lie between 110 bit/s and 115200 bit/s. To synchronize the sending and receiving devices, start and/or stop bits can be added to the data to transfer. RS-232 supports a simple validity check of the transmitted data, using a parity bit that can be added to the data. Two signal lines are available, TxD (Transmit Data) and RxD (Receive Data). These can be used simultaneously, which makes full-duplex communications possible.

Requirements

Measuring

To measure single RS-232 signals, a measuring instrument with at least one channel is required. To measure full-duplex signals, an instrument with at least two channels is required. The maximum frequency on the RS-232 bus depends on the bit rate that is used. The instrument must sample at at least three times the bit rate on the bus, but preferable ten times higher, on each channel. For a 110 bit/s bus that would mean a minimum sampling frequency of at least 1 kHz on both channels. RS-232 uses voltages between -12 and +12 V, so the instrument should be able to measure voltages between -12 and +12 V. Since data transfers can be long, a long record length is preferred to capture the communication.

The Handyscope HS3, Handyscope HS4, Handyscope HS4 DIFF, Handyscope HS5 and the Handyscope HS6 DIFF are suitable instruments to measure RS-232 signals.

Analyzing

To examine the transferred data in the measured signals, the various pulses have to be examined, the start and stop bits have to be taken out and the parity bit too, when used. The remaining bits have to be converted into readable data.

The TiePie engineering Multi Channel oscilloscope software is capable of analyzing RS232 signals, using the Serial analyzer.

Generating a test signal

In this example, a Handyscope HS4 is used to measure serial communication from a computer running a terminal program, in which text is typed.

Open your favorite terminal program (e.g. Hyperterminal) and set it up to communicate through a serial (COM) port using the following settings:

Setting Value
Bit rate 110
Data bits 8
Parity None
Stop bits 1
Data transport control None

Text typed in the terminal program should now be transmitted directly through the serial port.

Setting up the hardware

First the Handyscope HS4 is connected to the computer and the Multi Channel oscilloscope software is started.

Now connect Ch1 to the TxD line of the COM port of the computer. Connect the ground terminal of the input to CG (chassis ground) of the COM port.

COM ports use either a 9 pin or a 25 pin male D-sub connector.

Signal 9 pin 25 pin
TxD pin 3 pin 2
RxD pin 2 pin 3
CG pin 5 pin 1

Setting up the software

Setting up the input channels

Since only one channel is used to measure the RS-232 signal, Ch2, Ch3 and Ch4 of the Handyscope HS4 are removed from the screen.

We are using Ch1 to measure the Transmitted Data (TxD). To simplify recognition of the signal, it can be given a descriptive name (alias). To change the alias of a channel, right-click the channel in the object tree and select Set alias... and enter the required alias. Give Ch1 the alias "TxD".

RS-232 signals lie between -12 V and +12 V, idle state = -12 V. Therefore, set the channel input coupling of the channel to "DC" and set the input sensitivity of the channel to "20 V" full scale. That way both signal levels can be measured properly.

Setting up the time base

In our example, a 110 bit/s serial communication is used. Therefore, set the time base to a sampling frequency that is ten times higher, 1 kHz. Since we will be typing text in a terminal program, we need sufficient measuring time, e.g. 2 seconds. With a sampling frequency of 1 kHz, that requires 2000 samples record length.

Setting up the trigger

In idle state, the TxD line has a logic "1", which means that the voltage on the line = -12 V. When communication starts, first a start bit, a logic "0" (+12 V) is transmitted. That means that the start of a communication sequence is a rising edge. Therefore, set the trigger type to rising edge. The trigger level and trigger hysteresis are not really important, as long as they are within the -12 to +12 V range. Set the trigger level to e.g. 50% and the hysteresis to e.g. 2.5%. To make sure that the measurement is only started when the communication begins, the trigger timeout has to be set to infinite.

Serial communication

Setting up the Serial analyzer

To analyze the RS-232 signals, the serial analyzer sink is used. Create one by right-clicking Sinks in the object tree and selecting Serial analyzer. This also opens an additional window, which will display the analyzed RS-232 communication.

The serial analyzer can handle up to eight serial communication signals, but in our example, only one signal will be analyzed. Connect Ch1, TxD, to the serial analyzer by dragging it on the serial analyzer sink in the object tree.

Serial analyzer created

Port settings

Click on the Settings tab to setup the port settings for the analyzer.

Serial analyzer settings window

The serial analyzer can analyze serial signals from multiple sources. Sources that are connected will initially get default values. These default values can be changed by selecting Default in the Source selector. Settings for sources that are already connected can be selected as well. Our example uses TxD as source, so select that.

Bit rate
The serial analyzer can determine the bit rate of the measured signal automatically. However, it requires at least 25 edges in the measured signal, meaning that the communication must be long enough, at least 4 to 5 characters of transmitted data. The Analyzer can also be set to a fixed bit rate. In that setting, the analyzer will immediately start analyzing the data, using the preset bit rate. In our example, a bit rate of 110 is used. Set the bit rate of the analyzer to 110.
Data bits
Serial communication can use various numbers of data bits per transmitted "word". In our example, a 8 data bits are used. Set the number of data bits of the analyzer to 8.
Parity
Serial communication can use different kinds of parity checks to verify the correctness of the transmitted data. In our example, no parity is used. Set the Parity of the analyzer to None.
Stop bits
Serial communication can use different numbers of stop bits to indicate the end of a transmitted "word". In our example, 1 stop bit is used. Set the number of stop bits of the analyzer to 1.
Type
With normal serial communication, a logical "0" is represented by a high voltage and a logical "1" by a low voltage. Sometimes this is inverted, a logical "1" is a high voltage and a logical "0" a low voltage. In our example, we use standard RS-232, so set Type to Normal.
Mid level
With normal serial communication, all levels above mid level are considered a logical "0" and all levels below mid level are considered a logical "1". The analyzer can detect a mid level based on the measured data or the user can set a voltage that will be used as mid level. Usually, Auto level will do, so set Mid level to Auto level.

Ready to measure

Now everything is properly setup, type a word in the terminal program to create a serial communication. The instrument will capture this communication and the serial analyzer will analyze and decode it.

Serial communication decoded

In our example, the word "tiepie" was typed and measured and converted by the serial analyzer. The settings that were used are displayed above the decoded part of the communication.

To clear the Serial Analyzer output window for a new measurement, press the Clear text button ClearBtn.

When a block of communication is longer than the Serial Analyzer output window, it is not possible to see all text that is appended. The window has an auto scroll function, which always makes sure the bottom lines are visible. To toggle this function, click the Auto scroll button ScrollBtn.

To save the contents of the output window to a file, press the Save button SaveBtn.

To avoid the output window being hidden behind other windows, press the Always on top button Always On Top.

Cleaning dirty signals

In industrial environments, the measured signals can be very "dirty", causing the Serial analyzer to have problems decoding the communication properly. Cleaning the signals may improve the ability of the Serial analyzer to decode the signals properly.