1.
SERIAL COMMUNICATION
BASICS OF SERIAL COMMUNICATION
When a microprocessor communicates with the outside world, it provides the data in byte-
sized chunks. In some cases, such as printers, the information is simply grabbed from the 8-
bit data bus and presented to the 8-bit data bus of the printer. This can work only if the
cable is not too long. Furthermore, an 8-bit data path is expensive. For these reasons, serial
communication is used for transferring data between two systems located at distances of
hundreds of feet to millions of miles apart.
The fact that serial communication uses a single data line instead of the 8-bit data line of
parallel communication not only makes it much cheaper but also enables two computers
located in two different cities to communicate over the telephone.
Half- and full-duplex transmission
In data transmission if the data can be transmitted and received, it is a duplex transmission.
This is in contrast to simplex transmissions such as with printers, in which the computer only
sends data. Duplex transmissions can be half or full duplex, depending on whether or not
the data transfer can be simultaneous. If data is transmitted one way at a time, it is referred
to as half duplex. If the data can go both ways at the same time, it is full duplex. Of course,
full duplex requires two wire conductors for the data lines (in addition to the signal ground),
one for transmission and one for reception in order to transfer and receive data
simultaneously.
Asynchronous vs. Synchronous Communication
Synchronous: Sender and receiver share clock; exact timing; mode 0.
Asynchronous: No shared clock, but both still operate at same frequency. Start and
stop bits needed for alignment; modes 1, 2, and 3.
SERIAL PORT OF 8051
8051 has a high speed, full duplex, software programmable Serial Port.
Data is received serially through the RxD line, and transmitted through the TxD line.
SBUF register acts as a buffer for both reception and transmission.
The SCON SFR mainly controls serial Communication.
The SMOD bit in the PCON SFR controls the baud rate.
PCON (Power Control) Register:-Controls power modes and serial communication speed.
SCON (Serial Control Register) Structure
SM2 (Serial Port Mode Bit 2)
Enables multiprocessor features in Mode 2 and Mode 3.
Mode 2 or Mode 3:
If SM2 = 1, RI will be 1 when the 9th data bit received is "1".
Mode 1:
If SM2 = 1, RI will be 1 when the Stop bit received is "1" (valid).
Mode 0:
SM2 is kept 0 (Not Used).
REN (Receiver Enable)
REN = 1: Enables the Receiver.
REN = 0: Disables the Receiver.
TBS (Bit 8, i.e. 9th bit transmitted)
In Mode 2 and Mode 3 holds the 9th Programmable bit to be transmitted.
In Mode 1 and Mode 0 it is not used.
RBS (Bit 8, i.e. 9th bit received)
In Mode 2 and Mode 3, used to receive the 9th Programmable bit.
In Mode 1, receives the Stop bit.
In Mode 0, it is not used.
RI (Receive Interrupt)
RI = 1: One complete character is received.
RI must be explicitly cleared by software before receiving the next byte.
TI (Transmit Interrupt)
TI = 1: One complete character is transmitted.
TI must be explicitly cleared by software before transmitting the next byte.
SMOD (Serial Baud rate Modify Bit in PCON SFR)
SMOD = 1: Doubles baud rate of Timer 1 for Modes 1, 2, and 3.
SMOD = 0: Uses Timer 1 baud rate.
SBUF Register
Physically two registers—one holds received character, one holds character to be
transmitted.
Both receive and transmit registers are addressed 99H.
Serial Data Interrupt
When a complete character is received the RI bit is set in the SCON Register.
When a complete character is transmitted the TI bit is set.
These two bits are OR'ed to produce the serial data interrupt.
RI/TI bit must be explicitly cleared before transferring the next character.
Data Transmission
Data written in SBUF.
Data transmitted through TxD.
When a complete character is transmitted, TI is set.
Serial Data interrupt occurs.
In ISR the TI bit is reset.
New data written into SBUF—process continues till all data is transmitted.
Data Reception
REN in SCON must be set to prevent receiving unwanted data (e.g., noise).
Data received through RxD into SBUF.
When a complete character is received, RI is set.
Serial Data interrupt occurs.
In ISR the RI bit is reset; program accepts the received data.
New data is received in SBUF and process repeats.
Multiprocessor Communication in Mode 2
If multiple processors on serial network:
Sender sets TB8 (9th bit):
TB8=1: “Broadcast” (all devices accept).
TB8=0: “Selective” (only devices with SM2=0 accept).
Receivers use SM2:
SM2=1: Performs error check on 9th bit. Only accepts if TB8=1.
SM2=0: Blindly accept all data.
Example: Set-top box analogy:
Strict box (SM2=1): Only accepts correct channels.
Lenient box (SM2=0): Accepts all channels.
Serial Data Transfer Modes
a) Mode 0 (Shift Register)
8-bit Half-Duplex mode.
Start/Stop bits not required.
TXD line provides clock for data transfer (square wave pattern).
Transmission: Data is shifted out of SBUF.
Reception: RXD is sampled and then shifted.
Used for high-speed data collection with discrete logic (not for computer
communications).
Baud rate: Fixed, fBaud = f/12 (Oscillator Frequency).
B)Mode 1 (8-bit "Standard" UART)
C)Mode 2 (9-bit UART) (Multiprocessor Mode)
2. 8051 connection to RS 232
Basic Analogy — “Two People Speaking Different Languages”
Imagine:
8051 microcontroller = speaks “TTL language” (0 V to +5 V)
Computer (PC) = speaks “RS232 language” (−12 V to +12 V)
They both want to talk — but their “languages” (voltage levels) are totally different!
➡️MAX232 acts like a translator between them.
It converts the high and negative voltages of the PC into safe TTL voltages for the 8051, and
vice versa.
So:
8051 says “Hi” (+5 V signal)
MAX232 converts it to −12 V (RS232 level)
PC understands it
…and the same happens in reverse.
So think of MAX232 = language translator between 8051 (TTL) and PC (RS232).
1. What is RS232?
RS232 is a serial communication standard used for connecting computers and
devices (like modems, microcontrollers, etc.).
It was set by EIA (Electronics Industries Association) in 1960 to make devices from
different manufacturers compatible.
Updated versions:
o RS232A → 1963
o RS232B → 1965
o RS232C → 1969
We commonly just call it RS232.
2. Why RS232 was needed
Different devices communicate serially (bit by bit), but each used different voltage
levels and timing.
3. RS232 Voltage Levels (Important!)
Logic RS232 Voltage TTL Voltage (used in microcontrollers)
1 (Mark) -3V to -25V +5V
0 (Space) +3V to +25V 0V
➡️Because of this voltage difference, RS232 is not TTL-compatible.
➡️That’s why we need a voltage converter (MAX232) to connect RS232 to 8051.
4. RS232 Connectors
DB-25 Connector (25 pins) → Old standard
DB-9 Connector (9 pins) → Common in PCs (introduced by IBM)
Type Gender Use
DB-9P Plug (Male) Connects to PC
DB-9S Socket (Female) On device/modem
RS232 Handshaking Signals (for data coordination)
When two devices communicate, they must coordinate “who sends” and “who receives.”
These control lines help manage that flow:
Signal Full Name Direction Function
DTR Data Terminal Ready PC → Modem PC sends this to show it’s ready.
DSR Data Set Ready Modem → PC Modem sends this to show it’s ready.
RTS Request To Send PC → Modem PC wants to send data.
CTS Clear To Send Modem → PC Modem says “OK, you can send now.”
Modem confirms connection with another
DCD Data Carrier Detect Modem → PC
modem.
RI Ring Indicator Modem → PC Phone line is ringing.
7. 8051 Microcontroller Serial Pins
TxD → P3.1 (Pin 11) → Transmit Data
RxD → P3.0 (Pin 10) → Receive Data
These are TTL-level pins (0V and +5V), not directly RS232-compatible.
8. Why MAX232 is Used
RS232 uses ± voltage (like +12V and -12V)
8051 uses 0V to +5V
MAX232 converts between these two voltage levels.
9.MAX232 Features:
Converts RS232 ↔ TTL
Works with a single +5V supply (same as 8051)
Contains two transmitters (T1, T2) and two receivers (R1, R2)
10. How MAX232 Works
MAX232 Section
Direction Signal Flow
Used
8051 → PC TxD (TTL) → MAX232 → RS232 Uses T1 driver
RS232 → MAX232 → RxD
PC → 8051 Uses R1 receiver
(TTL)
The capacitors connected to MAX232 help it generate the ± voltages internally.
Pin Function Connection
11 TXD (Transmit Data) Microcontroller output
10 RXD (Receive Data) Microcontroller input
14 T1OUT RS232 RX (DB9, Pin 2)
13 R1IN RS232 TX (DB9, Pin 3)
12 R1OUT Microcontroller RXD