RS-232 PROTOCOL

# RS-232 Protocol

Article by:

## 1. Overview

RS-232 is a digital data transmission protocol with origins dating back to the 1960’s. It was designed as a communication protocol to talk between DTE (data terminal equipment) and DCE (data communication equipment). It is closely related to the UART communication protocol provided by most microcontrollers, except that RS-232 uses higher-voltage signalling whilst UART is restricted between VCC of the microcontroller and GND.

 Drive Type Single-ended Num. Wires (excl. GND) 2 (TX/RX) or 4 (TX/RX and RTS/CTS) Duplexity Full Connection Topology Point-to-point OSI Layers Layers 1 (physical) and 2 (data link)

RS-232 is commonly used today for a variety of different purposes in embedded systems, incl industrial equipment, test and measurement equipment. RS-232 ports are no longer available on most desktop computers (and certainly not on laptops), but USB-to-RS232 adapters are cheap, popular and easy to use with almost any operating system.

## 2. Pinout

Figure 1. The pinout of a male RS-232 DE-9 connector. Image from http://www.ethernut.de/.

## 3. Revisions

• RS-232C (or just shortened to RS-232)

• EIA-232-D (1987)

• EIA/TIA-232-E (1991)

## 4. Flow Control

The flow control is a way of detecting when the receiver or transmitter is ready to accept or send new data. The UART protocol provides a few (all optional) methods for flow control:

• Hardware RTS/CTS lines

• Software XON/XOFF flow control

### 4.1. RTS/CTS

This is done by various additional connections to the standard transmit, receive and ground wires. The two most common are CTS and RTS. Typically, a micro-controller may have one or two UART peripherals that support this feature, while the rest are just basic non-flow control UART’s.

A small amount of power can be extracted from the RTS and CTS lines for powering low-power devices.

The following tables lists all of the flow control signals (as well as the data signals), with respect to the device in question. Matching signals are grouped together.

Signal Port Type Description DB-25 Pin DE-9 Pin

Output

DTE drives this to indicate to the DCE that it is present.

5

4

DCD (Data Carrier Detect)

Input

DCE drives this when it is connected to the telephone line.

8

1

RI (Ring Indicator)

Input

The DCE drives this when it has detected a phone call. Note that there is no matching signal going the other way.

22

9

RTS (Request To Send)

Output

DTE drives this to tell the DCE to get ready to receive data.

4

7

CTS (Clear To Send)

Input

Driven by the DCE when it is ready to accept data.

5

8

TxD (Data Transmit)

Output

The DTE sends data to the DCE over this line.

2

3

Input

The DCE sends data to the DTE over this line.

3

2

Common Ground (GND)

n/a

The common ground for all signals.

7

5

Protective Ground (PG)

n/a

The protective ground. This is usually just connected up to the common ground on the PCB.

1

n/a

 There is confusion of how to connect two RS-232 (or UART!) devices together arises when it is not terminal equipment (DTE) connected to modem equipment (DCE). In the embedded world, microcontrollers and other devices which support RS-232/UART can act either as a DTE or a DCE. Take particular care when connecting RS-232/UART ports together on embedded devices!

Rule-of-thumb: Most RS-232 serial interfaces with a male 9 or 25 pin connector are DTE’s, most with a female 9 or 25 pin connector are DCE’s.

Most often, manufacturers label the UART pins as DTE’s. In this case, you have to swap all connections with their matching line. So TxD of device 1 is connected to RxD of device 2, RxD of device 1 is connected to TxD of device 2, RTS of device 1 is connected to CTS of device 2, e.tc.

15m or less

## 6. Higher-Level Protocols

Do you need a higher-level communication protocol that works over a UART connection? See the SerialFiller library on GitHub (written in C++). SerialFiller uses a publish/subscribe mechanism and works well on point-to-point serial connections such as UART.

## 7. Interfaces

The pinout of a typical Analog Devices RS-232 to UART transceiver is shown below.

Figure 2. Pinout of a RS-232 transceiver by Analog Devices.

Another example of a RS-232 to CMOS UART converter is the MAX3221IDBE4. It supports an auto-shutdown feature based on the voltage-level of the receiving RS-232 line.

## 8. Driver ICs

### 8.1. MAX3227

The Maxim MAX3227 is a popular RS-232 line transceiver. It contains 1 driver and 1 receiver as is designed to be driven from CMOS signals (e.g. connected to a microcontroller UART)[2]. Texas Instruments produces a drop-in replacement part for the MAX3227, the MAX3227CDBR (the CDBR standing for commercial temp. range, tape and reeled)[1].

## 9. Cheap Discrete-Part RS-232 To TTL Converter

A RS-232 to TTL logic-level converter can be made out of a few discrete components. The schematic shown below uses some clever circuitry, including a charge-pump like circuit, to generate the negative voltage required for RS-232 transmission back to the computer.

Figure 3. The schematic of a cheap, discrete-part RS-232 to TTL logic-level converter. Image from Atmel AVR910 (http://www.atmel.com/).

## Authors

### Geoffrey Hunter

Dude making stuff.