Electronics » the v3 Z80 project » serial comms
Originally I was using a couple of parallel port bits to transfer data serially
to and from the from the Z80 project. This meant I had to use a custom data
server program I'd written which only worked reliably in DOS (cus I could switch
the PC's interrupts off, essential for accurate timing). What I really needed was a Windows app using a standard RS232 serial connection. This required two things: a) A small interface circuit to convert the RS232 voltages to 5 volt logic and b) A serial file transfer program.
The interface:
The interface circuit was quite simple - I used a MAX232 IC to convert the RS232
signal levels and a PIC16F627 to buffer and relay the data. The PIC wasn't absolutely
necessary but as it has a UART built in, it saved me worrying about exact timing at
the Z80 end. Useful, as even with this new RS232 serial system, the Z80 project is
still sending and receiving data via its simple 9-pin Atari 2600 style joystick port
(no interrupts, its a simple CPU hogging affair to send and receive. I could've tried
to implement my own hardware UART in the main Z80-facing CPLD but.. well, didn't..:)
The joystick port has 6 input lines.. Normally these are for the 4
directions and two fire buttons but here 4 inputs are used to receive
a byte from the PIC in two 4-bit chunks. One more bit is used for a clock
signal and the other input is for flow control between the PIC and the
Z80 project (tells Z80 side not to send any more bytes until this current
one is passed on). The clock is a DDR type arrangement, the first part
of the byte is presented to the 4 inputs when the clock goes high, the
second part on clock going low.
When sending data to the PIC (for relaying on to the PC) data is sent
using two spare pins (clock and data) in the 9-pin joystick connector
(which are configured as open collector port ouputs on the Z80 project's
PCB). The PIC s/w arranges the bits received into the original byte
before putting it into its internal serial-out h/w register for
transmission to the PC.
Note: I haven't used any actual RS232 hardware flow control on the PIC-to-PC
side, its just a 3 wire "TX, RX and Gnd" connection.
PIC software:
The PIC software is very simple. It waits for either of two conditions:
a) Its internal h/w register has received a data byte from the PC side.
b) The Z80 side wants to transmit a byte.
In the case of a) the PIC clocks out the byte from the PIC's hardware
serial input buffer to the Z80 side in two chunks as mentioned above..
This happens sooner than two sucessive bytes can be received at the fastest
allowable baud speed (so there is no need for flow control this direction.)
In the case of b) the PIC sets the wait (flow control) line, listens for 8
serial bits from the Z80, puts the byte into its hardware-out register,
sets it to transmit, waits for it to be sent then clears the wait line.
Transmission speed:
The Z80 side does not need to know the RS232 baud rate (the Z80 communicates
with the PIC as quickly as it can/is reliable). The PIC and PC side
software must agree on the baud rate. The system is set up to work
from 9600 to 56700 baud (the PIC PCB has jumpers to set the speed).
PC Software:
I was able to test the circuit and Z80 side software by using HyperTerminal in Windows. HyperTerminal also allows files to be sent using protocols like X-modem, Z-modem etc but when I looked deeper into these, they all turned out to be either too restrictive (X-modem's 128 byte "granularity") or overkill (Z-modem's compression etc). I decided I needed to write my own file transfer program.. The problem was finding a way to access the serial port easily - AFAIK modern Windows variants do not allow direct low-level access to the hardware ports, so a simple DOS program was out. Fortunately I'd recently been looking at Pure Basic (a great straightforward version of BASIC, which makes nice small executables). It doesn't feature any COM port instructions natively but it does accept 3rd party extensions and
Marc Vitry has written a serial port library (called MVCOM) - exactly what I needed! With it I was able to make a small util to send and receive binary data from the Z80 Project over a true serial link.
Source code
My Z80, PIC and PC (Purebasic) source code can be downloaded here.
|