RS232 Protocol and Fundamentals
Learning Goals
- Understand RS232 protocol specification: recognizing asynchronous serial communication standard for point-to-point connections, utilizing start/stop bit frame structure, supporting configurable baud rates, and maintaining compatibility across different manufacturers
- Master RS232 pin assignments: identifying TXD (Transmit Data) on pin 3 for data transmission, recognizing RXD (Receive Data) on pin 2 for data reception, understanding ground reference pins, and analyzing 9-pin vs 25-pin connector configurations
- Analyze RS232 voltage levels: recognizing signal voltage range (±3V to ±15V typical), differentiating mark state (-5V to -15V representing binary 1) from space state (+5V to +15V representing binary 0), and understanding inversion relative to TTL levels
- Master flow control signals: understanding RTS (Request to Send) from transmitter and CTS (Clear to Send) from receiver enabling transmit operation when low, analyzing DSR (Data Set Ready) and DTR (Data Terminal Ready) for device status indication
- Understand 8051 serial modes: Mode 0 (synchronous 8-bit with shift clock), Mode 1 (asynchronous 10-bit transmission: start + 8 data + stop), Mode 2 (asynchronous 11-bit with programmable baud rate), Mode 3 (asynchronous 11-bit similar to Mode 2 with extended capability)
The RS232 (Recommended Standard 232) is a long-standing standard for serial binary data signals connecting between a DTE (Data Terminal Equipment, like a computer) and a DCE (Data Circuit-terminating Equipment, like a modem) . In the context of microprocessors, it is the primary method for point-to-point external communication, allowing a controller to "talk" to peripherals or other computers over relatively long distances compared to I2C or SPI.
Unlike parallel communication, which sends multiple bits simultaneously, RS232 is an asynchronous serial protocol. This means data is sent bit-by-bit over a single wire, and the transmitter and receiver do not share a common clock signal. Instead, they agree on a specific baud rate (bits per second) and use a standardized frame structure to synchronize communication.
Footnotes
-
Ultimate review on RS232 protocol - Detailed overview of DTE/DCE and protocol longevity. ↩
RS232 Connection to 8051 Microcontroller
Electrical Specifications and Voltage Levels
One of the most critical aspects of RS232 is its electrical characteristic, which differs significantly from the Transistor-Transistor Logic (TTL) used inside microprocessors like the 8051. RS232 uses bipolar voltage levels to increase noise immunity over long cables .
- Logic 1 (MARK): Represented by a negative voltage between and .
- Logic 0 (SPACE): Represented by a positive voltage between and .
This creates a fundamental "inversion" compared to TTL logic, where is logic 1 and is logic 0. To bridge this gap, an interface IC like the MAX232 is required to perform voltage level shifting and logical inversion.
| Characteristic | RS232 Standard | TTL (Microcontroller) |
|---|---|---|
| Logic 1 | to | (or ) |
| Logic 0 | to | |
| Max Cable Length | ~50 feet (at 19200 baud) | Few inches |
Footnotes
-
An introduction to RS232 serial port communication - Explanation of Mark/Space voltage levels. ↩
Voltage Incompatibility
Never connect an RS232 port directly to a microprocessor pin. The negative voltages (up to -15V) and high positive voltages (up to +15V) of RS232 will permanently damage the CMOS/TTL logic of the controller .
Footnotes
-
MAX232 Signal Conversion Explained - Importance of level shifting for TTL compatibility. ↩
RS232 Data Frame Structure
- 1Step 1
The transmission line is held at the MARK state (negative voltage) when no data is being sent.
- 2Step 2
The transmitter pulls the line to the SPACE state (positive voltage) for exactly one bit-clock period. This '0' bit alerts the receiver that a data frame is beginning.
- 3Step 3
5 to 8 bits of data are sent, starting with the Least Significant Bit (LSB). Each bit is held for the duration defined by the baud rate ().
- 4Step 4
An optional bit used for simple error checking (Even or Odd parity) to ensure the integrity of the data byte.
- 5Step 5
The transmitter returns the line to the MARK state for 1, 1.5, or 2 bit periods to signify the end of the frame and prepare for the next start bit.
Pin Assignments and Flow Control
While the original RS232 standard used a 25-pin DB25 connector, most modern applications use the more compact 9-pin DB9 (or DE-9) connector.
Essential Pins (DB9)
- Pin 2 (RXD): Receive Data.
- Pin 3 (TXD): Transmit Data.
- Pin 5 (GND): Signal Ground (Common reference).
Hardware Flow Control
Flow control prevents data loss when the receiver's buffer is full.
- RTS (Request to Send): The DTE signals that it wants to send data.
- CTS (Clear to Send): The DCE signals that it is ready to receive.
- DTR (Data Terminal Ready): DTE indicates it is powered on and ready.
- DSR (Data Set Ready): DCE indicates it is powered on and ready .
Footnotes
-
RS232 pinout and signals - Comprehensive guide to hardware flow control signals. ↩
| Pin | Name | Direction | Description |
|---|---|---|---|
| 1 | DCD | In | Data Carrier Detect |
| 2 | RXD | In | Receive Data |
| 3 | TXD | Out | Transmit Data |
| 4 | DTR | Out | Data Terminal Ready |
| 5 | GND | - | Ground |
| 6 | DSR | In | Data Set Ready |
| 7 | RTS | Out | Request to Send |
| 8 | CTS | In | Clear to Send |
| 9 | RI | In | Ring Indicator |
8051 Microcontroller Serial Modes
The 8051 microcontroller features a built-in UART (Universal Asynchronous Receiver/Transmitter) controlled by the SCON (Serial Control) register. It supports four distinct modes of operation :
Mode 0: Synchronous Shift Register
- Frame: 8 bits of data.
- Clock: Provided through the TXD pin; data enters/exits through RXD.
- Baud Rate: Fixed at .
Mode 1: 8-Bit UART (Standard)
- Frame: 10 bits (1 Start, 8 Data, 1 Stop).
- Baud Rate: Variable, typically determined by the overflow rate of Timer 1. This is the most common mode for RS232 communication.
Mode 2: 9-Bit UART (Fixed Baud)
- Frame: 11 bits (1 Start, 8 Data, 1 Programmable 9th bit, 1 Stop).
- Baud Rate: Fixed at or (controlled by the PCON register).
Mode 3: 9-Bit UART (Variable Baud)
- Frame: 11 bits (same as Mode 2).
- Baud Rate: Variable, determined by Timer 1. Useful for multi-processor communications where the 9th bit acts as an address/data identifier.
Footnotes
-
Serial I-O for 8051 - EE337 Microprocessors Lab - Technical breakdown of 8051 serial modes and SCON register. ↩
8051 Serial Mode Comparison
Number of bits per frame across different 8051 modes
Baud Rate Calculation
In 8051 Mode 1, the baud rate is calculated as:
Where is the double-baud-rate bit in the PCON register .
Footnotes
-
Serial I-O for 8051 - EE337 Microprocessors Lab - Technical breakdown of 8051 serial modes and SCON register. ↩
Knowledge Check
In RS232 standard, what voltage range represents a binary '0' (Space)?