22.2 Serial Ports
PC serial ports, also known as communications ports, comm ports, asynchronous ports, or async ports, connect slow bit-oriented peripherals like modems, mice, printers, and plotters to the fast, byte-oriented system bus. Serial ports may reside on motherboards or expansion cards, or be embedded on devices like internal modems. PC serial ports haven't changed much over the years, although they're faster now and have larger buffers.
Serial ports were formerly used to connect almost anything to a PC modems, mice, printers, plotters, etc. Nowadays, serial ports are used mostly to connect modems and other peripherals (like the Palm cradle) that do not require high- speed communications. Although serial ports are obsolescent and will eventually be replaced by USB ports, nearly any motherboard or PC you buy today will have one or two serial ports, although one or both may exist only as a group of header pins on the motherboard, rather than as visible ports on the rear panel connector. For now at least, the serial port is sometimes the best (or only) way to get the job done. The following sections describe what you need to know to use serial ports effectively.
22.2.1 Serial Port Standards
Because they transfer only one bit at a time, using serial communications interfaces to establish a unidirectional connection between two devices in theory requires only one data circuit. This circuit comprises one data (or signal) wire and a second wire (called the ground, return, or common) that completes the electrical circuit. In practice, most PC serial communications devices use additional wires to enable bidirectional communication, to provide control circuits between the devices, and so on.
Serial port interface and signaling specifications are defined by the Electronic Industries Association (EIA) standard Interface Between Data Terminal Equipment and Data Communication Equipment Employing Serial Binary Data Interchange, Revision D. This standard is properly abbreviated EIA-232D, but is usually called RS-232C, for the earlier and nearly identical revision C. The ITU (formerly CCITT) defines essentially identical standards as V.24 (interface) and V.28 (signaling).
188.8.131.52 DB25 Pin Definitions
EIA-232D defines pin assignments, but does not specify physical connectors. In the PC environment at least, a well-established defacto standard does exist for 25-pin serial connections. By convention, DTE devices (e.g., PC serial ports) use a 25-pin male D-sub plug connector, designated DB25M. DCE devices (e.g., modems) use a 25-hole DB25F female socket connector. There are exceptions. For example, some serial printers are DTE devices but use a DB25F connector. Figure 22-1 shows a DB25 connector.
Figure 22-1. A DB25 connector
Table 22-1 lists DB25 pin assignments. The column headings are self-explanatory, except the following:
EIA-232D maps circuits, all of which are named from the point of view of the DTE device, to pin numbers. Placing a voltage signal on a circuit is called asserting or raising that circuit. For example, placing voltage on pin 20 asserts (or raises) DTR. Although you probably don't need to understand these signals in detail, knowing something about their purposes will help you choose the right cable and troubleshoot connection problems. The signals asserted on the EIA-232D pins and pin pairs commonly used in PC serial communications have the following purposes:
PCs commonly use nine of the preceding ten pins and signals (excluding pin 1, GND). Pins 12 through 17, 19, 21, 23, and 24 are not used for standard PC serial connections, but may be used in nonstandard ways by proprietary serial devices. Most commercial DB25 serial cables are labeled as "9-wire," "10-wire," or "25-wire." The first connects only the most commonly used pins. The second also connects GND. The third connects all 25 pins.
184.108.40.206 DB9 Pin Definitions
When IBM introduced the PC/AT in 1984, it used a nonstandard DB9M 9-pin serial connector that included only the commonly used pins. Because this connector is physically smaller, it allowed putting both a serial port and a DB25F parallel port on the same expansion card bracket. The market presence of IBM and the passage of years have combined to make this DB9M serial connector a defacto standard. Like the DB25, DB9 connectors are available in male and female versions, designated DB9M and DB9F respectively. By convention, DTE devices use the DB9M. Few DCE devices use DB9 connectors. However, those that do usually use a DB9F. Figure 22-2 shows a DB9 connector.
Figure 22-2. A DB9 connector
Although its pinouts don't map to either DTE or DCE, the DB9M serial connector is considered an "honorary" DTE device, with DTE-to-DCE interfacing accommodated by the cable. The DB9 connector includes the nine important signals, but the pinouts differ from DB25, as Table 22-2 shows.
22.2.2 Universal Asynchronous Receiver-Transmitter (UART)
The Universal Asynchronous Receiver-Transmitter (UART) is the heart of a serial port. When transmitting, the UART receives the outbound byte stream from the system bus, converts the bytes into a bit stream, and places the bits onto the serial interface. When receiving, the UART receives an inbound bit stream from the serial interface, buffers the inbound bits, assembles them into bytes, and places those bytes onto the system bus.
It's important to have the right UART, because that determines how fast serial connections can run, particularly with multitasking operating systems like Windows 9X and NT/2000/XP. For best performance, determine which UART you have, and replace it if necessary. You may have any of the following UARTs:
220.127.116.11 Determining UART Type
Under DOS and Windows 9X, you can determine the UART type with Microsoft Diagnostics (MSD.EXE), with a general-purpose diagnostic utility such as SiSoft Sandra, or with a dedicated port diagnostics program such as PortMaster. Either of the latter two utilities can be downloaded from any of numerous Internet sites.
Figure 22-3 shows SiSoft Sandra displaying information about COM1 on an AMD Duron system, built on a Microstar motherboard that uses a VIA KT133 chipset, and running Windows 98. Sandra reports that COM1 uses a National Semiconductor 16550AN UART, which is not precisely true. The COM1 UART is actually just one of the functions provided by the Super I/O portion of the Southbridge of the VIA chipset. The UART is emulated rather than physically present, but as far as Windows and connected serial devices are concerned, this system might just as well have a real physical 16550AN UART.
Figure 22-3. Using SiSoft Sandra Ports Information to view serial port configuration on a Windows 98 system
Utilities that run under Windows NT/2000/XP are limited in the amount and accuracy of the information they can provide, because Windows masks the underlying hardware from the utility. For example, Figure 22-4 shows the results of running SiSoft Sandra Ports Information on a system running Windows NT 4. The Windows NT Hardware Abstraction Layer (HAL) prevents user-mode applications (like Sandra) from accessing the underlying hardware, so Sandra can report only what NT sees fit to tell it, which is often little or nothing.
Figure 22-4. Using SiSoft Sandra Ports Information to view serial port configuration on a Windows NT 4 system
If your system boots Windows NT 4 or Windows 2000/XP, the only way to obtain detailed information about the hardware is to boot DOS and run a DOS-mode diagnostic utility. You can use either a comprehensive commercial diagnostics program like CheckIt for that purpose, or a dedicated small utility such as PortMaster.
If the device has not yet been installed in the computer (or if you're willing to pop the lid), you can sometimes determine the UART type by examining the chips on the device to locate a UART number. However, many devices use VLSI/ASIC components rather than discrete UART chips, making it difficult or impossible to identify the UART type visually. In these cases, if you don't have the documentation, the only convenient way to determine the UART type may be to install the board, boot DOS, and run a diagnostics program.
Some "enhanced" VLSI/ASIC-based 16450 serial ports with FIFO buffering added may falsely report themselves to the operating system and applications as 16550s, although PortMaster usually detects them properly. These UARTs are commonly found on early 486 motherboards and "high-speed" serial cards designed for 486 systems. These bumped-up 16450s may or may not function properly with any particular combination of operating system and application, and should be replaced with a serial port that uses a 16550AFN or higher UART.
18.104.22.168 Choosing UART Type
Which UART you need to use for maximum throughput depends on three factors:
After you determine the UART types used by your serial ports, use the following guidelines to decide if these ports are adequate for their intended purpose:
22.2.3 Resources Required by Serial Ports
Each standard serial port requires an IRQ and an I/O port. The serial port generates an interrupt on its assigned IRQ to get the processor's attention when it has data to transfer. The I/O port is a range of addresses, named for the first address in the range, that defines a "scratchpad" area that the serial port uses to exchange data with the computer. For example, I/O Port 0x3F8 includes the address range 0x3F8 through 0x3FF.
Serial ports are named COM[xxx]:, where [xxx] may be a number from 1 through 256. Although the serial port name technically includes the trailing colon, the colon is usually dropped for convenience, and that is the practice we follow. IBM originally defined only COM1 and COM2 for the PC BIOS, although they later defined standard values for COM3 and COM4 as well. Table 22-3 lists the standard COM port assignments for ISA/PCI systems. (Systems that use the EISA or MCA bus use additional COM ports with different settings, but these systems are obsolete and immaterial.) The values for COM1 and COM2 are invariant due to long usage. The values for COM3 and COM4 are semi-standard, but may differ on some systems.
Note that ports 1 and 3 and ports 2 and 4 share an IRQ. Although EISA and MCA systems permit IRQs to be shared gracefully, ISA/PCI systems do not. This means that, in effect, you can use only two serial ports safely on a system that uses standard COM port assignments. You may be able to get away with such sharing say by putting a serial printer on COM3 and a mouse on COM1 but you must make sure never to use both devices that share one IRQ at the same time.
Windows 95 went a long way toward solving this problem by adding support for up to 128 COM ports. Windows NT 4.0 goes further still, supporting up to 256 COM ports and allowing you to define custom values for IRQ and base address for each installed COM port. Because Windows applications use COM ports by name and are not concerned with underlying settings, it is relatively straight-forward to support multiple COM ports in the Windows environment.
A final note: PCs assign a priority to each IRQ, and process interrupts on the higher priority IRQ first. The highest priority IRQ is 0, followed by 1, 2/9, 10 through 15, and then 3 through 8. Put high-priority devices like modems on a high-priority serial port (e.g., COM2/IRQ3) and low-priority devices like mice on a lower priority serial port (e.g., COM1/IRQ4). This is less important with recent UARTs than it used to be, but is still worth doing as a matter of good practice.
22.2.4 Enhanced Serial Ports
The proliferation of high-speed external serial devices, notably serial ISDN terminal adapters, made it obvious that something faster than the standard 16550 UART was needed. The standard serial ports on most PCs top out at 115 Kbps or (rarely) 230 Kbps. That's not fast enough to support the full throughput of a dual B-channel ISDN terminal adapter, which operates at 128 Kbps natively, and up to four times that fast when data compression is enabled.
To address that need, various manufacturers supply enhanced serial ports, which are add-on cards that include one or two serial ports. These use 16650 or 16750 UARTs, which are essentially 16550 UARTs with additional buffering added. Some cards also include an embedded processor, typically an 80186 or 80286, which offloads interrupt handling from the main processor.
These adapters are overkill for normal serial port applications, may provide some benefit for 56K dial-up modems, and often provide a noticeable performance increase for ISDN applications. If you buy such a card, make sure that it includes any necessary drivers for your operating system.
22.2.5 Multiport Serial Adapters
Each standard serial port occupies one IRQ, which limits how many standard serial ports can be installed. Most computers need one or two serial ports at most, so this is seldom a problem. But there are applications such as running a terminal server under Linux where it is desirable to have 8, 16, or more serial ports available. That's clearly impossible if each serial port requires one IRQ. The solution is a special board called a multiport serial adapter.
These adapters are available in ISA and PCI form, and are installed in the PC just like any other expansion card. They provide from 4 to 32 serial ports using only one IRQ. The serial port connectors reside in a separate external box that connects to the multiport serial adapter via multiple 8P8C ("RJ-45") connectors or a single proprietary octopus cable with many conductors.
Such adapters are available in two forms: "dumb" multiport serial adapters are little more than a collection of UARTs and connectors, use 8-bit transfers, generate an interrupt for each byte transferred, and depend on the host PC for processing power. "Smart" multiport serial adapters include a microprocessor (typically an 80286 or 386) that offloads serial interrupt processing tasks from the host PC. Smart adapters usually buffer 1KB of data or more between transfers, greatly reducing the interrupt burden on the host system. Nowadays, most multiport serial adapters are of the smart variety.
Dumb terminals have become rare in most applications LAN connected PC clients are much more common nowadays, even on Linux systems and so the need for multiport serial adapters is much less than formerly. If you do need one, for example for process control, automation tasks, or building a terminal server for a modem pool, make sure that drivers are available for your operating system.