- Wed Dec 14, 2005 10:29 am
#8572
I have also tried to understand several versions of such RS232 tricks lately. I find that understanding such seemingly simple analogue circuits is very useful to gain basic analogue skills. The last post summerized it well, but the naming of TX and RX confused me at first.
According to RS232 the pin 2 on the DB-9 connector in this schematic is "Received Data". So "RS-Out" in this schematic is an output, for data to your PC. This implies that the serial output on your uC must be connected to the RX pin in this circuit. That confused me. Anyway, the left PNP transistor is switched on/off whenever your uC clear/set the RX pin in this circuit.
The neat part of this circuit is the "stealing" of negative voltage from the computers RS232 port. To understand this I dug up the following, partly also mentioned by previous poster.
- Logic voltages on RS-232 (pin 2 and 3) are inverted. Logic "1" is aprox -2.5V to -15V, and logic "0" is +2.5V to +15V.
- 0 volt is usually interpreted as negative voltage, or logic "1" by your computer
- After power-up and in idle state an RS232 line is in its lower voltage state, hence 0V or negative voltage
So, after power-up and before/between transmissions the "Transmit Data" on the DB-9 connector (RS-In) will be negativ, or -15V. This voltage will transfer to C1 through D1 since positive side of C1 is connected to earth. Negative voltage on "RS-In" also keeps the right NPN transistor off, so TX signal is pulled to VCC by default.
Now, one of two things can happen. The PC sends data or the uC sends data.
When PC sends data:
When PC sends logic "0" then "RS-In" is set to high voltage +15V. Because of D1 this does not affect the negative voltage kept on C1. But it turns on the right NPN transistor, and the TX signal is pulled to ground. Since the RX pin on your uC is connected to this TX signal, your uC will correctly read a logic "0"
When the PC sends logic "1" then "RS-In" is set to low voltage -15V. Besides recharging C1 to -15V this turns off the right NPN transistor and the TX signal will be pulled to VCC. Again, since the TX signal is connected to the RX pin on your uC the latter will correctly read a logic 1 (VCC).
When uC sends data:
Now your PC is idle, so the "RS-In" pin is negative, keeping C1 at -15V.
When your uC sends a logic "1" on its TX pin, the RX signal in this circuit becomes VCC, which turns off the left PNP transistor. So "RS-out" is pulled to the negative voltage on C1 (-15V) through R2. This is correctly interpreted as logic "1" by your PC.
When your uC sends logic "0" the RX signal in this circuit is 0V. The left PNP transistor turns on and pulls "RS-Out" to VCC. This is read as logic "0" by your computer.
R2 reduces current when "RS-Out" is pulled to VCC by left transistor. A current of (15+VCC)/10k will flow through R2. With VCC=5V this would only be aprox 2mA. Note that although C1 delivers current through R2 it will continously be recharged from "RS-In" via D1.