Tony Lawrence: Serial Wiring
Copyright September 1992 Anthony Lawrence, Lawrence & Clark, Inc.
The article below was written in 1992. Nowadays we wouldn't use flat cable; we'd wire this with CAT-5 and use punchdown blocks and patch cords- in other words, just like we were wiring for a network. In fact, anything that has been wired for a netork can be used to carry serial traffic- you just don't plug into the network hub!
But the rest of the article still has value.
I have seen intelligent adult human beings brought to the very edge of insanity by the (anticipated) simple connection of a terminal or a printer to a Unix system. I have seen the aftermath of such installations: solder-burned fingers, floors littered with clipped off RJ-11 phone connectors, and wires ending in amazing combinations of store-bought null modems, gender changers and straight-thru cable connectors. I have seen full 25 wire cable strung through walls to service one lone terminal, and signal boosters sprinkled every fifty feet on a 200 foot run to a slow printer. I guess I've seen about every mistake that can be made, and I've made quite a few myself. But, RS232 does not have to be difficult. In fact, it can be simple.
When I was first exposed to RS232, I thought "Gee. There are 25 (count 'em) pins on this connector. That's an awful lot of possible combinations. I'd better hire somebody who knows what they are doing." So I did, and what that person knew that I didn't was that, for more than 99% of configurations, only 3 of those wires matter at all. That cuts down on the permutations quite a bit, and bolstered my confidence enough that I was willing to try it myself the next time. So I did, and everything worked out wonderfully, and I've been doing all my own RS232 wiring ever since.
You can, too. It's not hard, and although you may get confused now and then (it happens to me; why should you be any different?), there are some tricks I've picked up over the years that can help you get back on track. You'll need a few simple tools, but you'll probably spend less than $50.00 for everything. Armed with these tools and a little knowledge, you'll be ready to tackle any RS232 problem.
Before we start, let's dispense with some common myths. The most prevalent is the old "RS232 runs have to be less than fifty feet". If this was ever true, it related to equipment in use long before I started playing with this stuff (1983). I have not seen a UART (Universal Asynchronous Receiver-Transmitter) that couldn't support 9600 Baud or better for at least several hundred feet over ordinary telephone wire. Most good quality multiport cards can drive 9600 Baud for 20 times 50 feet and never garble a byte. If you think about it from an electrical viewpoint, it's a simple a matter of how much degradation in signal strength there will be over X feet of Y size wire, and just how much of said degradation the devices at each end of the wire can put up with. So forget about 50 foot limitations. Start worrying when you get close to 1,000 feet, but don't be surprised if it works at that distance, too!
Another common "truth" is that you must wire DTR, DTR, RTS, CTS, CD, both grounds, and maybe jumper a few pins also. That there are situations and even equipment (modems being the obvious example) that may require fairly complex wiring is true. But, for most terminals and just about all printers, a grand total of just three (3) wires will work. Why complicate your life? And why not capitalize on the opportunity? If there happens to be a strand of 25 wire cable running from near your computer to some other point, you can probably support 8 terminals or printers off that one cable. Might save yourself some significant cash.
See RS232 Diagrams and Pinouts also.
Note: After I wrote this, one gentle reader got really angry with me for suggesting this. In no uncertain terms, he insisted that unprofessional hacks (that would be me) have no business running wires for professional installations. He's right. What I neglected to mention here is that this sort of thing should only be done when you are willing to take responsibility for it yourself, or when you are clobbering together something to figure out why the "professional" installation isn't working. In general, hire wiring contractors and use hardware flow control except where it makes no sense (low speed terminals). But when you need to trouble-shoot, keep it simple..
One caveat that you will want to check into: In many localities, the fire code requires that wiring strung through walls be installed by a licensed person. The safety reason for this is not the voltage levels, but to prevent fire from spreading by way of the wires. When such a code is in effect, you obviously do not want to be doing that part of the job yourself. Generally, the code would not extend to the connections you make to the wire outside of the wall, but it wouldn't hurt to have a short chat with your local fire department before doing this kind of work.
Ready to begin? All of the tools you will need can be bought at Radio Shack or any other electronics store. The very first thing is a modular connector crimper. This is a tool for crimping RJ11 plastic connectors on to flat phone wire. You can buy these for as little as $10.00, but if you are planning to do any significant amount of work, plan on spending $30-40 for decent quality. The top of the line models ($100.00 or more) can crimp anything from 8 wire RJ45 down to the little plugs that go into telephone handsets.
The next tool is a line analyzer. It's just a box that plugs into an RS232 line and has LED's to show which lines are active. Radio Shack sells one (Part # 276-1401) for around $15.00, but you can probably get them for less than $10.00 if you shop around. It's nice to have two of them, but even one will save you a lot of trouble. You can buy more expensive versions that combine this with a break-out box (allows you to easily swap pin configurations) and sometimes even a voltmeter, but you probably won't need anything more than the simple one.
A voltmeter is a good tool to have. When I first realized that, I went out and bought a wonderful, whiz-bang $250.00 multi-function voltmeter. It had digital displays, automatic range sensing, pulse capabilities- the darn thing was almost an oscilloscope! I found that, in the field, I would only ever use it as a continuity tester. So I retired the Wonder Meter to my shop and bought a $12.00 Radio Shack model instead. Works great for what we need to do here.
Many of the people who do this sort of work do have the Break Out boxes mentioned above. I have one also (bought about the same time as the Wonder Meter), but I never use it and don't even carry it with me any more. If it makes you more comfortable, by all means do buy one. They are great for teaching basic electricity to your children.
For the purposes of this article, I'm going to pretend that you will be connecting terminals and printers that are close enough to the main machine that you will NOT be going through the walls. That this is an idealization of the real world is true, but if I start getting into the wall, we have to talk about the different color schemes used for that kind of cabling, and we'd probably have to get into punch down blocks and all that kind of stuff. Time enough for all that once you get basic cabling under your belt. Until then, let's string the wire over the partitions and see what we can learn.
We want to use flat telephone cable. This comes in 4, 6 and 8 wire configurations. The reason for flat cable is so that we can easily attach RJ12, RJ11 or RJ45 connectors to the wire. These are the same kind of connectors you use in your house for telephone wiring. As was explained above, 3 wires are sufficient for almost every situation, so 4 wire cable is all you will likely need. Because I do a lot of this and am more apt to run into the odd situations, I generally carry 6 and 8 wire cable with me. But, it's still true that only 3 wires usually get used. Make sure that the cable has colored wires. Although it's rare, I have seen 4 wire cable where each wire is the same color. While not impossible to use, the lack of a color scheme will complicate things unnecessarily. It is also not absolutely impossible to get round telephone cable inserted in RJ connectors. However, at best it is difficult and certainly is not something you want to do if there is any way around it.
Flat wire comes in various lengths; expect to pay $30-$40 for 1,000 feet. If you do buy the thousand foot box, this will give you an excellent opportunity to see just how far your RS232 ports and terminals can be spaced apart; more on this test later.
You will also need RJ to DB25 or DB9 connectors. You can buy these pre-wired (and if you do, you don't need to be reading this article), but they are expensive, and may even be wired incorrectly for the task you have at hand. There are at least three different types of "do it yourself" connectors available: the kind you solder a pin onto each wire, the kind where you crimp a pin onto each wire. and the kind where the pins are already connected and you just push them through the right holes.
There are those who will argue strongly for the soldered approach. Personally, I don't care for the smell of burnt plastic, and I like the smell of burnt flesh even less. As for the crimp kind, I find it real hard to get a solid, reliable connection. The pre-pinned push-through connectors cost less than $3.00 apiece in small quantities and are very simple to put together.
Should you choose this approach (wise choice), you will also need a pin extractor. This is a little gadget that looks like it belongs in your Mom's sewing kit. It lets you pull those little pins back out when you accidentally put them in the wrong hole because it's nine o'clock at night and you've already wired thirty of these stupid things and your eyes and your brain are tired. Buy a few of these; they are inexpensive but they do wear out. If you can find one, a pin pusher is also a good tool to have; it just makes the job easier. These don't wear out, so one is sufficient.
Let's take the very simplest job first: A terminal to be connected to one of the built in COM ports (tty1a, for example). The terminal probably has a DB25 connector, and your COM port is either DB25 or DB9. The first thing to do is to cut a piece of flat cable to appropriate length. If you bought the thousand foot box and you want to see if your equipment can work at that distance, don't cut off anything. Dig in and find both ends of the spool.
Trim each end of the wire carefully; you don't want any wire burrs sticking out to cause a short circuit. You will need to trim off a small amount of the outside insulation in order to insert the wire into the RJ connector. Your crimping tool probably has both a cutter and a stripper built in, but it may take a little practice (particularly with the less expensive models) to get a good cut and trim. Note that the inner (colored) insulation is not stripped: no bare wires should be showing. The RJ connectors have knife edges that will pierce this insulation to make the connection.
I'm going to assume here that you are using 4 wire cable and that the color scheme is Yellow-Green-Red-Black. We'll also pretend that you bought 4 wire RJ to DB connectors, because that doesn't give us any extra wires to worry about. Don't worry, I will get to the more complex stuff. But for now, we are taking the simplest case. Insert each end of the wire into a modular connector, keeping the wiring oriented the same way to both connectors. The simplest way to do this is to hold the connectors with the plastic snap pin facing down and then keep the same color on the wire to your left. It really doesn't matter which color you choose: Yellow or Black. Use the crimper to install the connector. If you've never done this before, observe what the connector on your phone looks like. See how all the metal pins are above the surface of the plastic before you crimp but recessed into the plastic on the one on your phone? That's what your connectors should look like when you are done. Be sure to push the wire in firmly and keep it straight before you crimp. With less expensive tools, you will have to apply more force than with the higher priced models. But be careful with the very cheapest ones: you can easily break the tool.
You have now made a "Straight Through" cable. If you had twisted the wire before installing one of the connectors, you would have made a "Twist" or "Flip-Flopped" cable. You obviously have to make one or the other. If you now hold the two ends of the cable so the connectors are side by side and facing the same direction, you will (or should!) see that the colors run in the same order from left to right in both connectors. If this is not the case (I screw it up more often than not), it really isn't a critical mistake. We can correct it later when we do the actual wiring, but for now, if you did do this wrong, cut off one end and try again.
Now plug one of your RS232 Line Analyzers into the back of the terminal. If you have another one, plug that into the COM port on your computer. Turn on the terminal and the computer. If you only have one of these gizmos, you can move it from the terminal to the computer as we talk about what you will be seeing. Notice that we have NOT done anything with the cable yet and we have NOT used any of the RJ to DB connectors either. We just have the terminal and the computer with your line analyzers hanging off the back.
I'm going to make another assumption here, and that is that your terminal is a Wyse60 or one that works in pretty much the same way. In other words, I assume it has a port marked "Modem" and a port marked "Aux" and that there is a special key or combination of keys that you can press to get into "Setup Mode" on the terminal. Your analyzer should be in the "Modem" port, and (if it has this feature) your terminal should be set for "Host is on Main Port" and for 9600 Baud, 8 bit, no parity, XON/XOFF flow control.
Take a look at the analyzer on the terminal. You should see a "red" TD light, a "green" RTS and a "green" DTR. The colors indicate high or low voltage. Occasionally I have seen these analyzers wired the other way: you'll have green where it's normally red and vice versa. That's okay, as long as you know that yours works the opposite of what I'll be describing. If you see a different light configuration, check that you are in fact in the right port and that the terminal setup agrees with you.
Now look at the computer side. Ignoring all other lights, you will see a red TD. You are about to learn the most important thing about RS232: TD to TD doesn't work. We have to switch around some wires to get these two guys talking to each other. If you happen to have a modem handy, hook your analyzer onto it. Notice that you get a red RD now. That's why a computer can be connected to a modem with a straight through cable: TD talks to RD. Do you have a Null Modem in your kit? Stick it onto the terminal and then attach your analyzer to the Null Modem. You have a red RD. Now you know what a Null Modem does. Basically, it lets TD talk to TD by switching around some wires. Take the Null Modem out, though, we won't be needing it.
If you were aware that both computers and terminals are DTE (Data Terminal Equipment) you wouldn't have needed the Analyzer to show you that these two devices won't talk through a straight cable. And since, computers and terminals ARE always DTE (modems are DCE: Data Communications Equipment) you really won't need that tester to tell you this again. However, you have not wasted your money. First of all, there is no standard for multiport serial boards. Some are DTE, some are DCE, and some can be configured either way. And, as we'll see later, it's pretty easy to cross wires in the wall and accidentally turn DTE into DCE or vice-versa. The analyzer will help you spot that quickly. Another thing the analyzer is good at showing you is the absence of signal. Turn the terminal off. The lights go out. The same thing happens if a wire is broken. The analyzer will also help you identify mis-wired cables, but we'll see that later on. Let's get on with connecting this terminal.
Plug a DB connector onto each end of the wire. Note we have not yet pushed any pins through the shell part of the connector, and we haven't connected to either the computer or the terminal in any way. All we have now is two DB connectors with a length of wire between them and bare pins hanging out each end. It's time to pull out the Voltmeter and find out a few things.
First, we want to be sure that there is continuity (an electrical path) and then we want to check for any shorts. Set your voltmeter to read Ohms and touch one lead to the Yellow wire at one end of your cable. Touch the other lead to the Yellow wire at the other end. If you get a reading on your meter, great. Try the same thing with each of the other colors.
If you do not get a reading, try having one lead on the Yellow, but touch the Black at the other end. If this gives you a circuit, you've just learned another fact about RS232: color schemes aren't standard. The problem is this: the DB connector may be configured Yellow-Green-Red-Black or it may be Black-Red-Green-Yellow. Notice that the order of the colors is really the same; it's just a matter of which color is connected to Pin 1 on the RJ plug. If this is confusing you, visualize what would happen if you had made a "Flipped" cable instead of a straight through. The Yellow wire would end up connected to the Black wire at the other end, and vice-versa. Effectively, this is what can happen with the DB connectors. You would think that buying the same type of connector from the same manufacturer would guarantee some consistency in the color orientation, but it doesn't. The good news is, that with the exception of rare defects, the color order is guaranteed: it will be Y-G-R-B or vice versa. When we get beyond 4 wires it's usually Blue-Y-G-R-B- White, and if 8 wires are used the outside pair is usually Orange and Brown, but this isn't always true, and the Blue and White colors are sometimes changed also. But, as we will see shortly, these minor inconsistencies are totally unimportant.
Back to the Voltmeter (remember, we are measuring continuity right now, not voltage). With luck, you have found that you do have continuity, although you may have a color reversal. What if you don't have continuity on one or more wires? First, it is possible (though extremely rare) that the DB connector is defective. More likely, you have made a bad crimp on the RJ connector. Inspect each end visually. Are the metal tabs recessed into the plastic? Are the wires themselves extended far enough into the RJ plug? If you turn the plug sideways, you will be able to see the outside wires. Does it appear that the metal tab has reached the wire? If anything looks suspicious here, try re-crimping. If you still do not have continuity, cut off one or both ends and try again.
Once you have passed this test, it's time to look for shorts. Touch one lead to the Yellow wire. Touch the other lead to each of the other colors in turn (you can do this at the same end; a short will show up wherever you test). You should not see any reading on the meter because there should be no connection between the different color wires. If you do show continuity, check to be sure that none of the wires are crossed at either end (a strategically applied piece of tape is an easy way to keep the wires apart), and be sure that your nervously sweating hands aren't accidentally providing a path for the current. If you do have a short, it's probably due to bad cutting or stripping. Be sure that the ends are neatly and cleanly sheared off and be sure that your stripper has not cut too deeply and removed the inner insulation.
With luck and a small amount of skill, you now have a piece of cable that is ready to work. But let's digress for just a moment and discuss the significance of the Green-Red inner pair of wires versus the Yellow-Black outer pair. Just which pair should be carrying the TD-RD signals and which pair should be carrying Ground? Just what is the standard here?
There isn't any. Or if there is a standard, nobody pays any attention to it. For example, there are a number of different manufacturers of dumb and intelligent multiport serial I/O cards. Many of these cards can be purchased with RJ11 or RJ45 plugs as the connection point. With these, you only need a DB connector at one end of your wire. The other end plugs directly into the multiport card.
Some of the manufacturers use the middle pair (Red-Green) for TD and RD, and others use the outer (Yellow-Black). While I have never seen a board that used anything outside of the Yellow-Black for TD-RD (such as Blue-White), I don't think it would surprise me too much if I came across one. Fortunately, the manufacturers do provide at least some sort of wiring diagram, so you will be able to know which way their board works. We'll come back to multiport cards later, but for now just accept that Color Doesn't Matter.
So now we are ready to do a test connection of the terminal. Note that we still have not used the shell connector: the wires are still dangling loose. We aren't going to commit to anything just yet. Instead, starting at the terminal end, stick the Yellow wire pin directly into the Pin 2 hole of the analyzer (which is still hanging off the back of the terminal, isn't it?). If you are looking at the female end of the analyzer, and the wide end is up, Pin 1 is the top right pin. Pin 2 is the second top pin moving to your left, and so on. The numbers may even be marked on your tester; they are on the Radio Shack model. Push the Black wire into Pin 3, and the Green into 7. As a visual check, there should be 3 empty spaces between the Green and the Black wires.
Now to the computer side. Here we may have a problem. Depending on your hardware, and on whether you are using tty1a or tty2a, you may be connecting to a DB9 or maybe to a DB25. If a DB25, it may be male or female. For the simplest explanation, I'll first assume that it is a female DB25. This will illustrate the theory in the easiest way, and we can deal with the nasty real world afterward.
So, at the computer end, put the Black wire into Pin 2, the Yellow into Pin 3, and the Green into 7. Note that the Black and Yellow have been reversed. This accomplishes just what a Null Modem would: TD gets to talk to RD and vice versa. (If you had the unfortunate experience of finding that your continuity was from Yellow to Black and so on, your wiring at this end is exactly the same as at the terminal end. This is because the DB connector has effectively done the reversal for you). Now check the lights. You should have RD and TD at both the terminal and the computer and both should be red. If you do not have both lights at either end, you have mis-wired. Pull the analyzer from the terminal, leaving the wires still plugged in. Do you show a red RD? You should. If it's TD, you have mixed up the Black and the Yellow. Switch them, and try again.
Now that you have it right, let's make some deliberate mistakes and see what the analyzer shows. Put the Red and the Green into Pins 2 & 3, and the Yellow or Black into 7. The tester will either show nothing at all or both TD and RD as green. Try different "wrong" wiring, and see what you get. If you want, set your Voltmeter to a low DC setting and see what levels you get across the pins. You will find that the strongest voltage is from TD to Ground, and the weakest is from RD to ground. There will be a voltage difference between RD and TD, but it will be less than that between TD and Ground. Your voltmeter can be used to identify TD and RD, but the analyzer is much easier and quicker. Put everything back the way it should be, and we'll go on.
With both connections made, enable the port, checking that the baud rate of the port and the terminal match. You should have a login prompt. If so, you can remove the analyzers and plug the pins into the shell connectors. Push in firmly. You may want to use the extractor tool to push the pins in, or use a pair of needle nosed pliers to pull the pins through from the other end. If using pliers, be careful not to bend the pins.
If you didn't get a login and everything else seems right, did you use the full 1,000 foot box of cable? Chances are good that it would work, but it may not. Try lowering the baud rate to 2400 and see what happens. If you have no luck, shorten the cable.
Another check is to send a continuous stream of data to a disabled port. "lr / > /dev/tty1a" is a simple test. You should see the RD light on the analyzer turning from red to green quickly as the data flows. If it isn't, data is not flowing.
Let's return to the problem of male DB25's or DB9's. If male DB25, the only difference is that you are looking at the pins from the opposite side of the mating. Therefore, Pin 1 is on your right. A DB9 presents a different set of problems. First, Pin 2 is RD and Pin 3 is TD. This means that Pin 2 from DB25 would go directly to Pin 2 on the DB9. Naturally, DB25 Pin 3 would go to DB9 Pin 3. On the DB9, Pin 5 is ground. Therefore, Pin 7 from DB25 would connect to Pin 5 on a DB9.
That concludes a simple 3 wire connection. For a multiport card, the only difference is that you could be starting with an RJ jack rather than a DB connector, and that the meaning or use of the wires is set by the manufacturer. One thing to know is that it is fairly common to get a bad port right out of the box on a new board. You may be driving yourself crazy trying to get wiring to work, double checking the manufacturer's diagrams over and over, and be doomed to failure because the port is bad. Try a different port before you start getting desperate.
When do you need to wire more than TD, RD and Ground? Well, certainly for a modem, and also for any device that cannot or will not do Xon/Xoff (Software) Flow Control. Flow Control is an agreement between the computer and the device (terminal, printer, etc) as to how the device will tell the computer to stop sending data because the device is presently too busy to handle any more. It's the same concept as you holding up your hand with your palm facing me if I'm talking too fast. The signal means Stop: I can't take anymore right now.
Software flow control expects that the device will send back a Ctrl-S when it needs the computer to stop. Generally a Ctrl-Q is expected to restart the data flow. Hardware flow control involves the use of DSR/DTR or RTS/CTS. Most devices can be set to XON/XOFF, and that is my preference if I can get it. However, some devices can only do Hardware flow control, and others that say they will do XON/XOFF may not actually work. Therefore, it is possible that you may have to connect some extra pins for a particular printer or other serial device.
If so, try the manufacturer's suggestions first. If they want a cable with CTS and RTS wired together, make one by snipping off two pins from a DB connector, inserting them , stripping the insulation, and braiding and taping the wires together.
You may find (particularly with multiport boards) that you cannot make the proper cable because the signals they want aren't available on the card. This is particularly apt to be true of the less expensive boards. Some manufacturers (Digiboard, for example) provide a software switch that allows you to change which signals are provided on the outside pair of wires. If your board doesn't provide such an ability, do what you can and hope you can get it to work. These types of problems are rare, so don't anticipate having them very often.
In the event of problems, use your analyzer. Are you getting the lights you expect? Are you getting any lights you don't expect (could be a short)? Is there voltage where you expect it to be and is it at a reasonable level? Does dropping the baud rate help? Do the computer and the device agree on flow control?
See Serial Printers for more on printer flow control.
When dealing with RS232, it's often helpful to be painstakingly methodical. Check everything, and verify everything you check. There's nothing magic about any of it, so a logical approach to each element involved should yield good results.
I have not touched on some of the software issues such as getting older versions of SCO to do anything but XON/XOFF flow control, or on the data loss problems that can come from large printer buffers, or even such simple issues as "hold-open" scripts for printers. But those issues have been covered elsewhere and undoubtedly will be covered again. I hope that this article, concentrating more on the physical issues, has been of interest to you.
See also Dumb Terminals
(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version