# Serial Programming/MAX232 Driver Receiver

Serial Programming: Introduction and OSI Network Model -- RS-232 Wiring and Connections -- Typical RS232 Hardware Configuration -- 8250 UART -- DOS -- MAX232 Driver/Receiver Family -- TAPI Communications In Windows -- Linux and Unix -- Java -- Hayes-compatible Modems and AT Commands -- Universal Serial Bus (USB) -- Forming Data Packets -- Error Correction Methods -- Two Way Communication -- Packet Recovery Methods -- Serial Data Networks -- Practical Application Development -- IP Over Serial Connections

## Applicability

This module is primary of interest for people building their own electronics with an RS-232 interface. Off-the-shelf computers with RS-232 interfaces already contain the necessary electronics, and there is no need to add the circuitry as described here.

## Introduction
### Logic Signal Voltage

Serial RS-232 (V.24) communication works with voltages (between -15 V ... -3 V are used to transmit a binary '1' and +3 V ... +15 V to transmit a binary '0') which are not compatible with today's computer logic voltages. On the other hand, classic TTL computer logic operates between 0 V ... +5 V (roughly 0 V ... +0.8 V referred to as low for binary '0', +2 V ... +5 V for high binary '1' ). Modern low-power logic operates in the range of 0 V ... +3.3 V or even lower.
So, the maximum RS-232 signal levels are far too high for today's computer logic electronics, and the negative RS-232 voltage can't be generated at all by the computer logic. Therefore, to receive serial data from an RS-232 interface the voltage has to be reduced, and the 0 and 1 voltage levels inverted. In the other direction (sending data from some logic over RS-232) the low logic voltage has to be "bumped up", and a negative voltage has to be generated, too.
All this can be done with conventional analog electronics, e.g. a particular power supply and a couple of transistors or the once popular MC1488 (transmitter) and MC1489 (receiver) ICs. However, since more than a decade it has become standard in amateur electronics to do the necessary signal level conversion with an integrated circuit (IC) from the MAX232 family (typically a MAX232A or some clone). In fact, it is hard to find some RS-232 circuitry in amateur electronics without a MAX232A or some clone.
We discuss the signal bits in more detail later in this book.

### MAX232 and MAX232A

The MAX232 from Maxim was the first IC which in one package contains the necessary drivers (two) and receivers (also two), to adapt the RS-232 signal voltage levels to TTL logic. It became popular, because it just needs one voltage (+5 V) and generates the necessary RS-232 voltage levels (approx. -10 V and +10 V) internally. This greatly simplified the design of circuitry. Circuitry designers no longer need to design and build a power supply with three voltages (e.g. -12 V, +5 V, and +12 V), but could just provide one +5 V power supply, e.g. with the help of a simple 78x05 voltage regulator.
The MAX232 has a successor, the MAX232A. The ICs are almost identical, however, the MAX232A is much more often used (and easier to get) than the original MAX232, and the MAX232A only needs external capacitors 1/10th the capacity of what the original MAX232 needs.
It should be noted that the MAX232(A) is just a driver/receiver. It does not generate the necessary RS-232 sequence of marks and spaces with the right timing, it does not decode the RS-232 signal, it does not provide a serial/parallel conversion. All it does is to convert signal voltage levels. Generating serial data with the right timing and decoding serial data has to be done by additional circuitry, e.g. by a 16550 UART or one of these small micro controllers (e.g. Atmel AVR, Microchip PIC) getting more and more popular.
The MAX232 and MAX232A were once rather expensive ICs, but today they are cheap. It has also helped that many companies now produce clones (ie. Sipex). These clones sometimes need different external circuitry, e.g. the capacities of the external capacitors vary. It is recommended to check the data sheet of the particular manufacturer of an IC instead of relying on Maxim's original data sheet.
The original manufacturer (and now some clone manufacturers, too) offers a large series of similar ICs, with different numbers of receivers and drivers, voltages, built-in or external capacitors, etc. E.g. The MAX232 and MAX232A need external capacitors for the internal voltage pump, while the MAX233 has these capacitors built-in. The MAX233 is also between three and ten times more expensive in electronic shops than the MAX232A because of its internal capacitors. It is also more difficult to get the MAX233 than the garden variety MAX232A.
A similar IC, the MAX3232 is nowadays available for low-power 3 V logic.

#### MAX232(A) DIP Package

MAX232(A) DIP Package Pin Layout :
| Nbr | Name | Purpose | Signal Voltage | Capacitor Value MAX232 | Capacitor Value MAX232A |
| 1 | C1+ | + connector for capacitor C1 | capacitor should stand at least 16 V | 1 µF | 100 nF |
| 2 | V+ | output of voltage pump | +10 V, capacitor should stand at least 16 V | 1 µF to VCC | 100 nF to VCC |
| 3 | C1- | - connector for capacitor C1 | capacitor should stand at least 16 V | 1 µF | 100 nF |
| 4 | C2+ | + connector for capacitor C2 | capacitor should stand at least 16 V | 1 µF | 100 nF |
| 5 | C2- | - connector for capacitor C2 | capacitor should stand at least 16 V | 1 µF | 100 nF |
| 6 | V- | output of voltage pump / inverter | -10 V, capacitor should stand at least 16 V | 1 µF to GND | 100 nF to GND |
| 7 | T2out | Driver 2 output | RS-232 | | |
| 8 | R2in | Receiver 2 input | RS-232 | | |
| 9 | R2out | Receiver 2 output | TTL | | |
| 10 | T2in | Driver 2 input | TTL | | |
| 11 | T1in | Driver 1 input | TTL | | |
| 12 | R1out | Receiver 1 output | TTL | | |
| 13 | R1in | Receiver 1 input | RS-232 | | |
| 14 | T1out | Driver 1 output | RS-232 | | |
| 15 | GND | Ground | 0 V | 1 µF to VCC | 100 nF to VCC |
| 16 | VCC | Power supply | +5 V | see above | see above |
V+(2) is also connected to VCC via a capacitor (C3). V-(6) is connected to GND via a capacitor (C4). And GND(15) and VCC(16) are also connected by a capacitor (C5), as close as possible to the pins.

## A Typical Application

The MAX232(A) has two receivers (converts from RS-232 to TTL voltage levels) and two drivers (converts from TTL logic to RS-232 voltage levels). This means only two of the RS-232 signals can be converted in each direction. The old MC1488/1489 combo provided four drivers and receivers.
Typically a pair of a driver/receiver of the MAX232 is used for
* TX and RX
and the second one for
* CTS and RTS.
There are not enough drivers/receivers in the MAX232 to also connect the DTR, DSR, and DCD signals. Usually these signals can be omitted when e.g. communicating with a PC's serial interface. If the DTE really requires these signals either a second MAX232 is needed, or some other IC from the MAX232 family can be used (if it can be found in consumer electronic shops at all). An alternative for DTR/DSR is also given below.
Maxim's data sheet explains the MAX232 family in great detail, including the pin configuration and how to connect such an IC to external circuitry. This information can be used as-is in own design to get a working RS-232 interface. Maxim's data just misses one critical piece of information: How exactly to connect the RS-232 signals to the IC. So here is one possible example:
MAX232 to RS232 DE9 Connection as a DCE :
| MAX232 Pin Nbr. | MAX232 Pin Name | Signal | Voltage | DE9 Pin |
| 7 | T2out | RTS | RS-232 | 8 |
| 8 | R2in | CTS | RS-232 | 7 |
| 9 | R2out | CTS | TTL | n/a |
| 10 | T2in | RTS | TTL | n/a |
| 11 | T1in | TX | TTL | n/a |
| 12 | R1out | RX | TTL | n/a |
| 13 | R1in | TX | RS-232 | 3 |
| 14 | T1out | RX | RS-232 | 2 |
| 15 | GND | GND | 0 | 5 |
In addition one can directly wire DTR (DE9 pin 4) to DSR (DE9 pin 6) without going through any circuitry. This gives automatic (brain dead) DSR acknowledgment of an incoming DTR signal.
Sometimes pin 6 of the MAX232 is hard wired to DCD (DE9 pin 1). This is not recommended. Pin 6 is the raw output of the voltage pump and inverter for the -10 V voltage. Drawing currents from the pin leads to a rapid breakdown of the voltage, and as a consequence to a breakdown of the output voltage of the two RS-232 drivers. It is better to use software which doesn't care about DCD, but does hardware-handshaking via CTS/RTS only.
The circuitry is completed by connecting five capacitors to the IC as it follows. The MAX232 needs 1.0 µF capacitors, the MAX232A needs 0.1 µF capacitors. MAX232 clones show similar differences. It is recommended to consult the corresponding data sheet. At least 16 V capacitor types should be used. If electrolytic or tantalic capacitors are used, the polarity has to be observed. The first pin as listed in the following table is always where the plus pole of the capacitor should be connected to.
MAX232(A) external Capacitors :
| Capacitor | + Pin | - Pin | Remark |
| C1 | 1 | 3 | |
| C2 | 4 | 5 | |
| C3 | 2 | 16 | |
| C4 | GND | 6 | This looks non-intuitive, but because pin 6 is on -10 V, GND gets the + connector, and not the - |
| C5 | 16 | GND | |
The 5 V power supply is connected to
* +5 V: Pin 16
* GND: Pin 15

## Alternatives
### Data Cables

With the rise of mobile phones so called data cables for these phones have also become popular. These are cables to connect the mobile phone to a serial interface of a computer. The interesting thing is that modern mobile phones work with 3.3 V logic, and older phones with 5 V logic on their data buses. So these data cables must and do convert the phone logic voltage levels to and from RS232 voltage levels.
No-name data cables have become rather cheap (as opposite to original phone-brand data cables). The cheap cables with their voltage converters can be used as an alternative to home-made MAX232-based circuitry. The advantage is that the cables occupy much less space (the converter is usually inside the RS232 plug). Such a cable also saves the effort to solder a circuitry board. Another advantage, which can also be a disadvantage of such a data cable is that they usually take their power from the RS232 connector. This saves an external power supply, but can also cause problems, because the RS232 interface is not designed to power some logic and the DTE might not provide enough power. Another disadvantage is that many of these cables just support RX and TX (one receiver, one driver), and not two drivers/receivers as the MAX232. So there is no hardware handshake possible. Finally, when using such a cable it should be made sure that they convert to the desired voltage (3.3 V or 5 V).
* ^ There are also data cables for USB ports, but these are of no interest here.
* ^ Some data cables are powered by the phone and not via the RS232 interface. In such a case an external power supply is still needed, to replace the one from the phone.

### (Ab)using a USB <-> RS-232 Converter

USB to Serial interface cables often have two components: a USB transceiver that outputs serial data; and a voltage shifter to produce standards-compliant RS-232 voltages. It is often possible to throw away (ignore, desolder, cut-out) the USB part of these cables, connect an external 5 V power source (or abuse the RS-232 interface) to replace the power coming from the USB bus and to just use the RS-232 level-shifter. All this is probably as much work as using a MAX232A, although you get one RS-232 connector for free.
If you consider a USB cable, it is also worthwhile to consider using USB directly, instead of RS-232. Many USB transceiver chips can be integrated directly into circuits, eliminating the need for voltage-shifting components. Parts such as the FTDI FT232BM even have an input allowing designers to select 5 V or 3.3 V output levels. Most of these USB transceiver chips are available as surface-mount components only. But some vendors offer DIP-sized preassembled modules, often at competitive prices, and often with free or cheap drivers or driver development environments.
See Serial Programming:Universal Serial Bus for more on USB hardware, interfacing with USB devices and programming USB devices.

### MAX232N

A Texas Instruments MAX232 (not A) second-source. The N indicates the package (plastic dip), and not any special electric characteristics. This is a non-A MAX232, therefore it needs at least 1µF capacitors. It can sometimes be found rather cheap. TI also offers MAX3232s and a number of other RS-232 drivers/receivers, like MC148x.

### Linear Technology LT1181A

The LT1181A from Linear Technology is very similar to the MAX232A. It has the exact same pin-layout, also uses 0.1µF capacitors, and can in general replace a MAX232A. However, for the hobbyist it is typically a little bit more difficult to get one, and they tend to be slightly more expensive than the original Maxim MAX232A.

### Intersil HIN202

The Intersil HIN202 is yet another IC very similar to the MAX232A. It also has the same pin-layout (DIL package), uses 0.1 µF capacitors and can replace a MAX232A. The HIN202 is especially interesting when more I/O lines are needed (four pairs), since the manufacturer specifies that two HIN202's can share a single V+ and a single V- capacitor. So the resulting circuit saves two capacitors.

### MC1488 and MC1489

The MC1488/MC1489 ICs have already been mentioned. However, they are no real alternative to a MAX232 these days. A combo of these ICs has twice as many drivers/receivers, but the MC1488 driver requires a +12 V, -12 V power supply, and the MC1489 receiver a +5 V power supply. That makes three power supplies instead of one for the MAX232. Unless the required ±12 V supply lines are already available in a circuit, it is recommended to use either two MAX232s, or a single MAX238.

## External links

* MAX232 (MAX220 to MAX249) product webpage - Maxim - (5 volt)
* MAX3232 (MAX3222 to MAX3241) product webpage - Maxim - (3.3 or 5 volt)
* MAX3232E (MAX3222E to MAX3246E) product webpage - Maxim - (3.3 or 5 volt)
* MC1488 product webpage - Texas Instruments - (+12 and -12 volt)
* MC1489 product webpage - Texas Instruments - (5 volt)
* MAX232: Construction, Operation, Types and Application
Serial Programming: Introduction and OSI Network Model -- RS-232 Wiring and Connections -- Typical RS232 Hardware Configuration -- 8250 UART -- DOS -- MAX232 Driver/Receiver Family -- TAPI Communications In Windows -- Linux and Unix -- Java -- Hayes-compatible Modems and AT Commands -- Universal Serial Bus (USB) -- Forming Data Packets -- Error Correction Methods -- Two Way Communication -- Packet Recovery Methods -- Serial Data Networks -- Practical Application Development -- IP Over Serial Connections