IT236 Microprocessor and Computer Architecture

Microprocessor and Computer ArchitectureUnit 97 min read

Input/Output Interfacing – I/O Basics, Serial & Parallel, Interrupts, DMA, and Real‑World Applications

Unit 9 of Microprocessor and Computer Architecture: covers I/O interfacing concepts, types of I/O devices, communication protocols, interrupt and DMA mechanisms, and practical design considerations.

Key points

  • I/O interfacing connects the microprocessor to external devices through parallel and serial buses.
  • Serial protocols (UART, SPI, I²C) trade bandwidth for simplicity and pin‑count.
  • Interrupts and DMA offload the CPU from continuous polling, improving efficiency.
  • Addressing, port I/O, and control registers determine how data moves between CPU and peripherals.
  • Real‑world systems (eSewa payment terminals, Pathao GPS, Ncell SIM modules) rely on these concepts.

Unit 9: Input/Output Interfacing

9.1 Overview of I/O Interfacing

Input/Output (I/O) interfacing is the bridge that allows a microprocessor to exchange data with the outside world. It is realized through parallel and serial buses, each with distinct characteristics. Parallel buses transmit multiple bits simultaneously over several wires, offering high throughput but consuming many pins. Serial buses transmit one bit at a time over a few wires, trading speed for simplicity and lower pin usage.

Feature Parallel Serial
Pin count High Low
Speed High (simultaneous bits) Lower (bit‑by‑bit)
Complexity Simple timing Requires clock synchronization
Typical use Legacy printers, memory buses UART, SPI, I²C, USB

Parallel I/O is still used in high‑speed memory interfaces (e.g., DDR), while serial I/O dominates modern embedded systems due to its compactness and robustness.

9.2 Types of I/O Devices

I/O devices are classified by their data transfer mode and interface protocol:

Device Interface Typical Use
Keyboard, Mouse PS/2 (parallel), USB (serial) Human‑computer interaction
Display VGA (parallel), HDMI, DisplayPort (serial) Visual output
Storage SATA, IDE (parallel), NVMe (serial) Data persistence
Sensors ADC (parallel), I²C, SPI, UART (serial) Environmental monitoring
Actuators GPIO, PWM (parallel), serial for motor drivers Control systems

9.3 Parallel I/O

Parallel I/O uses a set of data lines, a clock line, and control signals. The classic parallel port (DB‑25) used in printers is a 8‑bit data bus with separate read/write strobe lines. Data is transferred in a single cycle, enabling high throughput.

Worked Example – Parallel Port Data Transfer
A microcontroller writes the byte 0xA5 to a printer:

Step Action Signal
1 Set data lines to 10100101 8 data pins
2 Assert WR (write strobe) low 1 control pin
3 Wait for ACK from printer 1 status pin
4 De‑assert WR 1 control pin

The entire byte is transferred in one clock cycle, but the need for 10 pins (8 data + 2 control) limits scalability.

9.4 Serial I/O

Serial communication transmits data bit‑by‑bit over one or two wires. Three widely used serial protocols are UART, SPI, and I²C.

9.4.1 UART (Universal Asynchronous Receiver/Transmitter)

UART is asynchronous; it does not share a clock line. Each frame starts with a start bit, followed by data bits, optional parity, and stop bits. The baud rate determines the bit duration.

Mermaid State Diagram – UART Transmission

stateDiagram-v2
    [*] --> Idle
    Idle --> Start : Start bit detected
    Start --> Data : 8 data bits transmitted
    Data --> Parity : Parity bit (if enabled)
    Parity --> Stop : Stop bit(s)
    Stop --> Idle : Frame complete

9.4.2 SPI (Serial Peripheral Interface)

SPI is synchronous and uses four lines: MISO (Master In Slave Out), MOSI (Master Out Slave In), SCLK (Serial Clock), and CS (Chip Select). The master generates the clock and selects the slave.

9.4.3 I²C (Inter‑Integrated Circuit)

I²C uses two wires: SCL (clock) and SDA (data). It supports multiple masters and slaves, with each slave identified by a 7‑bit address.

9.5 I/O Control Mechanisms

9.5.1 Polling

The CPU repeatedly checks a status register to see if data is ready. Polling is simple but wastes CPU cycles.

9.5.2 Interrupts

An interrupt signal notifies the CPU that an event has occurred. The CPU saves its context, executes an interrupt service routine (ISR), and resumes normal execution.

Mermaid Flowchart – I/O Interfacing Process

flowchart TD
    A["Start"] --> B["Check I/O type"]
    B -->|"Parallel"| C["Configure parallel pins"]
    B -->|"Serial"| D["Configure serial registers"]
    C --> E["Enable interrupts"]
    D --> E
    E --> F["Wait for interrupt"]
    F --> G["Execute ISR"]
    G --> H["Process data"]
    H --> I["Return to main"]

9.5.3 Direct Memory Access (DMA)

DMA allows peripherals to transfer data directly to/from memory without CPU intervention, freeing the CPU for other tasks.

Feature Polling Interrupt DMA
CPU involvement High Medium Low
Throughput Low Medium High
Complexity Low Medium High

9.6 I/O Addressing and Port I/O

I/O devices are accessed via memory‑mapped I/O or port I/O. In memory‑mapped I/O, device registers occupy specific memory addresses; the CPU uses normal load/store instructions. In port I/O, dedicated instructions (e.g., IN, OUT on x86) access I/O ports.

Example – Memory‑Mapped I/O
A UART data register at address 0x4000_0000:

#define UART_DATA  (*(volatile uint8_t*)0x40000000)
UART_DATA = 0x55;   // Send byte

Example – Port I/O
On x86, port 0x3F8 is the COM1 data register:

mov al, 0x55
out 0x3F8, al

9.7 Practical Design Example: Temperature Sensor Interface

A common embedded application is reading a temperature sensor (e.g., TMP102) via I²C and displaying the value on an LCD.

System Diagram

classDiagram
    class MCU {
        +GPIO
        +I2C
        +LCD
    }
    class TMP102 {
        +TempReg
    }
    class LCD {
        +DataBus
    }
    MCU --> TMP102 : I2C
    MCU --> LCD : Parallel

Step‑by‑Step Trace

  1. MCU initiates I²C start condition.
  2. Sends sensor address 0x48 with R/W=1.
  3. Sensor acknowledges.
  4. MCU reads 16‑bit temperature value.
  5. MCU converts raw value to Celsius.
  6. MCU writes the formatted string to the LCD via parallel port.

Worked Example – Raw Data 0x1A2B

  • Raw value = 0x1A2B = 0001101000101011₂.
  • Temperature (in 0.0625°C units) = 0x1A2B * 0.0625 = 26.8125°C.
  • MCU formats as "26.8°C" and sends to LCD.

9.8 In the Real World

Product I/O Idea Used How It Works
eSewa payment terminal USB 2.0 (serial) The terminal uses a USB controller to transfer transaction data to a host PC, relying on the USB protocol’s packet framing and interrupt transfers.
Pathao GPS module UART The GPS receiver outputs NMEA sentences over UART at 9600 baud; the microcontroller parses the sentences to obtain latitude/longitude.
Ncell SIM module UART The SIM card interface uses AT commands over UART; the module responds with status strings, enabling mobile data and SMS.
NEPSE trading system PCIe (parallel‑like, high‑speed serial) Trading servers use PCIe to exchange market data at gigabit speeds, employing DMA for bulk transfers.

9.9 Exam Tip

  • Understand the difference between parallel and serial I/O: pin count, speed, and typical use cases.
  • Know the frame formats of UART, SPI, and I²C; be able to draw them from memory.
  • Explain interrupt vs. polling vs. DMA: when to use each and their impact on CPU load.
  • Be able to design a simple I/O circuit: choose the appropriate bus, set up control registers, and write a short ISR.
  • Practice tracing data through an I²C transaction or UART frame to reinforce timing and bit ordering.

Real‑World Images


Figure – UART, SPI, and I²C Frame Formats

Based on the TU BIM syllabus for Microprocessor and Computer Architecture (IT236), unit 9.

Discussion

Loading…