Written by Kevin Ross
A common feature found on many Microcontrollers is a serial port (often called a SCI, COM, or ASYNC port). I am going to use the term SCI as a short cut to mean the serial port on your Microcontroller. Quite often, the SCI on your Microcontroller will generate the appropriate LOGIC signals to communicate with another chip. They do not, however, generate the proper voltages required for connecting to RS-232 devices. This article is going to describe the differences between RS-232 and TTL, and how to build a converter so you can connect your Microcontroller to an RS-232 compatible device, such as the COM port on your PC.
Standards are a wonderful thing. However, standards beget more standards, numbers, and classifications. Before you know it, people start talking in terms of standards and their revision numbers. Such is the case with RS-232. Lots of people can tell you what a 'serial' port is, but few could quote you the details about the contents of the RS-232-C or CCITT standards. (I certainly can't!). The RS-232 interface has been around for a very long time. It specifies the line voltages, connection considerations, baud rates, and a whole slew of other technical items. Modern day engineers treat RS-232 as an ancient standard handed down through the generations. Someone probably knows the origins, but most of us just use it as a given.
"RS-232" is pretty much the standard serial communications interface found on all types of equipment such as computers, modems, printers, Microcontrollers, eprom programmers, and a host of other devices. I won't be going into too much detail about the particulars of the RS-232 interface other than to point out a key issue to us: The voltages required.
Most microcontrollers run on a single supply voltage, and 99 out of 100 times, that voltage is +5 volts. In rough terms, logical 1 on these devices indicates that +5 is the voltage on the output pin. Logical 0 specifies that 0 volts is on the line.
The RS-232-C standard specifies that the voltage on the wire for sending a logical 0 are from +5v to +15v. The voltage for sending a 1 are from -5v to -15v. Most microcontrollers not capable of generating these voltages. So, to connect a microcontroller SCI port to a true RS-232 device, you need to convert the TTL voltages of 0 and +5 into voltages between about -10 volts and +10 volts.
You could, if you were so inclined, create something called a voltage doubler, which is capable of getting you 10 volts. Then, another circuit called a voltage inverter is capable of generating a negative voltage from that. The solution, of course, is to use a single chip for both.
Sure enough, the MAX232 is the chip for you. It runs on a single chip supply (+5 volts), and requires a few external capacitors. There is another version, the MAX233 which requires no external parts. It is, however, a little larger physically, and also costs about 75% more than the MAX232A.
Here is a diagram of the internals of the MAX232A. It shows a double charge pump voltage doubler and a +10v to -10v voltage inverter. The voltages output are used to generate the RS-232 compliant signals. The MAX232A has provisions for two serial ports on the same physical package. Most people only connect one of them. You can get a data sheet for the MAX232 and friends from Maxim. Try downloading MAX232-MAX233 Data Sheets in PDF format which is a fairly large file (1.2 meg), but has lots of information in it.
There are two camps on how to implement serial ports on a robot. One says stick the MAX232 on the robot. The other says don't. I kind of like the don't category! Most of my robots are autonomous, so I don't really need the MAX232 onboard consuming power. Since it isn't onboard, it needs to be on its own board. Turns out that a MAX232A fits quite nicely inside a DB-25 connector shell. The unit is powered by +5 and GND being supplied by the connection to the microcontroller. This powers the MAX232A.
The MAX232 comes in several varieties. I am using the MAX232A (actually MAX232ACPE is the full part) because it requires only .1uF capacitors. The original MAX232 required 4.7 and 10uF capacitors, which are bigger and cost more.
The photo below shows my stab at putting a MAX232, its capacitors, and the wire inside a standard DB-25 connector shell . I will add a parts list near the end of this article. This is a simple circuit to wire up, but I did play a couple of easy tricks. First was that the capacitors and the MAX232 share perfboard holes. I did this by pushing a screwdriver firmly against the IC pins at the point where they go through the perfboard. That should give just enough room to press the leads of the capacitors through the holes. This saved space and also made soldering these connections really easy. The other trick involves the cable clamp on the wire exiting the shell. The 4 conductor wire wasn't large enough to be held securely by the cable clamp. So, I took a rubber band and wrapped it multiple times around the cable, which enlarged it quite a bit. It now has a nice firm hold on the cable.
The perfboard fits snugly between the connector rows on the DB-25 (Female/Receptacle). It seems to work best using connectors that have solder cup terminals. There is just enough room in the shell to fit the 16-pin DIP part and a few capacitors. As you can see on the back view, the board has slipped right between the solder cups.
The particular wire I chose to use for the connector to the microcontroller is a 22 gauge, 4 conductor.
On the microcontroller side of the cable (not shown), I use a Molex/Waldom 4 pin connector. This is compatible with the BotBoard connectors. You can put any other connector that you find appropriate.
Just to be complete, here is the basic circuit connected to a 68HC11. As you can see, it is just a simple connection to the microcontroller. Other controllers will have a very similar connection.
I left out the perfboard, since I don't know its part number. I bought a 8x6 sheet of it at Radio Shack for a couple bucks. I would imagine that you can order the DB-25 parts from Digi-key, but I put in what I used. Chances are pretty strong that the Digi-key products will work as well.
|Mouser Part Number||Description|
|ME156-2025||DB-25 Connector Shell|
|ME156-1325||DB-25 Female solder cup|
|Digikey Part Number||Description|
|P4917-ND||.1uF Caps (need 5)|
|WM2002-ND||4 pin BotBoard connector|
|WM2200-ND||Pins for connector (need 4, must buy 10!)|
Mouser Electronics 1-800-346-6873
Digikey Electronics 1-800-344-4539