| You are in home \ microcontroller \ peripherals \ RS-232 serial to TTL serial (back) |
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.
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...
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.
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.