The Role of the Z80 SIO
The Z80 SIO (Serial Input/Output) chip is a sophisticated peripheral that acts as a dual-channel UART (Universal Asynchronous Receiver/Transmitter). It handles all the complex timing, start/stop bit generation, and error checking for serial communication entirely in hardware.
Advantage: The SIO makes robust serial communication (like RS-232, modem, or network) fast and reliable, saving the Z80 CPU thousands of cycles compared to software bit-banging (Part 40).
SIO Communication Ports
The SIO chip provides two independent serial channels (A and B), each with its own Data and Control ports, typically occupying four consecutive I/O port addresses:
Channel | Port Type | Function |
---|---|---|
A | Data Port | Transfers data bytes (Read/Write). |
A | Control Port | Writes commands and reads status/errors. |
B | Data Port | Transfers data bytes (Read/Write). |
B | Control Port | Writes commands and reads status/errors. |
Initialization: Setting the Baud Rate
To initialize an SIO channel, the Z80 must write several Control Words to the Control Port. These words configure the channel’s operation, including the data format and the communication speed.
Key Configuration Steps:
- Reset: Issue a global reset command to clear the chip.
- Baud Rate: Configure the internal clock logic to match the desired Baud Rate (e.g., 9600 bps).
- Data Format: Set the number of Data Bits (e.g., 8), Stop Bits (e.g., 1), and Parity (e.g., None).
- Interrupts: Enable the receiver and transmitter interrupts.
Example: Writing Control Words (Conceptual)
SIO_PORT_A_CONTROL EQU 41H
INIT_SIO:
; Write 1: Reset the channel (Specific command sequence)
LD A, 18H ; Example: Master Reset Command
OUT (SIO_PORT_A_CONTROL), A
; Write 2: Set Baud Rate and Data Format
LD A, 4EH ; Example: Command to set 8 data bits, 1 stop bit
OUT (SIO_PORT_A_CONTROL), A
RET
`ü};
## Data Transfer and Interrupts
Once initialized, the SIO takes over the transfer logic entirely. The Z80 only needs to check two key registers:
1. **Status Register:** A read from the Control Port returns a status byte containing flags (e.g., **RxRDY** = Receiver Ready, **TxRDY** = Transmitter Ready).
2. **Interrupts:** The SIO generates interrupts when a byte is fully **received** or when the transmitter is **ready** to accept the next byte. This is the most efficient method for transfer.
**Efficient Transmission Loop (Interrupt-Driven):**
The Z80 main loop simply processes other tasks. When the SIO is ready for the next byte, it generates an interrupt, the CPU executes the **Transmit ISR** (which loads the next byte from a transmit buffer), and returns. The main CPU is never stalled waiting for the slow serial process.