Purple Computing
Pfranctastic
#1
Serial Communication Basics
RS-232
The most common method of handling serial communications utilizes aspects of a standard
called “RS-232.” RS-232 is a species of serial connection described in a Electronic Industries Association (EIA) specification
which, in conjunction with the Telecommunications Industry Association, defines
the standards for traditional serial data transfer. Formally, the RS-232
standard is called EIA/TIA-232-F, reflecting the initials of the organizations
that administer it. The RS-232 specification describes the signaling,
electrical, and mechanical characteristics of RS-232 serial ports.
Serial Communications Equipment
The RS-232 specification defines two types of communication equipment: Data
Terminal Equipment, (abbreviated as DTE); and Data Circuit-Terminating
Equipment, or DCE. These two types of equipment differ in pin-out assignments
—for practical purposes the connector at a PC can be considered a DTE, and a
connector on a modem a DCE. Usually an RS-232 link connects a DTE to a DCE. A
link can also be connected from DTE to DTE using a crossover or “null-modem”
cable to make the connection between two DTE appear as if there were modem
equipment inbetween (as when connecting two PCs with
a serial cable).
Signaling
The RS-232 standard defines 25 signal lines in its interface. Many of these
signals are used for synchronous communication and duplex sub-channel
signaling, and are not supported by most PC equipment. In practice a PC rarely
will use more than nine of these lines even if it has a 25-pin connector. In
fact, with just three of these lines—receive data (RD), transmit data (TD), and
ground (G)—bi-directional RS-232 communication can occur.
The other lines are designated for a variety of control purposes. The remainder
of the basic nine lines consist of: data carrier detect (DCD), data terminal
ready (DTR), data set ready (DSR), request to send (RTS), clear
to send (CTS), and ring indicator (RI). These nine signal paths are those
typically used between a PC and a serial device such as a modem.
Electrical
RS-232 signals are indicated by voltage differences with respect to a ground
signal, and can vary between +3 to +15 volts and -3 to -15 volts. At the same
time, serial receivers must be undamaged by voltages up to ±25 volts, and
transmitters if connected to a ground or to another transmitter. The control
lines in RS-232 use “positive” voltage logic to indicate their state. That is,
a positive voltage on a wire carrying a control signal (DCD, DTR, DSR, RTS,
CTS, and RI on a nine-wire connection) indicates that the control signal
involved can be described as “On” , “Asserted” , “1” or “True.” A negative
voltage on a control line indicates that the control signal involved can be
described as “Off”, “De-asserted” , “0” or “False.”
The data lines are just the opposite. Data lines use a “negative” voltage
logic, meaning that a negative voltage on the wire carrying the data signal (RD
or TD on a nine-wire connection) is described as “On”, “Asserted”, “Mark”,
“Marking”, “1” or “True.” Conversely, a positive voltage on the wire is
interpreted as “Off”, “De-asserted”, “Space”, “Spacing”, “0” or “False.”
RS-232 also defines electrical signaling timing. An RS-232
connection differentiates between the bits of a serial data stream by reading
the voltage of its data lines. The number of readings taken within a byte is
determined by the settings used in the hardware for composing serial data:
whether the connection is synchronous (has external bit clocking and does not
utilize “start” and “stop” bits) or asynchronous (utilizes “start” and “stop”
bits and uses internal bit clocking), the number of data bits set for the link,
whether the connection has a parity bit.
Mechanical
Each line in an RS-232 interface is assigned a pin
number for the various connectors that RS-232 can use. The nine primary lines,
and their assignments in DB-9 and DB-25 connectors, are shown below.
Synchronous vs. asynchronous RS-232
RS-232 signals can be synchronous or asynchronous. Asynchronous RS-232 is by
far the most common. Asynchronous RS-232 signals are delineated by voltage
changes that identify the start and end of any byte of data. Within any byte of
data, the receiver is actually applying a clock to measure the elements of the
data transmission, and will sample the voltage level within the byte in a
manner corresponding to the number of discrete bits of data it expects the byte,
along with its framing and possible parity bits, to have.
Synchronous RS-232 signals are synchronized by a clock that dictates the timing
of each bit that is sent. The timing provided by the clock is shared by both
sides of the serial connection, so each side is aware of the timing of the next
bit of data. Additional control lines beyond the basic nine lines are needed to
support synchronous RS-232, and these are not present on a standard PC.
Asynchronous, In the simplest terms, monitors the incoming data line for a
transition from True to False with that transition signifying the beginning of
a “start” bit and hence a data byte. Then, reading the line at intervals
predefined by the data rate, with each interval representing the next bit in
the stream of data, a character is read. The last such bit read must again be True, and is the “stop” bit. Once the stop bit is read, the
connection waits for the next start bit to arrive. The timing of these
intervals is determined by the data rate of the link.
Asynchronous Transmission Basics
In the most common Windows and MAC communication
hardware the transmission mode is asynchronous. The software and hardware of
each serial port has line setting parameters that allow the port to be
configured. The settable parameters control the speed, number of data bits,
type of parity, number of stop bits, and type of flow control and byte settings
related to the handling of the higher level protocol used.
Data
Frame
A byte of asynchronous data is carried within a “frame”. The frame consists of
a leading “start” bit and one or more trailing “stop” bits. Between the start
and stop bits are the bits composed of the data byte and, optionally, a parity
bit. There must always be the same number of bits present between the start and
stop bits, and if the stop bit is not found where expected a “framing” error is
detected.
Stop and start bits
When framing a byte, the hardware adds bits that
indicate the start and stop of each byte. Without these start and stop bits,
the flow of serial data would be an undifferentiated stream. The hardware adds
a start bit and either 1, 1½ or 2 stop bits. Use of 1½
stop bits is normally limited to use, and is only valid, when the data byte is
comprised of 5 bits.
Data bits
The serial data can be configured to specify the number
of data bits in a frame. The number of data bits used can be 4, 5, 6, 7, or 8.
When the hardware sends the data bits, it sends the data bits of the byte in
the order of least significant bit to most significant bit; e.g.: bit-0 of each
byte follows the start bit.
Parity bits
As it frames a byte for transmission, the hardware may
also add a bit called a “parity bit” to provide a means of checking that the
data received matches the data that was transmitted. Parity bits can have one
of five possible settings: none, even, odd, mark, or space. Without matching
parity settings on both sides of a link, the receiving hardware, if parity
checking is enabled, will detect and report “parity errors”. Normally, parity
can not be used with 5-bit data.
Flow Control
The serial port has a setting for flow control that
allows choosing a method of controlling the flow of data so that the
transmitting device does not send data faster than it can be consumed by the
receiving device. The methods of flow control are hardware (called “CTS/RTS” or
“DTR/DSR”) and software (called “Xon/Xoff”). Additionally a feature called “DSR
Sensitivity” can be employed. All of these methods can be used to control the
flow of data between the PC serial port, devices such as one or more modem, and
the final receiving device. Hardware flow control uses dedicated lines of the
serial connection to communicate the flow control protocol. Software flow
control places controlling data bytes into the data transmission stream, and
they travel along with the data. In most cases, hardware flow control is
preferable because it is more immediately responsive than software flow
control. Software flow control can be used when the serial cable does not have
dedicated control wires. See document “Serial DCB.htm” for more information.
Buffers
and triggers
Most PC serial ports have hardware equipped with
buffers, or small portions of storage devoted to storing groups of bytes in
transit through the hardware. Buffers greatly improve the efficiency of serial
port interactions, and help to reduce transmission errors called “overrun
errors” that occur when a new byte arrives at a serial port before the previous
byte has left the hardware.
Hardware usually has adjustable settings governing
when data in the buffers is released. These settings are the “trigger levels”
of the hardware. The trigger level for the input buffer indicates the number of
bytes of data required to be in that buffer before the driver is asked to
collect them; the trigger level for the transmit buffer indicates the number of
bytes of data remaining in that buffer before the driver is asked to refill it.
Software usually also has buffering built into the driver. This buffering can
be quite extensive, being limited only by the size of memory that is allowed to
be allocated to a driver, and or by parameters passed from the users application to the driver.
RS-232 Signals
DTR: Data Terminal Ready
Used by a piece of Data Terminal Equipment to signal that it is available for
communication.
DSR: Data Set Ready
The companion signal to DTR, it is used by a piece of Data Circuit-Terminating
Equipment to signal that it is available for communication.
CTS: Clear to Send
Used by a piece of Data Circuit-Terminating Equipment to signal it is available
to send data. This line is also used in response to an RTS request for data.
RTS: Request to Send
Used by a piece of Data Terminal Equipment to indicate that it has data to send.
DCD: Data Carrier Detect
Used by a piece of Data Circuit-Terminating Equipment to indicate to the Data
Terminal Equipment that it has received a carrier signal from the modem and
that real data is being transmitted. Sometimes abbreviated as
CD.
RI: Ring Indicator
Used by a Data Circuit-Terminating Equipment modem to tell a piece of Data
Terminal Equipment that the phone is ringing and that some data will be
forthcoming.
TD: Transmit Data
This wire is used for sending data. Sometimes
abbreviated as TXD. This wire will also be used to carry flow control
information if software flow control is enabled.
RD: Receive Data
This wire is used for receiving data. Sometimes abbreviated as RXD. This wire will also be used to
carry flow control information if software flow control is enabled.
GND: Ground
This wire is the same for Data Circuit-Terminating Equipment and Data Terminal
Equipment, and it provides the return path for both data and handshake signals.
RS-232 Connectors and
Cabling
See the diagrams in document “Serial Pins.htm” for
9 and 25 pin connector layout and the wiring of loop-back adapters and
null-modem cables.