RS232
RS232
RS232
INTRODUCTION
There are several popular types of serial communications. Here are
a few worth noting:
RS232. Peer-to-peer (i.e. communications between two devices)
RS485. Multi-point (i.e. communications between two or more
devices)
USB (Universal Serial Bus). Replaced RS232 on desktop
computers.
CAN (Controller Area Network). Multi-point. Popular in the
automotive industry.
SPI (Serial Peripheral Interface). Developed by Motorola.
Synchronous master/slave communications.
I2C (Inter-Integrated Circuit).Developed by Philips. Multi-master
communications.
RS-232(1)
What is RS-232?
RS-232 is a standard by which two serial devices communicate.
The connection must be no longer than 50 feet.
Transmission voltages are 3 to -25V and +3 to +25V.
It is designed around transmission of characters (of 8 bits of
length).
One important aspect of RS-232 is that it is an asynchronous form
of communication.
Asynchronous communication is important because it is efficient;
if no data needs to be sent, the connection is idle. No additional
CPU overhead is required for an idle serial line.
RS-232(2)
Logical Voltages:
Logical 1 is -3 to -25Volts. (ON)
Logical 0 is +3 to +25Volts. (OFF)
When the connection is idle, the hardware ties the connection to
logical 1.
How can You Transmit Data?
RS-232 communication is dependent on a set timing speed at
which both pieces of hardware communicate. In other words, the
hardware knows how long a bit should be high or low.
RS-232 also specifies the use of start and stop bits.
The start bit is a logical 0 sent on the line to tell the other device
to start sampling.
Remember, the logical 0 is +3 to +25Volts.
The stop bit is a logical 1. -3 to -25Volts.
Function
Abbreviation
Pin #1
Chassis/Frame Ground
GND
Pin #2
Transmitted Data
TD
Pin #3
Receive Data
RD
Pin #4
Request To Send
RTS
Pin #5
Clear To Send
CTS
Pin #6
DSR
Pin #7
Signal Ground
GND
Pin #8
DCD or CD
Pin #9
TD+
Pin #11
TD-
Pin #18
RD+
Pin #20
DTR
Pin #22
Ring Indicator
RI
Pin #25
RD-
Function
Abbreviation
Pin #1
CD
Pin #2
Receive Data
RD or RX or RXD
Pin #3
Transmitted Data
TD or TX or TXD
Pin #4
DTR
Pin #5
Signal Ground
GND
Pin #6
DSR
Pin #7
Request To Send
RTS
Pin #8
Clear To Send
CTS
Pin #9
Ring Indicator
RI
UART
When we talk about serial communications, what do we really
mean? How is the data transmitted? Serial data is transmitted
between devices one bit at a time using agreed upon electrical
signals. In our C programs, though, we read and write bytes to the
serial port not bits. To accomplish the necessary translation
between bytes and bits, another piece of hardware is required the
UART.
UART (pronounced You Art) is an industry acronym that
stands for Universal Asynchronous Receiver Transmitter. It is the
interface circuitry between the microprocessor and the serial port.
This circuitry is built in to the 8051 microcontroller.
The UART is responsible for breaking apart bytes of data and
transmitting it one bit at a time (i.e. serially). Likewise, the UART
receives serialized bits and converts them back into bytes. In
practice, its a little more complicated, but thats the basic idea.
UART
The UART, however, doesnt operate at the line voltages required
by the RS232 standard. The UART operates at TTL voltage levels
(i.e. 0 to 5V). For noise immunity and transmission length, the
RS232 standard dictates the transmission of bits at a higher
voltage range and different polarities (i.e. typically -9V to +9V).
An external transceiver chip is needed.
Binary 0: UART: 0V RS232: +3 to +25V
Binary 1: UART: 5V RS232 -3V to -25V
UART
UART communications is asynchronous (i.e. not synchronous). This
means that there is no master clock used for timing data transfer
between devices.
The UART is also responsible for baud rate generation. This
determines the speed at which data is transmitted and received. One
baud is one bit per second (bps). As of this writing, data rates can
reach up to 230,400 baud. The cable length between devices is limited
by the baud rate -- the higher the speed, the shorter the cable. The RS232C standard only permits transmission speeds up to 19200 baud
with a cable length of 45 feet. With modern UARTs, 230,400 baud
can be achieved with a short cable length of a few feet.
A Simple Transmission
Register List
Handshaking(1)
The 8051 only has a one-byte buffer SBUF. In contrast, a typical
PC serial port with a 16550 UART has a 16-byte buffer.
If SBUF is not serviced quickly enough, an incoming byte may
overwrite a byte that has not yet been read and processed. Using a
control technique called handshaking, it is possible to get the
transmitting device to stop sending bytes until the 8051 is ready.
Likewise, the 8051 can be signaled by the receiving device to stop
transmitting. There are two forms of handshaking software and
hardware.
Handshaking(2)
Software handshaking (also called XON/XOFF) uses control characters in the
byte stream to signal the halting and resuming of data transmission. Control-S
(ASCII 19) signals the other device to stop sending data. Control-Q (ASCII
17) signals the other device to resume sending data. The disadvantage with this
approach is that the response time is slower and two characters in the ASCII
character set must be reserved for handshaking use.
Hardware handshaking uses additional I/O lines. The most common form of
hardware handshaking is to use two additional control wires called RTS
(Ready to Send) and CTS (Clear to Send). One line is controlled by each
device. The line (either RTS or CTS) is asserted when bytes can be received
and unasserted otherwise. These two handshaking lines are used to prevent
buffer overruns.
Handshaking(3)
There are two other less commonly used lines DTS (Data
Terminal Ready) and DSR (Data Set Ready). These lines are
typically used by devices signaling to each other that they are
powered up and ready to communicate.
To summarize, RTS/CTS are used for buffer control and DTS/DSR
are used for device present and working indicators. In practice,
serial communication with no handshaking uses 3 wires (TX, RX
and GND). Serial communications with basic hardware
handshaking uses 5 wires (TX, RX, RTS, CTS and GND).
BaudRates