RS-232 Serial Communication Two computers will be connected via their serial ports so that full-duplex data may be transferred both ways. Low-level serial port driver software must be written for the serial hardware of two PC machines - one at either end of the serial link. Higher level software will be written so that one PC can request a file residing on the other PC's disk. The file will consist mostly of (but not limited to) ASCII characters. The file shall be transferred to the first PC, where it will be stored as a file on its local disk. Both PCs will be running Microsoft DOS operating systems. Serial ports shall be configured for 9600 baud transfer rate. The higher level software must be written to successfully transfer all data despite cable interruptions. An interrupting device will be inserted into the serial lines to evaluate your serial protocol robustness. The data lines of the cable shall be opened at random intervals averaging five percent of the time. Your software shall record (or display) the time from the beginning of the file request, until the file is stored on the disk of the local machine. DOS timing services may be used for this purpose. DOS or BIOS serial services may not be used. DOS or BIOS or compiler library file services may be used to read and/or write files. Speed (given the 9600 baud constraint) is a design goal. To this end, data compression techniques should be investigated. Since the cable connecting the two PC's is unreliable (due to the interrupting device) packet protocols should be implemented. You may use one of a number of packet standards or design your own. You will be evaluated on: •
Successful file transfer with no interruptions
•
Success of file transfer with interruptions
•
Time to successfully transfer the file (with interruptions)
•
User interface
UARTS in the PC Environment The PC machines at each end of the serial link are of different vintage, although both run the same operating system (DOS). Modern PC's include serial hardware as part of a "jungle chip" on the motherboard. A stand-alone UART chip (PC16550D) is register compatible with most of these PC jungle chips. Indeed, the jungle chips were designed specifically to emulate this particular UART, or its predecessors (16450, 8250). How this chip fits into the PC's environment is outlined below. Of particular interest is where its registers fit into the PC's I/O address map, and where its interrupt line fits into the PC's interrupt hierarchy. The clock source for baudrate generation (particularly its frequency) must also be known. Most PC's include two UARTs, each having unique I/O addresses. Each UART is commonly known as COM1 and COM2. You may use either one. I/O Register Address Map for PORT READS
{PRIVATE}Register
COM1 COM2
Receive Buffer Data Register
03F8h
02F8h
Interrupt Enable Register
03F9h
02F9h
Interrupt Identification Register
03FAh
02FAh
Line Control Register
03FBh
02FBh
MODEM Control Register
03FCh
02FCh
Line Status Register
03FDh
02FDh
MODEM Status Register
03FEh
02FEh
Scratch pad Register
03FFh
02FFh
I/O Register Address Map for PORT WRITES {PRIVATE}Register
COM1
COM2
Transmit Holding Register
03F8h
02F8h
Interrupt Enable Register
03F9h
02F9h
FIFO Control Register
03FAh
02FAh
Line Control Register
03FBh
02FBh
MODEM Control Register
03FCh
02FCh
Line Status Register
03FDh
02FDh
MODEM Status Register
03FEh
02FEh
Scratchpad Register
03FFh
02FFh
The 16-bit Divisor Latch registers (associated with UART baud rate) are not often accessed. Your program will have to write to them once to set the baud rate. Here's how to set them: •
Set the most significant bit of the Line Control Register to '1'.
•
Write the least significant byte of the Divisor Latch to port address 03F8h (or 02F8h for COM2)
•
Write the most significant byte of the Divisor Latch to port address 03F9h (or 02F9h for COM2)
•
Reset the most significant bit of the Line Control Register to '0'.
Using UART Interrupts with DOS You may choose to write your UART handling code as interrupts. UART interrupt handlers allow you to do other things (like write to the screen , or to a file) while serial data is coming in or going out. The Borland C language implementation allows interrupt routines to be written, and allows the interrupt vector to be read and written as well. An example is shown in the appendix. Other languages may require that you write interrupt handlers in Assembler. COM1 interrupts on IRQ4 while COM2 interrupts on IRQ3. You may also choose to avoid interrupts by polling UART status registers, but you must take care to poll often enough that no received UART characters are dropped. Calling subroutines to write data to the screen or to a disk file now become risky, if too slow. UART-to-RS-232 interface All UART pins are TTL-compatible, including serial input and serial output lines. These TTL signals must be converted to RS-232 levels between the UART and external rear-panel connector. The MC1488 chip is a quad TTL-to-RS-232 line driver, while the MC1489 chip is a quad RS-232-to-TTL line receiver. All signals on the serial cable outside the PC are NOT TTL levels, but RS-232 levels. Note that these line drivers and receivers are INVERTERS: while the TTL output from the UART is at logic "high", the RS-232 line is at a negative voltage level (space). The rear-panel RS-232 connector on a PC could be either a 9-pin male connector (DB-9), or a 25-pin male connector (DB-25). The PC is wired as a DTE (data-terminal-equipment) device, with the following pin assignments:
{PRIVATE}function
direction
pin# (DB-9)
pin# (DB-25)
Receive Data
in
2
3
Transmit Data
out
3
2
Data Terminal Ready
out
4
20
Data Set Ready
in
6
6
Request to Send
out
7
4
Clear to Send
in
8
5
Carrier Detect
in
1
8
Ring Indicator
in
9
22
Signal Ground
-
5
7
Chassis earth (shield)
-
-
1
Breakout Box To enable troubleshooting the RS-232 link from computer to computer, it is often helpful to see the logic state of the eight RS-232 lines described above. The breakout box shows (via lightemitting-diodes) the logic state of each of these lines. The breakout box is connected in-line, with two DB-9 connectors. All nine RS-232 lines from each side are wired to a proto-board. It is up to you to connect signal lines from one side to the other on the proto-board with wire jumpers, otherwise there is no connection from one DB-9 connector to the other DB-9 connector. There are two sets of LED indicators on each RS-232 line. If neither are lit, the line is opencircuit, and undriven. If the mark LED is lit, the RS-232 line is driven to the low-voltage level ( 10v to 0v). If the space LED is lit, the RS-232 line is driven to the high-voltage level (+2v to +10v). If both mark and space LED's seem lit, the RS-232 line is switching back and forth rapidly. A DC signal at the mark level and a DC signal at the space level are also available on the proto-board. These may be useful to tie various RS-232 control lines high or low. A RS-232 compatible data test output is also available. It is a serial signal source that outputs data at various baud rates between 1200 baud and 19200 baud. At each baud rate, a stream of ascii characters are sent in different formats (7-data, 8-data, no parity, even parity, odd parity). If you send this test signal to either computer on its Receive Data line, much of this data will appear as garbage, because the computer will only recognize proper ascii characters at one baudrate. However, some of the character sequences should make sense. The