Sorry this is late; I wanted to run it by another engineer as a double- check, but I'm so busy lately, I guess I'll just post what I drafted... =3D=3D=3Dsnip=3D=3D=3D Implementing RS232 is easy to get working just well enough that you have no idea how far you actually are from the spec. Cabling, voltage, and flow-control misunderstanding plague most new designs. When building any serial device, the first things you should do before you design or do anything else (and forgive me if you've already done these) are, in this order: 1. Familiarize yourself with the normal, 25-pin, RS-232 signalling set. (Also, familiarize yourself with the "spec" voltage levels, although you will rapidly find that people have a wide range of = "interpretations" of them...) 2. Decide whether your device is Data Communications Equipment (DCE), or Data Terminal Equipment (DTE). Examples of DCE include modems, serial printers, and (if memory serves) mice. Examples of DTE include the PC (ALWAYS, even if there are two PCs-- see "DTE-to-DTE Wiring" in the spec), and a datalogger that takes the place of a PC when connected to some DCE instrument. If in doubt, if you are going to talk to a PC, I would strongly lean towards DCE to reduce cabling headaches later. 3. Decide what type of flow control you would like to use: software or hardware. If you are building DCE, I strongly recommend CTS/RTS flow control (you will assert CTS to tell the PC that it may send you data; your device can check the RTS line to see if it is ready to send data, or, more typically on PIC-based projects, just ignore it). DTR/DSR flow control is really intended for when the DTE is not likely to be able to keep up with the DCE, and that just doesn't tend to be the case these days, because the buffers on PCs tend to be huge compared to the devices they are talking to. 4. Pretend that both the PC (or other device) and your device are RS232 spec-compliant, 25-pin devices. Design your pin layout such that your device could be connected to the PC (or other device) with a standard, off-the-shelf, 25-pin RS232 DTE->DCE (or DTE<->DTE, if appropriate). Consult the spec to do this. Pay special attention to which signals, if any, are supposed to be crossed by the cable, and which pins have their "names swapped" on the DCE. For example: Many DTE->DCE cabling layouts have lines labelled from the DTE's point of view-- "TX" means "DTE's TX, DCE's RX", etc. Note that on a 25-pin DTE->DCE connection, this means that TX(2) and RX(3) are NOT CROSSED-- and neither are the flow control signals; the whole cable is wired straight through. (You can see how this all STARTED OUT so nice and simple...) On a DTE<->DTE connection (for example, to connect two PCs), you MUST swap the following pins between the ends for a fully-spec cable (which is to say, flow control will work to spec): 2=3D3, 4=3D5, = 6+8=3D20. Note that last one: tie BOTH 6 AND 8 on one end to 20 on the other; this must be done on both ends. If you have a pesky (typically non-PC) DTE that refuses to talk to your DCE device, try a straight-through cable with these modifications: on both ends, loop 4 to 5 (do not pass either through to the other side, just tie them together). On the DCE end, loop 6 to 20. On the DTE end, tie 6, 8, and 20 all together (do not pass any of these through to the other side). Note that this cable effectively smites hardware flow-control; look at the pinout to see why. If you have TWO pesky pieces of DTE that won't talk, try this: CROSS 2 and 3 over the cable, LOOP 4-5 on each end, and tie 6, 8, and 20 together on each end (passing none of these through to the other side). Again, this flushes flow control-- and DTE<->DTE is one place you may really need BI-directional flow-control. 5. Familiarize yourself with the 9-pin serial spec typically used on a PC. More specifically, become aware of the cabling required to connect a 9-pin DTE (PC) to a 25-pin DCE (external modem), and then realize that what you probably want for a PIC-based DCE is actually a 9-to-9 STRAIGHT cable, NOT a "NULL MODEM" cable. So the PIC's RS232 "transmit" pin is actually going to go on the RECV line for the PC, which is pin 2 on a 9-pin connector, even though it would be pin 3 on a 25-pin connector. Confusing? This is why, if you try to copy the pinout from a PC for a DCE device, you will wind up needing a crossover ("null modem") cable for whatever you've built. 6. Use standard connectors to save your users some headaches. If you need a CROSSOVER ("null modem") cable to talk to a PC, you have built a DTE device, and you should have a MALE jack (you can see PINS in it) on your device. If you need a STRAIGHT cable, you have built a DCE device, and you should have a FEMALE jack (you can see HOLES in it) on your device. 7. Whatever you do, BE CONSISTENT. If you cross your TX and RX lines, but don't cross your flow-control lines (CTS<->RTS, DTR<->DSR+DCD), you will have a MESS, and NO standard cabling, straight or crossover, will let your device your device talk to anything. If you have a device that you suspect has been misdesigned this way, try one of the flow-control loopbacks described in tip 4. IF YOU CAN TRANSMIT AND RECEIVE, BUT YOUR FLOW CONTROL DOESN'T MAKE ANY SENSE, OR IT SEEMS LIKE YOU CAN'T EVEN TOGGLE THE LINE, BE VERY SUSPICIOUS OF THIS PROBLEM AS THE CULPRIT. 8. While you CAN tap power off the flow-control lines, I don't recommend it. The amount you can source-- and, more importantly, the voltages you can source it at-- vary widely between differrent devices, even though the spec says it shouldn't. One example is that terminal- server equipment (another example of a DTE device) doesn't = necessarily have the same voltages and sourcing abilities as a PC serial port, and you may not be able to set the flow-control lines at your whim. Also, some devices will provide a negative voltage for low, others will provide ground. Again, not consistent with the spec, but this = is what has evolved in the market. If you DO source power from the serial port, I recommend testing with AT LEAST these devices (as = DTE): a generic, garage-built PC, a Compaq, an HP, an IBM Thinkpad (don't skip this one, they use a low-voltage serial port), a USB-to-serial adapter, a multiport serial card (such as a Rocketport card), and a terminal server, such as a Portmaster (or anything designed to run a rack of modems or a campus full of terminals). -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads