All these different interfaces...

You are in home \ microcontroller \ peripherals \ RS-232 serial to TTL serial     (back)  

In RS-232 style serial comms, the micro's UART puts out a TTL level High (+5 V) for a mark, and logic low (0 V) for a space.
That's fine from micro to micro, but the PC uses true RS-232, which involves transmitting a level of around -5 to -15 V for mark, and +5 to +15 V for spacing condition.
(Btw true RS-232 should receive a mark in the range -3 to -15 V, and a space between +3 & +15 V.

Fortunately for us, most modern UARTS in PC's will recognise 0 V as a marking condition, so we can use the micro's supply levels of +5 V for space (fits ok in the +3 to +15 V range), and 0 V for mark (although it's technically below the -3 to -15 range).

There is one catch though... the micro's outputs need to be inverted for RS-232 comms. Fortunately that's easily done.

Ideally we could afford a MAX-232 chip in every project, but it's not essential. Lets look at the alternatives.


Common TTL serial interface

The commonest TTL to serial interface is to use a transistor as an inverter. Often two NPN transistors are used, one for TxD & one for RxD.
Since the micro prefers to sink current than source it, we let the micro drive a PNP transistor low when it transmits. (We could also use an NPN as an emitter follower, I guess). Anyway, all that takes is 2 transistors, some resistors, and maybe a diode. That's one way...


TTL serial buffer interface

A hex schmitt trigger inverting buffer (as opposed to a wankel rotary engine :) is a better approach here than the more commonly used transistor inverters, because it doesn't draw as much current as the pull-up resistors in the common transistor version. (It also draws less current, btw, than the MAX-232.) Now wtf's a hexy thingy... well, it inverts the signal. In other words, in goes a low (0 V) & out comes a high (+5 V), OR in goes a high (+5 V) & out comes a low (0 V). The Hex part means there's six of these buggers in the chip, and the schmitt part just makes it less sensitive to noise.
Here I use the 74HC14 (DSE Cat.# Z 5814, $1.35), but just about any schmitt inverter will do. Do use a socket (14 pin).
Hopefully the circuit works with the values shown.

TTL to RS-232 interface

Sometimes, just sometimes, we want to do things properly, but need a cheapskate way to do it. What I mean is, sometimes we want real RS-232 signal level (actually providing a negative voltage, rather than getting away with 0 V).

You could give in and use a MAX-232, but that's a cop-out if you have no sense of adventure (or you actually have money and no spare components lying around). Anyway, we could use one of several voltage-doubler and/or voltage inverter circuits, which aren't that difficult, and can be fun, but still... the MAX232 does all that internally, and we want the simple way... read on..
We can 'steal' this negative voltage from the host end of the serial link (the PC, iow). When our micro transmits, the host (pc) TxD line should be negative (with respect to ground)... and that's where we steal the negative voltage from.

I wont explain how today, as it's 3:45 am and this is a rough draft... but you can steal the negative voltage from either the host's TxD line, RTS and/or DTR as well.
The former (steal from host's TxD) is 'relatively' straightforward, though the latter (steal from lotsa lines) is almost as simple, but does use a few more components (diodes to pins, and resistors across loopback connections to avoid host problems...). (we choose the former method here, I'll add in the latter method after this one at a later date after I get around to making & trying it...)

Anyway, here's the circuit...
RS-232 to TTL circuit diagram
And here's it's parts list...

RS-232 to TTL interface (232rs-tx.gif) Parts List. 

Q1 = BC556. Any General purpose PNP Trx will do, switching Trx is best. 
Q2 = BC546. Any General purpose NPN Trx will do, switching Trx is best. 
D1, D2, D3 = 1N4148. Any small-signal diode will do. 
C1 = 1uF. (Possible value range: 0.1u, 1u, 10u, 22uF.) 
R1 = 1k. Can be lower, or replace with 0 Ohm link. 
R2 = 1k. Can be lower, or replace with 0 Ohm link. 
R3 = 4k7. 
R4 = 4k7. (Alternate value: 10k.) 
R5 = 22k. (Alternate value: 10k.) 
R6 = 4k7. 
R7 = 10k. 
R8 = 4k7. (Value range: 1k, 3k3, 4k7, 10k.) 

This circuit allows the micro to provide the 
positive voltage (+5 V), and 
the host's RS-232 port to supply the negative voltage. 

Pins 1, 4, 6, 7 & 8 are connected to meet any 
hardware handshaking requirements by the host. 

- Do take note of the capacitors polarity, 
positive to ground, negative to the TxD end (thru R2, D1). 

- Note there is no connection to frame Ground (D9 shell). 
The cable shield (if present) may be connected at one end, 
but not both. Nor should frame ground (D9 shell) 
be connected to signal ground (pin 5). 

- Ring Indicator (9) has no connection, but perhaps it 
should be pulled high or low to prevent false triggering, 
unless of course the RS-232 host port takes care of this. 


Which one should I make...?

Well, if you want cheap and simple, and think that the host UART (PC) may forgive you bending the specs (using 0 V for -5...), then build the circuit with the inverter chip. (Good for micro to micro.)
If you can't find pinouts for another inverter that is in stock, or you insist on using spare components lying around (can't afford $2 eh :), then you'll be building the transistor inverter I guess... (micro to micro.)

If you want true rs-232 levels, then build the transistor inverter that steals the negative voltage from the host (PC). If you're not using the inverter chip design, then you may as well throw in the few more components to make it this 'proper' one ay. (best for micro to PC.

I've studied many other circuits and texts and done a lot of calculating to get these designs and values, but haven't tried them yet, so if blue smoke, or green smoke, or any other sign of excessive heat results, grab a marshmallow to toast quickly, instead of blaming me. I will be trying these very designs as shown, and will post updates then.
I'll also be writing up more, when I get time, or when I get the inclination, whichever requires the least effort.


Dave.


You are in home \ microcontroller \ peripherals \ RS-232 serial to TTL serial     (back)