Maker.io main logo

Understanding the RS-232 Standard

2023-10-25 | By Maker.io Staff

In contrast to previously discussed communication protocol standards, such as Modbus, RS-232 is a hardware standard for asynchronous serial communication. It defines the electrical and mechanical characteristics of the interface used to exchange data between electronic equipment. This article investigates the most important aspects and explores some benefits and drawbacks of the straightforward serial port.

Understanding the RS-232 Standard

Electrical Characteristics of the RS-232 Standard

Contrary to what you might know from other communication protocols, such as I2C and SPI, RS-232 uses negative and positive voltage levels to encode bits in messages. Other protocols encode the digital zero using 0V and represent the logic high state using a positive voltage level, typically 3V or 5V. In contrast, RS-232 represents a logic 1 using a negative voltage between -15V and -3V. Conversely, the protocol encodes zeros using a positive voltage between +3V and +15V. Therefore, RS-232 traditionally employs negative voltages and uses an inverted representation of the transmitted bits. Traditionally, the range between -3V and +3V is not defined — however, many modern controllers interpret this range as a logic 1.

While this choice of voltages represents some challenges, especially in modern microcontroller-based projects, the vastly differing voltages used to represent the two binary states provide good immunity to noise even when transmitting signals over large distances. However, they also imply that projects must somehow generate negative voltages to adhere to the RS-232 standard, which may increase a build’s complexity.

Message Frames in RS-232

RS-232 defines that asynchronous serial communication is used to exchange data between devices, meaning that information is transmitted one bit at a time without a dedicated clock signal that synchronizes exchange between the communication partners. Instead, each message contains start and stop bits that separate individual frames, which are indivisible packets of bits. Other than that, RS-232 doesn’t precisely define the composition of message frames. Nevertheless, a common approach is to use a start bit, followed by the data bits, an optional parity bit for error checking, and one or more stop bits.

The sending device shifts bits over the TX line into the receiver’s RX input in each transmission. Data can only travel from the sender's TX output to the recipient's RX input, meaning the protocol requires two wires if bi-directional communication is needed.

Understanding the RS-232 Standard This image illustrates how the control signals between the DTE and DCE connect. Note that the TX pin is always exclusively for sending data, and the RX pin receives input.

Communication in RS-232 is simplex, meaning the devices can’t send and receive data simultaneously. Instead, both devices must take turns sending and receiving messages. However, many applications only utilize uni-directional transmissions, meaning that one device solely acts as the sender while the other strictly receives and processes input.

The TX signal’s idle state is low (e.g., -12V), indicating no message is being transmitted. To start a new transmission, the sender must pull the TX line to a high state, for example, +12V, to signal the receiver to expect a message. This so-called start bit is required as there’s no clock signal to synchronize the communication partners. After starting a transmission that way, the sender transmits seven data bits starting with the least significant bit (LSB) at a previously agreed baud rate. The eighth bit is the parity bit, representing an error-correcting measure.

The partners can use either even, odd, or no parity. When using even parity, this bit has to be set when the message contains an even number of set bits. Similarly, the odd parity bit must be set when the message comprises an odd number of high bits. Finally, a message frame ends with the stop bit. When sending the stop bit, the transmitter pulls the TX line high again to allow the receiver to detect the next start bit in a consecutive message frame.

Understanding RS-232 Control Signals

You may likely only utilize the TX, RX, and GND signals found in a DB-9 connector, a standard connector often present on devices that support RS-232 communication. In many cases, using these three signals suffices. However, the standard describes a few more control lines that were once widely used in computer-to-modem communication. Nevertheless, they may still be relevant today in certain situations.

Data Terminal Ready (DTR), Data Set Ready (DSR), Request to Send (RTS), and Clear to Send (CTS) are four control signals still relevant in more modern applications. Using the DTR signal, the sending device, such as a computer, can indicate to the receiver — a modem, for example — that the recipient should get ready to receive data. Conversely, the DSR informs the computer that the modem is ready. The RTS and CTS lines indicate to the computer and modem, respectively, that they should prepare to receive data frames.

Understanding the RS-232 Standard This image explains the pins on the male RS-232 connector as commonly found on the data terminal equipment.

As mentioned, these control signals stem from the origins of the standard as a protocol that standardizes the communication between computer terminals (data terminals) and data communication equipment, such as telephone modems. Therefore, many other signals are only of historical relevance — the Ring Indicator (RI) and Data Carrier Detect (DCD), for example, which can inform the computer of incoming calls on the phone line and whether a carrier signal is present.

Summary

The electrical characteristics of RS-232 might seem strange at first glance, as the protocol utilizes negative voltages and uses an inverted scheme to represent high and low states. For example, the protocol defines that the sender must pull its transmit line (TX) below -3V to encode a high state, which might seem counterintuitive. Conversely, voltages above +3V encode low bits in messages. However, this large chasm in voltage levels introduces some immunity to electrical noise, which results in transmissions working reliably even in noisy environments and over long distances without introducing sophisticated error correction mechanisms.

While RS-232 doesn’t precisely define how to encode messages, the protocol states that messages be transmitted asynchronously over two separate serial data lines. Usually, message frames begin with a single start bit, followed by seven data bits, a parity bit, and one or multiple stop bits that separate consecutive message frames.

The standard also defines some control lines typically left unused in DIY projects.

制造商零件编号 DFR0258
RS232 SHIELD FOR ARDUINO
DFRobot
¥80.58
Details
制造商零件编号 MIKROE-1582
BOARD COMM SERIAL RS232 CLICK
MikroElektronika
¥146.51
Details
制造商零件编号 103030028
RASPBERRY PI RS232 BOARD V1.0
Seeed Technology Co., Ltd
¥93.61
Details
制造商零件编号 PRT-00449
SPARKFUN RS232 SHIFTER - SMD
SparkFun Electronics
¥142.44
Details
制造商零件编号 K046
ATOM RS232 KIT
M5Stack Technology Co., Ltd.
¥137.97
Details
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum