Practical PIC Projects

 

 

Simple RS232 to
 logic level converter

for PIC micros / TTL / CMOS

 

 


The circuit shown will convert logic level voltages to and from RS232 serial voltages levels.

For basic serial comms between a Microchip PIC and a PC or other device you generally only need to connect the Gnd, Txd and Rxd lines.

This little circuit will work with a supply voltage of 3.3v to 5v making it ideal for interfacing with a PIC 

It derives the negative supply for the RS232 transmit data from the serial RS232 receive data line in a parasitic fashion.  This means that the device it's connected to must use voltage levels within the RS232 specification. You can't for example connect two of these back to back since nothing is supplying the negative voltage.

The RS232 physical specification gives a logic 1 at the receiver input as -3 to -25 volts and logic 0 as +3 to +25 volts.  You may find that the reliable transmission over long cables, especially in electrically noisy environments with a 3.3v supply is not possible.

We've successfully used this circuit to transfer a 1.6Mb Linux kernel to a router at 115Kbs using a 3.3 volt supply without any errors through several metres of cable.
 

Schematic in PDF format

Similar designs to this appear on various websites on the Internet and I believe the original design appears in AN-681 from National Semiconductor, 1990 

 

 


Operating notes

The 100nF capacitor is used to generate the -12V supply for transmitting data back to the host.  It is charged from the host computers transmit signal coming into the adapter via the 1N4148 diode. 

This can cause a few issues:

  1. If data is being transmitted and received simultaneously, the voltage on the 100nF capacitor may drop below the minimum required by the RS232 standard and this will cause problems receiving data sent from the adapter to the host.
     
  2. Since the capacitor is connected via the diode directly the hosts transmit signal, at high bit rates the 100nF capacitor may cause the signal to be distorted to such an extent that it can't be received correctly, in which case try changing the 100nF capacitor to a 47nF or even 22nF.  If communication is strictly half-duplex you may not need the capacitor at all.
     
  3. If the host transmits a lot of zero (null) data in a stream, the capacitor will discharge because in RS232 zero bits are sent as a positive voltage and ones as a negative voltage.  Since the circuit needs the negative voltage to charge the capacitor, this will also cause problems when transmitting data back to the host.

For many applications this is a quick and simple way to interface to an RS232 port, however it isn't a universal solution, therefore if it works for you all's well and good, if not time for a MAX232 or a similar.

 


The circuit is so simple you can construct it on some strip board, or even wire it up ' birds nest' fashion. However, for a professional job I've done a PCB layout for it because it's quite a useful adapter to have around.

On the 4-pin connector the signals are:

  1.    +3.3 to +5 volt supply
  2.    Transmit data from PIC
  3.     Receive data to PIC
  4.     Supply Ground

On the 9-way D-connector the connections are:

   2.     RS232 transmit data out
   3.     RS232 receive data in
   5.     Signal Ground

A component overlay is shown above. The original artwork is available here as an Eagle PCB CAD .brd file and also in PDF format.

The layout is designed for 1/8 watt resistors - these are a bit smaller than the standard 1/4 watt parts.  You can use 1/4 watt resistors but you'll need to stand them on end.

The two transistors aren't critical, any general purpose devices could be substituted for the parts shown.


Here's a couple of photo's of a completed board. Note the very small 1/8 watt resistors. 

Also notice the blue jumper on the 4-way connector. This shorts the RxD and TxD signals together forming a loop-back for testing 

Hook the board up to a suitable power supply, then connect to a PC running a terminal emulator. With the loop-back in place anything you type at the terminal should be echoed back.

(click on images for large version)