David P. Goldenberg
December 2002
This document is the result of my own attempts to understand the intricacies of serial port connections, especially in the context of interfacing Macintosh computers with spectrophotometers. A Macintosh application written for this purpose, MacSpec II, is available at the Goldenberg Lab web page, and the documentation provided with the program includes instructions for making connections to the currently supported spectrophotometers. This additional documentation is intended for those who might want to interface another instrument with a Macintosh or, for some other reason, would like to know more about this arcane subject.
The serial connection is one of the oldest bits of computer technology that is still with us. It was originally designed to connect computers or terminals to modems, but it has also been used to connect computers to each other, to printers and to a variety of peripheral devices including scientific instruments. The good thing about a serial connection is that it is relatively easy to write software to transmit data over it. The worst, probably, is the fact that it is one of the least standardized standards in the computer industry. Different connectors are used, and, even worse, different equipment manufacturers have different ideas about how the connector pins should be wired! Finding a cable with the right kind of connector at each end is no guarantee that it will work. The serial connection is also relatively slow by modern standards, but that is not at all a problem for this application.
To the extent that they follow any standard, most instrument manufacturers will specify that the serial port is an ``RS-232'' connection. None of the current Macintoshes have have serial ports, but there are adaptors that allow serial devices to be connected via the USB port found on the newer machines. These, and the serial ports found on older Macs, are not actually RS-232 connections, but are RS-422 ports, and use the small circular DIN-8 plug. Fortunately, the two standards are similar enough that it is usually possible to get the Mac to talk to an RS-232 device, though it may take some trial and error and some soldering.
If the manufacturer says that the instrument is wired as a "DTE" device, try using the hardware handshake cable along with a device called a "null modem adaptor". This is a small box with DB25 connectors on each end with internal wiring that crosses some of the pins, as described below. Again, you may also need a DB25-DB9 adaptor or a gender changer.
If the manufacturer doesn't say whether the device is DCE or DTE, go ahead and try the connections described above. One of them may well work, and you will never need to know what DCE and DTE mean! This, in fact, worked for the first two spectrophotometers we tried.
Experimenting with the serial port should be relatively safe for both the computer and the instrument, provided that you don't leave any incorrect connections for more than a few minutes. The RS-232 standard specifies that any of the pins should tolerate connection to any other pin, including a connection to the maximum voltage (15 V) or a direct short to ground. Incorrect connections can cause large current loads on the drivers, however, which can generate a lot of heat and burn something out. It is also possible that you could expose the circuits to a static discharge at a much higher voltage. Please read the disclaimer again!)
A web page with Macintosh-specific information on serial port connections is maintained by Charles B. Cranston:
http://www.wam.umd.edu/~zben/mac/MacSerHard.html
For several years, another excellent web page dedicated to Macintosh serial port connections was maintained by Jim Conners. Unfortunately, the page disappeared without a trace, but Francis Courtois has archived it and posted it on his own web site:
http://francis.courtois.free.fr/jc1/serial/main.htmlThis web site is especially useful if you need to work out a serial connection by direct testing.
Though they do not deal with Macintosh-specific issues, I have found the following two pages on RS-232 connections very useful:
From CAMI Research, Inc.:
http://www.camiresearch.com/Data_Com_Basics/RS232_standard.htmlFrom Lammert Bies:
http://www.lammertbies.nl/comm/info/RS-232.html
There are also several books devoted to serial connections. A particularly popular one that I found helpful is:
"The RS-232 Connection" by Joe Campbell and published by SYBEX, Inc.Like Jim Conners' web page, this book emphasizes the experimental approach to working out a serial connection. The book is out of print, but used copies seem to be readily available on the internet.
In order to understand the very confusing terminology and wiring conventions associated with serial port connections, it may be helpful to start with a bit of background. The RS-232 standard was originally intended to be used for a quite specific purpose, communication between computers or terminals and communications devices (like modems), which would then be connected by some other means (e.g. a telephone line) with another communications device. A typical arrangement might look like:
The computer or terminal is described as "data terminal equipment" (DTE) and the modem is "data communications equipment" (DCE). Much of the confusion over serial connections comes from the fact that RS-232 has been used for lots of things that don't really fall into either the DTE or DCE class, like spectrophotometers or other instruments. Some manufacturers treat the instrument as a DTE and others as DCE.
The original RS-232 standard specified that the cable should have 25 conductors, but did not specify the mechanical connectors. Later versions specified the DB-25 connector, which has 25 pins in two rows, numbered as shown below (as viewed from the male connector):
Of the 25 pins, 22 have assigned functions in the official specification. But, most of these are very rarely used in modern equipment. The pins that are commonly used are:
|
|
| |||
| 1 | Cable ground (shield) | - | |||
| 2 | Transmit data | TX | |||
| 3 | Receive data | RX | |||
| 4 | Request to send | RTS | |||
| 5 | Clear to send | CTS | |||
| 6 | DCE ready | DSR | |||
| 7 | Signal ground | GND | |||
| 8 | Carrier detect | CD | |||
| 20 | Data terminal ready | DTR | |||
| 22 | Ring indicator | RI |
The other connector that is commonly used for serial connections is the DB9, a smaller version with only 9 pins. The standard RS-232 connections on the pins of a DB9 connector are shown below. For the rest of this discussion, though, we will refer to the DB25 pins to avoid at least one source of confusion.
There are two very important (and seemingly contradictory) conventions to keep in mind:
With those things in mind, we can consider what the different wires in the cable do. The three most important wires (pins) are:
All of the other pins have roles in "hardware handshaking", i.e. allowing the two devices to tell each other when it is OK to transfer data. Two of these carryout an exchange of information:
Two additional pins are used to convey the status of the DCE and DTE to one another without being asked:
The last two pins listed in the table above are intended to carry information that is specific to a modem connection:
Although the manufacturers of an instrument may say that it has an RS-232 port, it is quite likely that it won't use all of the handshaking connections, and it may use them in a non-standard way. This is often the most confusing part of establishing a connection.
In the above discussion, the nature of the signals sent between the devices was left rather vague. The most obvious convention would be that a positive voltage (relative to the ground wire) indicates a logical "true" on a handshaking connection and a binary 1 on a data line (TX or RX). As it happens, the first of these is true and the second isn't.
For both data and handshaking, there are two states defined by positive or negative voltages. In this context, a transmitted positive signal should have a voltage between +5 and +15 V and a negative signal should lie between -5 and -15 V. The signal is undefined if it lies between -5 and +5 V, which shouldn't happen. At the receiving end, the signal will be interpreted as being positive if it lies between +3 and +15 V and negative if it lies between -3 and -15 V. The extra range on the receiving end is meant to provide some tolerance to noise.
For data transmission, a positive voltage is used to indicate a binary 0, and a negative voltage indicates binary 1. The negative voltage is also referred to as a "MARK" and the positive voltage as a "SPACE", terminology that has its origins in telegraph and teletype communications. When the transmit line (TX) is in a resting state, the RS-232 standard specifies that it should have a negative voltage. The receiving pin (RX) should have a zero or slightly positive voltage if it is not connected to another device. This information can be used to determine whether a device is DTE (negative voltage on Pin 2) or DCE (negative voltage on Pin 3).
For the handshaking signals, the convention is reversed: A positive voltage means that the signal is on or "asserted".
In the simplest null cable, the two DB25 connectors are wired to connect two DTE devices (A and B) as follows:
If the devices require the handshaking signals, they can sometimes be tricked by using a more elaborate connection, called a "loop back" cable:
The most elaborate, and probably most common, null cable is connected like this:
In addition to cables wired as described above, there are also small adaptors that can be added to a standard cable to cross the connections. These generally seem to be wired for full handshaking, as in the last example
Unfortunately, the variety of cable connections used to connect serial devices extends way beyond these examples.
The next thing to come to terms with is the fact that the serial connections on a Macintosh are not RS-232 connections. Instead, they are RS-422 connections. The major difference between the two standards lies in the way that the data signals are encoded electrically. As discussed earlier, the RS-232 signals are expressed as voltages (positive or negative) relative to the ground wire (Pin 7 in a DB25 connector). Thus, one wire is needed for TX and one for RX. For RS-422, TX and RX each get two wires, and the signals are expressed as a voltage difference (positive or negative) between these two wires, rather than a voltage relative to a common ground wire. This arrangement is called a "balanced differential" line and can potentially carry data over longer distances and at higher rates than an unbalanced line as used for RS-232. Some RS-422 connections do not include hardware handshaking, but the Macintosh implementation has three pins for this purpose.
Except for the very earliest models, Macs use a small circular connector, the DIN-8, for their serial connections. The male connector (on the cable) looks like this:
There are three handshaking pins: HSKo, HSKi and GPi. The lower case o and i in the designations indicate whether the pins are outputs or inputs, respectively, for the computer.
The way in which Apple intended for the various pins to be used in conjunction with an RS-232 device can be deduced from their specification for a cable to connect the Mac to a modem, i.e. to a DCE device.
For the modem connection, the handshaking works as follows: Before the DCE modem can receive signals, it needs positive signals on its RTS and DTR pins, which are provided by the HSKo pin of the computer. The modem can signal the computer that it is ready to receive by sending a signal from its CTS and CD pins to the computer's HSKi and GPi pins, respectively. Notice that the DSR pin of the modem is not used.
The software on the computer, of course, has to use the handshaking pins appropriately. Most Mac serial port software, including terminal emulators and MacSpec II, has options to turn on and off "CTS" and "DTR" handshaking, either together or independently. According to Jim Conners, CTS and DTR correspond to the HSKi and HSKo pins, respectively, which is how they are connected in the standard cable illustrated above. When CTS is activated, the Mac monitors the HSKi pin and sends data only when it has a positive voltage. When, DTR is activated, the computer will set the voltage on its HSKo pin positive when it is ready to receive data. Hopefully, the peripheral is checking this voltage so that it will send data only when it is positive. Apparently, the GPi pin is not monitored by most software.
So far, we have managed to make MacSpec II work with three spectrophotometers: The Spectronic 2001, the Pharmacia-LKB Ultrospec III and the Spectronic Genesys 8. This required incorporating the command set for each spectrophotometer into the MacSpec code and establishing a hardware connection. The hardware connections and their rationales are described here, in order of increasing complexity.
This spectrophotometer has a DB25 connector, and the manufacturer provided the following information:
|
|
| |||
| 1 | Shield | Cable Shielding | |||
| 2 | Receive Data | Data from computer | |||
| 3 | Transmit Data | Data to computer | |||
| 4 | Clear to send | Hand shake from computer | |||
| 5 | Ready to send | Handshake to computer | |||
| 6 | Data terminal ready | Handshake to computer | |||
| 7 | Ground | Ground |
The "Function" column in this table is especially helpful, because it explains what is really going on. Since data is being received from the computer on Pin 2 and sent to the computer on Pin 3, this must be a DCE device. (See above.) In this case, using the standard hardware handshaking cable works perfectly. With this cable, the handshaking signal from the HSKo pin of the computer goes to Pin 4 of the spectrophotometer (as well as Pin 20, which apparently isn't used), and the handshake signal from Pin 5 of the spectrophotometer goes to the HSKi pin of the computer. The signal from Pin 6 of the spectrophotometer isn't connected to the computer at all, but this signal is presumably redundant.
Notice that the labels given in the "Signal Title" column don't actually follow the usual convention of defining the functions in terms of the DTE device. Instead, the manufacturer defines them in terms of the spectrophotometer, which makes sense if this what you expect . . .
This instrument also uses a DB25 connector and comes with the following information:
|
|
| |||
| 1 | GND | Chassis ground | |||
| 2 | Transmit Data | Data out from 1001 | |||
| 3 | Receive Data | Data in from external device | |||
| 4 | Request to Send | 1001 Supplies ±12V | |||
| 5 | Clear to Send | Requires ±3 to ±25 V from external device | |||
| 6 | Data Set Ready | Requires ±3 to ±25 V from external device | |||
| 7 | Signal/Ground | Return for data and control signals | |||
| 20 | Data Terminal Ready | 1001 Supplies ±12V when power on |
This matches the specification for a DTE device, except for Pin 8 which would normally be used for the carrier detect signal from a modem. A simple test showed that the hardware handshaking cable connected to a null modem adaptor gives a working connection. This combination leads to the following connections between the Mac and the spectrophotometer:
|
|
|
| ||||
| 1 | HSKo | 5, 6, 8 | CTS,DSR | ||||
| 2 | HSKi | 4 | RTS | ||||
| 3 | TxD- | 3 | RX | ||||
| 4 | GND | 7 | GND | ||||
| 5 | RxD- | 2 | TX | ||||
| 6 | TxD+ | none | none | ||||
| 7 | GPi | 20 | DTR | ||||
| 8 | RxD+ | 7 | GND |
Thus, the HSKo signal from the Mac satisfies the spectrophotometers requirements for handshaking signals on on pins 5 and 6, and the signals from Pins 4 and 20 of the spectrophotometer are fed to the HSKi and GPi pins of the Mac. (Likely, the signal on the GPi pin is ignored.)
The hardware interface for this instrument proved more difficult to decode than the others. (In fact, this is the instrument that drove me to try to understand all of this stuff!) The manufacturer was not able to provide a list of the pin functions, but does specify a cable for connecting the instrument to a PC. The spectrophotometer uses a DB9 connection, and the cable has DB9 connectors at each end. But for consistency with the discussion above, I have "translated" the DB9 connections to the equivalent DB25 pins. The DB25 equivalent of the specified cable is shown below:
The confusing part of this connection involves Pins 4 and 8 on each side. It isn't entirely clear why these two pins are connected on each side. It may be that they only have to be connected on one side and that the designer connected them on both sides simply to make the cable symmetrical, so that it could be used in either orientation. On the computer side, it is possible that the designer wants to make sure that Pin 8 (CD) gets a signal whenever Pin 4 (RTS) is activated. That Pin 4 on the computer is an output also implies that Pin 6 on the spectrophotometer is an input. Shifting to the pins that are connected together on the spectrophotometer side (4 and 8), these are also connected to the DSR pin on the computer, an input. Thus, it seems likely that 4 or 8 on the spectrophotometer is an output, with the other pin being an input that is to be activated by the spectrophotometer itself. But, as noted above, the two pins might be just connected together for symmetry, and one may not be used at all. To summarize, we can deduce the following about the functions of the pins on the spectrophotometer:
|
| ||
| 2 | Transmit data to computer | ||
| 3 | Receive data from computer | ||
| 4 | Input, output or possibly null | ||
| 5 | Input from computer | ||
| 6 | Input from computer | ||
| 7 | Signal ground | ||
| 8 | Input, output or possibly null | ||
| 20 | Output to computer |
To make and test connections between this spectrophotometer and a Mac, I used the following pieces of hardware:
After all of this is connected together, the easiest way to think about it is to consider the two sides of the jumper box as extensions of the pins on the computer and spectrophotometer. With the numbers representing the DB25 connectors on the jumper box, what we know about the two sides can be summarized as:
Unfortunately, this set of connections didn't work reliably. However, adding one more jumper to the adaptor, connecting Pin 8 on one side to Pin 8 on the other, did the trick. The final adaptor is wired like this:
Often, on both computers and peripherals, the DB25 connector is replaced with a 9-pin connector, the DB9. The pins on this connector are labeled as shown below (as viewed from the male connector):
|
|
| |||
| 1 | CD | 8 | |||
| 2 | RX | 3 | |||
| 3 | TX | 2 | |||
| 4 | DTR | 20 | |||
| 5 | GND | 7 | |||
| 6 | DSR | 6 | |||
| 7 | RTS | 4 | |||
| 8 | CTS | 5 | |||
| 9 | RI | 22 |
David P. Goldenberg
Department of Biology
University of Utah
257 South 1400 East
Salt Lake City, UT 84112-0840goldenberg@biology.utah.edu