MicroprocessorUnit 613 min read
Serial Communication, USART, RS-232 & Asynchronous Data Transfer
Unit 6 of Microprocessor covers serial communication principles, the Universal Synchronous/Asynchronous Receiver/Transmitter (USART) architecture (8251), RS-232 standard, asynchronous data transfer, and practical applications in embedded systems and real-world devices like eSewa terminals and Ncell modems.
TAKEAWAYS:
- Serial communication transmits data one bit at a time over a single wire (vs. parallel’s multiple wires), reducing cost and complexity in long-distance or multi-device links.
- The 8251 USART handles both synchronous (clock-based) and asynchronous (start/stop-bit) data transfer, with programmable baud rates, parity, and word lengths.
- RS-232 defines electrical signals (±3V to ±15V), connectors (DB-25/DB-9), and handshake lines (RTS/CTS) for reliable serial communication between devices like printers and modems.
- Asynchronous communication uses start/stop bits to synchronize sender/receiver clocks, while synchronous uses a shared clock signal for precise timing.
- USART advantages over parallel I/O include longer cable distances, fewer wires, and easier interfacing with external peripherals (e.g., GPS modules, sensors).
- Real-world examples: eSewa terminals use USART for secure serial communication with payment gateways, Ncell modems rely on RS-232 for AT command-based configuration, and industrial PLCs use serial links for remote monitoring.
1. Serial vs. Parallel Communication: Why Serial Wins in Most Cases
Serial communication transmits data bit-by-bit over a single wire (or pair), while parallel sends multiple bits simultaneously over multiple wires. While parallel is faster for short distances (e.g., CPU-memory bus), serial dominates in:
- Long-distance links (e.g., modems, GPS, sensors).
- Multi-device networks (e.g., USB, UART, I²C).
- Cost-sensitive applications (fewer wires = cheaper cables/connections).
Comparison Table: Serial vs. Parallel
| Feature | Serial Communication | Parallel Communication |
|---|---|---|
| Data Path | 1 bit at a time (single wire) | Multiple bits at once (8/16/32 wires) |
| Speed | Slower for short distances | Faster for short distances (e.g., CPU bus) |
| Distance | Longer (kilometers, e.g., RS-232, USB) | Limited (meters, e.g., printer cables) |
| Complexity | Simpler wiring, fewer pins | Complex wiring, more pins |
| Error Rate | Higher (noise susceptibility) | Lower (shorter traces) |
| Examples | UART, USB, I²C, SPI, RS-232 | Printer ports, CPU-memory bus |
2. Asynchronous Serial Communication: Start/Stop Bits and Baud Rate
Asynchronous communication (e.g., UART) does not use a clock signal. Instead, it relies on:
- Start bit (always
0): Signals the receiver that data is coming. - Data bits (5–9 bits): The actual payload (e.g., ASCII character).
- Parity bit (optional): Simple error-checking (even/odd).
- Stop bit (always
1): Marks the end of transmission.
How It Works: Bit Timing in Asynchronous Mode
timeline
title Asynchronous Data Frame (8N1: 8 data bits, No parity, 1 stop bit)
Start Bit: 0 (1 bit)
Data Bits: 1 0 0 0 0 1 1 0 (8 bits, e.g., 'A' in ASCII)
Parity: (None)
Stop Bit: 1 (1 bit)- Baud rate: Bits per second (e.g., 9600 baud = 9600 bits/sec).
- No clock signal: Sender/receiver must agree on baud rate beforehand.
Worked Example: Sending 'A' (ASCII 65) at 9600 Baud
- Time per bit: .
- Total frame time: 10 bits × 104.2 µs = 1.042 ms.
- If sender transmits 'A' every 2 ms, the receiver sees:
0 (start) | 0 1 0 0 0 1 1 0 (data) | 1 (stop) | [idle: 958 µs]
3. The 8251 USART: Architecture and Registers
The 8251 USART (Universal Synchronous/Asynchronous Receiver/Transmitter) is a programmable chip that handles both synchronous (clock-based) and asynchronous (start/stop-bit) serial communication. It is widely used in embedded systems (e.g., industrial controllers, modems).
Block Diagram of 8251 USART
Key Components:
- Control Register: Configures mode (sync/async), word length, parity, baud rate.
- Status Register: Reports errors (overrun, framing, parity) and buffer status (empty/full).
- Transmit/Receive Buffer: Holds data temporarily.
- Baud Rate Generator: Derives clock from input frequency (e.g., 1.8432 MHz → 9600 baud).
Register Fields: Mode Command Register (Asynchronous Mode)
| Bit | Field | Description |
|---|---|---|
| 7-6 | Word Length | 00: 5 bits, 01: 6 bits, 10: 7 bits, 11: 8 bits |
| 5 | Parity Enable | 1: Enable parity, 0: Disable |
| 4 | Even/Odd Parity | 1: Even, 0: Odd (if parity enabled) |
| 3 | Stop Bits | 1: 2 stop bits, 0: 1 stop bit |
| 2-0 | Baud Rate Divisor | Selects divisor for baud rate (e.g., 000: 1, 001: 16, etc.) |
4. RS-232 Standard: Electrical Levels and Handshaking
RS-232 (Recommended Standard 232) defines:
- Electrical levels:
-3V to -15V=1(logic high),+3V to +15V=0(logic low). - Connectors: DB-25 (older) or DB-9 (modern).
- Handshake lines: Ensures reliable data transfer between DTE (Data Terminal Equipment, e.g., PC) and DTE (Data Circuit-terminating Equipment, e.g., modem).
RS-232 Pinout (DB-9 Connector)
Key Signals:
- TXD/RXD: Transmit/Receive data.
- RTS/CTS: Hardware flow control (sender waits for CTS before transmitting).
- DTR/DSR: Indicates if devices are ready.
Real-World Example: Ncell Modem Configuration via RS-232
Ncell’s 3G/4G modems use RS-232 for AT command-based configuration:
- A PC connects to the modem via RS-232 (DB-9).
- The PC sends
AT(attention) commands (e.g.,AT+CGATT=1to attach to the network). - The modem responds with OK/ERROR over RXD.
- Handshake: RTS/CTS ensures the modem isn’t overwhelmed by rapid commands.
5. Synchronous vs. Asynchronous Communication
| Feature | Asynchronous (UART) | Synchronous (SPI/I²C) |
|---|---|---|
| Clock Signal | No (start/stop bits) | Yes (shared clock) |
| Speed | Slower (baud rate limited) | Faster (clock speed limited) |
| Complexity | Simpler (no clock wiring) | More complex (clock synchronization needed) |
| Error Handling | Parity/stop bits | CRC/checksums |
| Examples | UART, RS-232, Bluetooth | SPI, I²C, Ethernet |
When to Use Which?
- Asynchronous: Low-speed, simple devices (sensors, GPS, modems).
- Synchronous: High-speed, multi-device systems (SPI for sensors, I²C for EEPROM).
6. Advantages of Serial I/O Over Parallel
- Longer cable distances: Less signal degradation (e.g., RS-232 supports up to 15m).
- Fewer wires: Reduces cost and complexity (e.g., USB uses 4 wires vs. 8 for parallel).
- Easier interfacing: Standard protocols (UART, RS-232) work across vendors.
- Scalability: Supports daisy-chaining (e.g., I²C buses).
Disadvantage:
- Slower for short distances: Parallel is faster for CPU-memory communication.
7. Worked Example: 8086 Assembly Program for Serial I/O (USART)
Task: Send the string "HELLO" via USART (8251) at 9600 baud, 8N1 (8 data bits, no parity, 1 stop bit).
Steps:
- Initialize 8251:
- Set mode (async, 8N1, baud rate divisor).
- Enable transmitter/receiver.
- Send each character:
- Load data into transmit buffer.
- Wait for transmit buffer empty (TBE) flag.
Assembly Code (8086):
; Assume 8251 base address at 0x80 (simplified)
MOV AL, 0x40 ; Mode command: async, 8N1, divisor=1 (9600 baud)
OUT 0x80, AL ; Send mode command to 8251
MOV AL, 0x0E ; Enable transmitter/receiver
OUT 0x80, AL
; Send "HELLO"
MOV SI, OFFSET STRING
MOV CX, 5 ; 5 characters
NEXT_CHAR:
MOV AL, [SI]
OUT 0x81, AL ; Send to TX buffer
INC SI
LOOP NEXT_CHAR
HLT
STRING DB 'H', 'E', 'L', 'L', 'O'
Real-World Tie-In: eSewa Terminal Serial Communication
eSewa’s payment terminals use USART to communicate with:
- Card readers (Magnetic stripe/EMV chips) via UART.
- Printers (for receipts) via RS-232.
- Central server (for transaction validation) via GSM modem (AT commands over UART).
8. Short Notes (Exam-Friendly Summaries)
a) Asynchronous Serial Data Communication
- No clock signal: Uses start/stop bits for synchronization.
- Baud rate: Must match sender/receiver (e.g., 9600 baud).
- Frame format: Start bit + data + parity + stop bit.
- Example: UART in microcontrollers (Arduino, Raspberry Pi).
b) RS-232 Standard
- Electrical levels: ±3V to ±15V (inverted logic).
- Connectors: DB-25 (full) or DB-9 (simplified).
- Handshake: RTS/CTS for flow control.
- Limitations: Max 15m distance, no built-in error correction.
c) Addressing Modes (Bonus for ALP Questions)
- Direct:
MOV AX, [SI](SI holds address). - Indirect:
MOV AX, [BX](BX holds address). - Register Indirect:
MOV AX, [DI](DI holds address). - Base+Index:
MOV AX, [BX+SI](combines two registers).
In the Real World
eSewa Payment Terminals
- Idea Used: USART (asynchronous serial) for communication between the terminal’s MCU and:
- Card reader (UART at 115200 baud, 8N1).
- Printer (RS-232 for receipt printing).
- Why? Low-cost, reliable serial links for secure transactions.
- Idea Used: USART (asynchronous serial) for communication between the terminal’s MCU and:
Ncell 4G Modems (AT Commands)
- Idea Used: RS-232 serial for AT command-based configuration.
- Example Command:
AT+CGATT=1 ; Attach to GPRS network AT+CMGF=1 ; Set SMS to text mode AT+CMGS="+97798XXXXXXXX" ; Send SMS - Handshake: RTS/CTS ensures the modem processes commands without overflow.
Industrial PLCs (Programmable Logic Controllers)
- Idea Used: Synchronous serial (Modbus RTU) over RS-485 for:
- Remote sensor data collection.
- Motor control signals.
- Why? Long-distance (up to 1.2 km), noise-resistant twisted-pair wiring.
- Idea Used: Synchronous serial (Modbus RTU) over RS-485 for:
Exam Tip
Diagrams Are Mandatory:
- For 8251 USART, draw the block diagram (CPU, control/status registers, buffer, baud generator).
- For RS-232, sketch the DB-9 pinout and label TXD/RXD/RTS/CTS.
- For asynchronous frames, show the start/stop bits + data waveform.
Short Notes = Bullet Points:
- Questions like "Explain RS-232" expect electrical levels + connectors + handshake lines.
- "Advantages of serial I/O" → longer distance, fewer wires, cost.
Assembly Programming:
- If asked to send a string via USART, show:
- Initialization (mode command).
- Loop to send each character.
- Wait for TBE flag (transmit buffer empty).
- If asked to send a string via USART, show:
Real-World Examples:
- Link USART to eSewa terminals or RS-232 to Ncell modems.
- For baud rate calculations, use: (e.g., 1.8432 MHz / 192 = 9600 baud).
Common Pitfalls:
- Forgetting stop bits in async frames (always include 1 or 2).
- Mixing RS-232 levels (remember:
0= +3V to +15V,1= -3V to -15V). - Not waiting for TBE in assembly programs (leads to data loss).
Based on the PU BE Computer (PU) syllabus for Microprocessor, unit 6.
Discussion
Loading…