Opto-isolated level converter RS232 to TTL (and vice-versa)Plenty of today's microcontrollers have UART abilities to communicate with a computer's serial port via software protocol, which is basically RxD and TxD line to be broadcast. Usually, the microcontroller's I/O ports are TTL-style with unipolar 0V/5V voltage levels, while RS232 specifications require bipolar pulses about +/-12V. Standard solutions like MC1488/1489 or MAX232 may be provide little protective features... Now here's my proposal on RS232-to-TTL conversion with optoelectronic separation, not to be confused with those ultrasimple one-coupler-per-line-crap, published elsewhere! This concept performs real bipolar signal processing and regeneration, according to EIA-232 specifications!
![]() Pic.2: Rugged optoelectronic converter RS232 to TTL Circuit DetailsSerial Interfacing Starting from the DTE-connector X1 (9-pin D-SUB, female), we find RTS+CTS and DTR+DCD+DSR directly connected to each other. By that, the stupid DTE "believes", it's connected to an external serial device that is always ready to receive fresh data (sometimes referred to as a "RS232-masturbator-bridge"). Thus, serial connection can be established in pure software protocols (e.g. Xon/Xoff), as well as some originary hardware modes will work as well. Most of all, there are still only RxD and TxD signal lines to be connected with the DCE device. One main objective for my RS232-TTL-Converter was to provide RxD-input ot DTE-side with real bipolar data, according to EIA232-specifications, without additional power supply. In fact, DTE must deliver positive and negative auxiliary voltages, needed for RxD-regeneration, by itself. (To me, additional DC/DC-converters or power supplies didn't make sense for cost- and some technical reasons, too.) So, are these requisites all contradictory? "Not necessarily!" As a favourable "side effect" from the DTR+DCD+DSR interconnection, DTR-output is set to a "logical-0" (or "Mark") state immediately after the respective serial port was opened. This positive voltage is "tapped" by D1 to recharge an electrolytic capacitor C1, that could be seen as a small battery. (In addition to DTR, positive levels of TxD are also utilized by the way of D2; this is mainly to improve load balance on TxD.) To gain some negative voltage, we have to take TxD-output, which drops to -12V in idle state (stop-bit condition) - and while transmitting "logical-1"s, thus charging C2 via D3 to a negative auxiliary charge. Unfortunately, when transmitting "logical-0"s, TxD will rise to +12V, and worse energy balance for that negative auxiliary voltage. Yet, in many realworld configuration of hardware and protocols, this proposed method of gaining auxiliary voltages works pretty well! Transmit TxD to TxD-TTL (µC input) Depending on the actual state of TxD, there is always one of two antiparallel transmit-LEDs in PC1/PC2 active. Thus, at TTL-side, only one phototransitor becomes conductive at the time. It triggers either the "set" or "reset" input of a discretely wired R/S-flipflop (IC1a/b). On the output we now have clean, sharp-edged digital pulses. Regenerated TxD-TTL is led to the output line (pin 2 of X2: TxD-TTL). Receiving RxD from RxD-TTL (µC output) Switching either positive voltage with PC3 or negative voltage with PC4 directly to the RxD-input recreates a bipolar data signal for RxD. At the TTL side, logic levels coming from the controller (pin 3 of X2: RxD-TTL) are buffered and inverted by IC1c and once again by IC1d to drive transmitting-LEDs in PC3/PC4 in push-pull mode. Power supply This is +5V connected to Pin 1 (GND) and Pin 4 (+5V) of X2. The source should comply with basic TTL requirements. Power consumption on the TTL-system of the RS232TTL coupler is about 20mA. Parts
PCBBelow is my layout suggestion for Isolated RS232-TTL-Converter as a module. Should be no hassle to build on a veroboard, but take care of the D-SUB-pinning which is in fact no 2.54mm grid...I strongly recommend the use of high quality sockets for all semiconductors.
RemarksMeasuring the voltage level at plus pole on C1 and minus on C2 against serial GND should indicate something around +6...12 Volts resp. -6...12V against serial GND (see Pic. 2), when serial port was opened by regular software. Testing with Scope on the following signals: Regenerated RxD at RS232-site. It should not "underrun" +/- 6 Volts while data is received from the TTL-side (as mentioned before, minimum shift would be +/-3V). Other interesting measure points are the collectors at PC1/PC2. When DTE transmits data, you should see a ground-referred, "almost digital" pulses. Due to the finite steepness of the photocouplers, the signal might get softer with higher transfer speed - nothing to worry about, since the following RS-Flipflop will always regenerate some sharp-edged, debounced digital waveform for TxDTTL, as long as the input was reasonably symmetric. Functional testing is really quite simple. Connect the RS232TTL to the computer's RS232, connect TTL site with stabilized 5V supply, and short-circuit TxDTTL with RxDTTL. This "loopback" will receive every character coming from TxD and immediately send them back to the computer via RxD; by way of all the optocouplers, signal regeneration and driver stuff. Other couplers... Considerations LinksDatasheet CNY17-XOverview RS232 Complete RS232 coupling, the hard way... © 2004/2005 Julien Thomas - revision: 12/2005 |