Serial Interfaces: RS-232 Interface
Serial Interfaces: RS-232 Interface
Serial Interfaces
Serial interfaces are typically used to connect computer systems and low-speed external peripherals such as modems
and printers. Serial interfaces reduce the cost of interconnecting devices because the bits in a byte are time-multiplexed
onto a single conductor. Serial interfaces are covered in Chapter 9 of the text.
You should be able to describe the operation and format of data and handshaking signals on an RS-232 interface and
the data format on an HDLC synchronous data stream.
RS-232 Interface vices implement additional handshaking pins. Of
these, the most useful are called RTS (Request To
The most widely used peripheral interface is the Send) and CTS (Clear To Send). The CTS pin is a
“RS-232” serial interface. This interface is available DCE output and is used by the DCE to indicate that
on most general-purpose microcomputers. it can accept data on the TxD line. The RTS line is an
output on a DTE and is used to indicate that the DTE
DTE and DCE wants to send (RTS was originally used to control
half-duplex modems – these are rarely seen today).
The serial interface was originally designed to con- Since these signals are used to control the flow of
nect modems (Data Communications Equipment - data from the DTE (and optionally from the DCE)
DCE) to computer terminals (Data Terminal Equip- these pins are called [hardware] “flow control” sig-
ment - DTE). In its simplest form the interface has nals.
two signal lines, Transmit Data (TxD or TD) and DTE DCE
Receive Data (RxD or RD), and a ground reference. RTS RTS
The TxD signal is an output on a DTE device and an CTS CTS
input on a DCE device. Similarly, RxD is an output
DTR DTR
on a DCE device and input on a DTE device.
DTE DCE DSR DSR
("terminal") (modem)
TxD TxD
The second set of control signals are DTR (Data
RxD RxD Terminal Ready) and DSR (Data Set Ready). These
signals indicate that the DTE and DCE devices re-
("terminal") (modem)
spectively are connected and operational (typically,
Exercise: Is the “Transmit Data” (TxD) signal an input simply that the power is turned on). Some modems
or an output? How about “Receive Data” (RxD)? Is a com- can use DTR to force a reset and DSR as a replace-
puter a ‘modem’ or a ‘terminal’? ment for CD (see below).
The standard RS-232 connector is a 25-pin D-style In the original RS-232 specification there was no
connector called a ”DB-25”. Pin 2 is TxD, pin 3 is provision for hardware flow control of data from the
RxD and pin 7 is signal ground. When two serial de- DCE to the DTE. However many modems change
vices are connected together they are connected pin- the semantics of RTS so that it is used to flow control
to-pin (RxD is connected to RxD and TxD is con- data from the modem to the terminal (“bidirectional
nected to TxD). This means that RxD must be an in- RTS/CTS flow control”) .
put on one device and an output on the other device. Exercise: Which data line (TxD or RxD) would RTS
Thus the terms RxD and TxD do not say whether a flow control in this case?
pin is an input or output but are instead names for A number of other handshaking signals are avail-
pins on the connector. Typically DTE connectors are able but are less widely used. Carrier Detect (CD)
male and DCE connectors are female. is asserted by modem-type DCEs when a carrier sig-
In addition to the two data lines, most RS-232 de- nal is present. This signal is typically used by system
1
software to indicate the start and end of a dial-up ses- to indicate the start of the character being sent. This
sion. Another signal pin is Ring Indicator (RI) which is followed by the bits in the character, from LS to
is used by modem-type DCEs to indicates that the at- MS bit. After sending the 7 (for plain ASCII) or 8
tached phone is ringing. This signal is seldom used. (for arbitrary bytes) bits, an optional parity bit (even
The RS-232 specification defines a number of other or odd) can be sent, followed by a one “stop” bit.
signals (e.g. a secondary serial interface) but they are
almost never used.
In addition to the standard DB-25 serial con-
nector, there are a number of smaller connectors
that are widely used. These connectors are physi-
cally smaller and carry a subset of the RS-232 pins.
Exercise: Draw the waveform used to send the ASCII
The most common are the DB-9 connectors popu-
character ’e’ (hex 65) at 9600 bps with no parity.
lar on IBM PC-AT clones, the round DIN connectors
The start bit allows a receiver to re-synchronize
(popular on Apple computers), and the inexpensive
itself at the start of each character. This allows
telephone-style “RJ-11” (6-pin) and “RJ-45” (8-pin)
for small variations between transmitter and receiver
connectors (popular on devices with many serial in-
timing.
terfaces).
Adapters are often used not only to convert be- Exercise: What happens if the receiver’s clock is run-
tween different styles of connectors but also to con- ning faster than the transmitter clock?
vert between male and female connectors (a “gender The stop bit guarantees that there will be a tran-
adapter” which allows two males or two females to sition at the start of each character. It also allows
be connected together) and to switch between DCE a receiver to re-synchronize to a character boundary
and DTE pinouts (a “null modem” which allows two in the middle of a continuous data stream. If the re-
DCEs or two DTEs to be connected together). ceiver does not see a ’one’ stop bit (called a “framing
error”) it knows it is unsynchronized and treats that
bit as a start bit. Eventually the receiver will syn-
Interface Voltages
chronize to an actual start bit.
The serial interface voltage levels are bipolar with Exercise: What would happen if the receiver was ex-
respect to ground. The table below summarizes the pecting 8-bit characters and the transmitter was sending
relationship between voltage level, logical meaning 7-bit characters? What about the reverse case?
on handshaking lines and data bit value (values on There are a number of standard bit rates, typically
TxD and RxD lines). powers of two times 1200 bps (1200, 2400, 4800 bps
Signal Line For For etc). The RS-232 standard specifies maximum bit
Level State Handshaking Data rates, distances, etc but these are usually ignored in
negative mark false 1 practical applications. For short distances it’s possi-
positive space true 0 ble to send in excess of 100 kbps.
The RS-422 serial interface specification uses a
The received signal must be greater than +3 volts similar signaling scheme but uses differential signals
to be considered positive and less than -3 volts for (opposite voltages on two signal lines) to increase
negative. Intermediate values are considered invalid. immunity to noise and increase maximum transmis-
This allows disconnected pins to be detected. sion distance. Data rates up to 1 Mbps are common.
Note: The data lines (TxD and RxD) are asserted
when negative. The control lines (e.g. CTS) are as-
serted when positive. Synchronous Interfaces
One problem with asynchronous interfaces is the 2-
Character Format
bit penalty imposed by the start and stop bits. In a
Data is transferred over the serial interface one bit at synchronous interface the modem (DCE) supplies a
a time. A positive (zero) bit (the “start bit”) is sent clock signal output along with the data. The data
2
source (DTE) must supply a clock along with data. Special chips are used to convert the logic voltages
The timing accuracy requirements for synchronous used by the UARTs to/from the RS-232 signal levels.
devices are much stricter. There are also chips (USARTs) that perform the
Synchronous serial interfaces are often embedded same functions as UARTs but can also handle syn-
in links between peripheral devices rather than be- chronous data streams including the HDLC framing,
tween the computer and an external device. For ex- bit stuffing and error checking.
ample all modern modems use synchronous signal-
ing between themselves.
Serial Peripheral Interfaces
A problem with synchronous interfaces is that
some means must be provided to find the start of A third type of serial interface is used to connect pe-
the desired data within a continuous bit stream. The ripheral chips such as A/D converters, serial EEP-
HDLC (High-level Data Link Control) protocol, of- ROMs, FPGAs or other microprocessors to a micro-
ten used over synchronous bit stream channels, uses processor. The purpose of these serial interfaces is
a procedure called bit stuffing. HDLC uses “flag” to reduce the pin count. These interfaces are often
sequences of a zero, 6 consecutive ’1’ bits and an- found on microcontrollers and DSP microprocessors
other zero at the start and end of each frame to di- and include both a data line and a clock line. The
vide the data stream into frames. In order to prevent clock can be driven by the processor (the CPU is
sequences of 6 ’1’ bits in the data from being mis- called the “master”) or by the source of the data (the
interpreted as terminating a frame, a zero bit is in- CPU is the “slave”).
serted immediately after into any data sequence of 5
Exercise: What type of sequential logic device(s) would
’1’ bits. At the receiver a ’0’ received after 5 ’1’s
be used to implement this type of serial interface?
is removed. The HDLC frame includes one-byte ad-
dress and control fields at the start of the frame and a
16-bit check-sum (a CRC, actually) at the end.
Exercise: What is the probability of finding 6 consecu-
tive ’1’ bits in a random data stream?