Tuesday, November 24, 2009

Modding a PL-2303-based USB to RS-232 Adapter for TTL Serial

So a while back, user "tytower" on the Adafruit Forums needed a USB to Serial adapter to talk to his serial radio receiver, and was asking about connecting the 5V level system directly to a USB to RS-232 adapter.




I tried this for kicks on the receiver line of one to get information from an Arduino Diecimila with the provided example "ASCII Table" sketch. It didn't work. Here's why, and how to hack a PL-2303 based USB to RS-232 adapter for TTL level serial:


RS-232 is a pretty old standard, and requires transmissions of +12V/-12V for 0/1 binary signals (I've heard +15V/-15V quoted as well), and can apparently receive as low as +3V/-3V. A key point is that a negative voltage represents a "1," while a positive represents a "0." 0V doesn't technically mean anything, though there may be exceptions in existing hardware outside of RS-232 specification.

Comparatively, many microcontrollers talk in what some people call "TTL Serial," or "Logic Level Serial," which is the same variations of patterns (5 to 8 bits, with optional start, stop, and parity bits, and optional flow control) in the voltage range of a typical microcontroller. In this case, a "1" is around 2.2-5V, and a "0" is around 0-0.8V. Usually systems output on their power rails for high and low signals for serial, so a 5V microcontroller will usually have 5V "1's" and 0V "0's."





So, hooking up TTL Serial to an RS-232 receiver just doesn't work, since RS-232 expects a negative and positive voltage value for 1 and 0, and the TTL Serial transmitter puts out a positive and zero voltage value for 1 and 0. Conveniently, however, the USB bus itself is 5VDC, and USB to RS-232 adapters typically utilize two chips; one for USB host communication and 3.3V level Logic Level Serial communication, and another for converting  those signals to RS-232 levels. This means we can just crack open the adapter and solder in some wires to directly access 3.3V level serial lines that we can use to talk directly to our microcontrollers, or tytower's radio receiver!




The USB to serial adapter we will talk about here is one I grabbed off dealextreme for about $3. You can just take out the screws and force/peel off the plastic housing, which should slide off once you defeat the weak glue holding it in place around the DB-9 connector. The adapter uses the PL-2303HX, sometimes the PL-2303X USB to serial converter chip. The level conversion chip changes from revision to revision, and we don't really care about it. The following is a diagram of the chip, taken from the datasheet made available by the manufacturer, Prolific Technology Inc:





So, from this diagram, it's obvious that we want to tap pins 1 and 5, TXD and RXD, for use in simple serial communication. It can also be wise to link in with the ground signal, so you can link that ground up with your circuit's ground to avoid floating references. Similarly, we can also tap DTR_N, RTS_N, RI_N, DSR_N, DCD_N, and CTS_N, or pins 2, 3, 6, 9, 10, and 11. The pins and contacts are often hard to solder, however, so I would recommend only soldering what you have to to avoid burning the chip or accidentally bridging pins.

For now, we'll just talk about TX, RX, and GND. In the picture below, convenient (well, as convenient as they seem to get on this board) solder points are mapped out:



For this task, I would recommend one use thin (<28 gage) stranded wire (solid core may not last as long, and be more prone to detach). Be sure to use a lower temperature on your soldering pencil (if you just have a crappy single-temp pencil and are on the cheap, I'd recommend our friend here), and the smallest tip you have. Also, pre-tinning the soldering pencil tip, the stranded wire, and the solder point (or chip pin/pad) are all good ideas, provided you go easy on the solder volume.

There are plenty of good write-ups on the web on how to solder, and if you're looking for practice, I'd recommend getting some copper desoldering braid and an old VCR, and attempt to desolder various components from the board... It's a great way to learn and understand the liquid and surface tension properties of solder. It's something best learned with time and experience, and isn't easily explained properly.

Test for connectivity using a multimeter, test to ensure you didn't accidentally create a solder bridge with nearby pins, and you should be good to go. You can grab the Windoze PL-2303 driver here, and it should "just work" with the latest Ubuntu. Boot up your favourite 3.3V to 5V microcontroller or serial adapter, connect the "TXD" and "RXD" on the chip to your system's RX and TX (that's right, it's the typical crossover TXD->RX, RXD->TX), start up your favourite serial monitor (hyperterm, putty, gtkterm, realterm, etc.), and watch the magic happen*.

You may wish to hot glue or epoxy your wires in place once you've verified that the system works, as they may experience a fair bit of abuse in future tinkering. Also, you can cut some holes to work the plastic case back on, but I skipped that step since I didn't really like it to begin with. Alternatively, you can just desolder or chop off the DB-9 connector if you need to fit the assembly into a project box.

Since these USB to serial converters are cheaper than I can find the chips alone in single quantity, and the entire circuit is preconfigured, these may find their way into a few of my projects in the future.

Good luck!



-------------------

* If the magic does not happen, feel free to comment, and I'll see what I can do. Make sure everything's plugged in, that you can fully trust your other serially-communicating system, i.e. Arduino board, and that the communication bauds, stop bits, start bits, parity, and flow control options are set up correctly. Remember that accidentally reversing the pins should not kill the system, and might be the problem you're having.

2 comments:

  1. Clear and concise . I will have a look at mine and see if I can solder like you. I particularly like your graph explaining the signal . I thought it was along those lines but did not know for sure . Excellent . I'll be happy to add myself as a follower and put your blogin my bookmarks
    Thanks

    ReplyDelete
  2. On the picture above where you marked the pins. It confused me because on the diagrom pin #5 is RX and on your picture it is pin #6

    ReplyDelete