In this page, I am going to address an issue which gives many people trouble: The fact that "RS-232" and "serial" do not mean the same thing.
"Serial communication" merely means that some data is passed over a channel as a stream of ones and zeros. I.e., using the word "bit" in the narrow, binary numbers, sense, one "bit" at a time. This is Good, because you only need one wire... or other means of sending bits. (Leaving aside any craving for hardware handshaking you may feel.) This is Bad because it is slower than parallel data communication schemes.
I spoke of "ones" and "zeros".
A "one" is whatever you want to recognize as a "one". (Ditto zeros).
In simple work with microprocessors, such as the delightful Arduino, a zero may be "zero" volts in a wire... actually more precisely, "any voltage below a certain low threshold, say 0.6v". And a "one" may be defined as "5 volts" (or 3.3 volts, in low voltage devices). Again, that is more exactly as "any voltage above a certain moderately high voltage".
(An aside: That is part of the beauty of "digital", by the way. The electronics do not have to achieve "exactly" zero or five... near either is good enough. The engineers aren't being lazy with "good enough"... they are giving themselves room for the "things" that happen.)
RS-232 is a standard. ("V.24" was a similar standard.) A bunch of engineers met and produced a document, and it says, among other things, that in any "RS-232" data stream, "1" is represented by a negative voltage between -3 and -15 volts. "Zero" is represented by a positive voltage between 3 and 15 volts. Whoa! "Negative voltage"? Many beginning hobbyists, c. 2010 and later, will never have dealt with "negative" voltages. The "negative" end of a battery is more reasonably called the "zero volt" end, but we're stuck with the "negative" traditions. (The masochists among you can read many gory details of the RS-232 voltage levels at the relevant entry in Wikipedia.
Fear not! You don't need to know about negative voltages, if you take the advice that is coming. Just be careful not to feed any negative voltages... e.g. from an RS-232 device... into a circuit with only "zero", or "ground" and something positive, e.g. 5v, sometimes identified as "Vcc". (You may also have a "Vunreg", for "unregulated voltage", typically from a wall wart, fed to a voltage regulator, which generates your Vcc... the nice steady voltage your chips do best with. You may also have different positive voltages in different parts of your circuit. If you see things about "double rail" power, typically in connection with op amps, you may be getting into a situation with negative voltages, and need to read up... elsewhere!)
So... what can you do, if you want to work with something that is truly an RS-232 device? How do you interface your nice, uncomplicated little 0 volt/ 5 volt circuit with the +12 / -12 monster?
You can, if you want to, do it the hard way, incorporate a MAX232 chip in your project.
Or, if you will take my advice, you'll use the work someone has already done to invented this particular wheel. Several someones, in fact.
The answer to the RS-232/ TTL level shifting problem that I know and like is the following one. (Arduinos, Arizona Microchip PICs, and the BASICStamp all like "TTL").
ModernDevice initially created the P4B TTL/RS-232 interface to allow users to connect USB-less Arduinos to a traditional serial port on a PC, for programming. But it can perfectly well be used for any RS-232 to TTL interfacing. The device is bi-directional, by the way. It does also provide for "TTL to RS-232". (I mean to imply this bi-directionality in all that I've said on this page.) Cost: $6.50+p&p (Jan 2011) for unassembled kit, also available assembled and tested.
If you are new to serial work, buy an assembled and tested module... serial "stuff" is tiresome enough without having ANOTHER element in the mix which might be "the problem".
The P4B is also available from Wulfden, if you prefer that supplier, or see other "goodies" there that you want. His mini breadboards are all I want for Christmas. By the dozen, preferably.
(I have no "relationship" with either store, other than "happy customer". If you haven't visited both sites... and not overspent your electronics budget... visit them!)
I hope that has helped you understand the "RS-232 vs TTL voltage levels" issues? And solutions?
In this page, I have concentrated just on the voltage levels issues. You also have to deal with packet formats, handshakes, baud rates. Oh! So much fun to be had! I address some of those in my many other pages about serial issues. The one called "Using the PC's serial port" has a lot of information, and links to other pages about programming for serial comms, etc.
And lastly, a little anecdote which contains a warning of a major serial "gotcha". Many years ago, I made a quantum leap forward in my computing/ electronics accomplishments- to- date when I put together, from scratch, hardware and software what we called in those days a "single board computer". (It was based on the 6802... a wonderful line, which should never have died.) The "last challenge" in the series of "Bear climbed over the mountain, to see what he could see..." challenges was that "little detail" that has NEGATIVE 12v standing for "one" and POSITIVE 12v standing for "zero". Whom the gods would have insane, they send into the world of serial comms.
Having said that, my customary valediction of "Enjoy" may seem ironical... but once you get your serial link working, the thing you need it for will be enjoyable, I hope! With the 6802 project, I was trying to send "A5" to the dumb terminal the 6802 was connected to. ("A5" in Ascii has a good test pattern of 1's and 0's. However, I was, until I saw the problem, sending the inverse of "A5". The joy that silly little stream...
A5 A5 A5 A5 A5 A5 A5 A5 A5 A5...
....produced was wondrous.
Page tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org
....... P a g e . . . E n d s .....