Channels ▼

Embedded Systems

Designing a Parallel-to-Serial Port Adapter

Pawan Kumar Janbandhu can be contacted at

Most electronic devices available in market today come with either serial or parallel port which can be interfaced with each other using a PC. A standard PC comes with a parallel port (Standard Parallel Port, SPP /Enhanced Parallel Port, EPP) and Serial ports (USB/RS-232). SPP permits data transfer at the rates of 150kB/sec and is used for printing as well as non-printing purposes like tape-backup systems, DVD drives, and LAN adapters. EPP increases the performance by mainly reducing the software delays and permits speeds as high as 2MB/sec which is roughly 50-100 times faster than SPP allowing bi-directional data transfer over data lines. It is primarily used by non-printer peripherals -- DVD, tape, and hard drives, network adapters, etc. On the other hand, ECP (Enhanced Capability Port) is used for printers, scanners, and the like which provide features such as increased speed, data compression, and so on. The RS-232 interface of the PC is used for serial communication and permits data transfer in the range of 5-10kB/sec and is used in network adapters, serial printers, etc.

In this article, I present the design of an inexpensive and standalone parallel and serial port adapter that enables data transfer between serial port (RS-232) and parallel ports (SPP/EPP) of devices such as PCs and printers. I include both C and assembly programs for testing parallel-to-serial port transmission using the adapter that can be used to implement its device driver.

Interfacing Through Serial and Parallel Ports

Serial communication can be synchronous or asynchronous. In this article, I only address asynchronous communication. In serial mode, a byte is transferred with all its bits transmitted one after another. The speed of serial communication is mainly determined by the baud rate defined which is the number of bits transmitted / received per second. In asynchronous mode, a start bit (usually low) and a stop bit (usually high) is added at the beginning and end respectively of 8 data bits to distinguish between two consecutive bytes. You can further enhance serial communication by adding a parity bit at the end of 8 data bits.

The RS-232 port of PC for serial communication comes as 25-pin and 9-pin adapter in PCs. Only the TxD, RxD, and GND pins of this port are sufficient for serial communication. However, other signals like DSR, RTS, DTR, and CTS can be be used for "hardware handshaking". Handshaking can also be achieved using XON or XOFF characters which is known as "software handshaking". The voltage levels for RS-232 signals can be anywhere between -3V to -15V for a mark (logic high) and +3V to +15V for space (logic low). Voltage levels o f ±12V are more generally used to permit high noise margin. Because of high voltage levels, RS-232 is not TTL compatible. Hence, line drivers or receivers (such as MC 1488 and MC 1489 respectively) are required to interface the serial port with an external device. Alternately, this can be achieved using a circuit like that in Figure 1. This circuit ensures voltage level compatibility for interfacing a TTL compatible device with RS-232 port.

[Click image to view at full size]
Figure 1: Simplified circuit for interfacing external device with RS-232 port

Data can be read or written to the serial port of PC via the IN and OUT instruction on the serial port register (0x2f8/0x3f8). Baud rates on either side of the PC and external interfacing device should be set to same value to ensure correct data transfer. This involves data transfers between devices with IN/OUT data in parallel format; i.e. exchange of whole byte on 8 parallel data lines at a time, rather than bit-by-bit as in case of serial communication. Hence, parallel data transfer is faster than serial communication. Examples of such devices are PCs, printers, drives etc. Parallel communication can be bi-directional, i.e. data can be received as well as transmitted on the same data lines using Enhance Parallel Port (EPP) or unidirectional like Standard Parallel Port (SPP) (data lines are output only) and printers (data can only be received).

Printers having Centronix parallel ports can be interfaced with the parallel port of the PCs for communication. The printer port is TTL compatible. Hence, line drivers and receivers are not required to interface the printer with external peripherals. Proper handshaking is required for interfacing printer's parallel port with external devices such as PC to ensure correct data transfer.

The standard PC parallel port comes as 25-pin female type connector containing 17 active lines and eight ground lines. Unlike RS-232 port, the parallel port of a PC is TTL compatible. The 17 signal lines are divided into eight data, five status, and four control lines. Data that is written to data port appears as active high signals on the corresponding pins of the parallel port connector. The port uses totem-pole drivers; its outputs are actively driven both high and low. Control lines comprise the four least significant bits of the 8-bit control port. They are typically driven by open collector drivers. Control port can be used as both i/p and o/p port. However, using control lines is not as good as input lines as some parallel ports use totem-pole, not the more common open collector drivers on the lines, and other do not sense the actual physical levels on these lines. Status lines comprise of five most significant bits of the 8-bit read only status port. Bit 6 of the status port is also the parallel port interrupt request (IRQ signal). More details can be found in Using Parallel Port Adapter as a Host Interface Port by Dhananjay V. Gadre and in the IBM Technical Reference Library.

Data can be transferred by writing OUT instruction on the data register and can be received in 4-bit nibbles using status port or in 8-bit form by writing IN instructions on both control and status ports. However, these methods are software intensive. The device driver on the PC checks if peripheral is ready by probing Busy line then places outgoing data onto the data lines and generates a Strobe signal on one of the control lines. Similarly, for reading data, the PC reads data on the status lines and control lines (in byte mode) or a nibble on the status lines (in nibble mode) and then generate an Ack signal (acknowledge). Since, this is so software intensive, data transfer rates are limited to between 50 and 150kB/sec.

Using EPP, a data byte can be transferred by a single IN/OUT instruction to the I/O controller which handles the handshaking and strobe signal generations. Thus data transfer rates are limited by the rate at which the instruction can be executed and speeds up to 1-2MB/s can be easily achieved. The EPP protocol defines four data transfer cycles -- data write, data read, address write and address read. Data cycles are used for transferring data to and from peripheral devices while address cycles are used to exchange device address, control information etc. Only 14 of the 17 SPP signals are utilized in EPP mode for data transfer, handshaking and strobe. Data can be transmitted by simply performing OUT instruction to "base_address + 4" where base address is the address where the Data register is located in the PC's I/O space which is 0x378h for LPT1 and 0x278h for LPT2. The EPP controller generates the necessary handshake signals and strobe to transfer the data using an EPP Data Write cycle. Address cycles are generated when read/write I/O operation are generated to "base_address+3". More details can be found in The Enhanced Parallel Printer Port for Fast I/O by Dhananjay V. Gadre and Larry A. Stein.

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags


<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags


<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

