Connecting a microcontroller to RS-232 ports

and PS/2 devices - v. 1.1

You are the visitor n.

Fare click qui per la versione Italiana

Best view with 1024x768

     
 
 
A PIC 16F877 microcontroller connected to a PS/2 mouse and to a PC; the circuit, on the left in the two images, is a version (v. 2.1) built after the one described on this page, with more TX/RX channels and a few LEDs, and at the moment it is under test; on the oscilloscope, PS/2 data and clock are displayed.
 
 
Back to Home page

E-mail address

Similar topics on this site:

PIC 16F877 Development Board v. 1.2
PIC - PS/2 mouse interfacing and communication
Keypad 4x5 for microcontrollers
 
 
Circuit's characteristics

On this page a simple circuit is described, allowing to interface a microcontroller to a PS/2 device and to the serial port of a PC, working at RS-232 levels. On the board also four pushbuttons are available, whose logic level can be read by the microcontroller and therefore used as an user input. Concerning the value of protection resistors for the PS/2 connector and for the RS-232/TTL adapter (see schematic further), the circuit have been designed for the PIC 16F877 microcontroller. Being anyway the circuit simple, and resistors' value not critical, it should be suitable also for other PICs and other microcontrollers, too. On this page, we'll refer to the PIC 16F877.

The circuit must be fed by a +5 V supply; should the supply be different, the RS-232 interface could work not properly, and the PC serial port and possibly also the microcontroller could be damaged; also the PS/2 mouse could be damaged. The microcontroller and the circuit must be connected to the same supply pins (Vdd = +5 V, GND); should the microcontroller receive a different supply, its ports connected to the circuit could be damaged.

For a few informations about communication with a PS/2 mouse, you could have a look at PIC - PS/2 mouse interfacing and communication on this site.

Concerning the communication with the RS-232 serial port, the well.known TTL/RS-232 adaper MAX 232 is used. Up to four channels can be used, two as input and two as output. The microcontroller can be interfaced with the 232 serial port with a great freedom, as the nine RS-232 signals are available on two connectors; the four I/O channels of the MAX232 are also available on two connectors; in this way, through simple wires, soldered wires, or wires ending in a connector, up to four TTL ports of the microcontroller can be connected to some of the RS-232 signals.(two as input and two as output). Typically, two channels will be TD and RD; the others two available channels can be used as an instance to manage RTS and CTS, DTR and DSR or DCD, RI. The use of connectors also allows the "simulated" handshake, as an instance connecting DTR to DSR etc..

 
 
The circuit version 1.1

Acknowledgement and disclaimers

PIC and Microchip are registered trademarks.
Being this material at free disposal of whoever desires it, it is absolutely forbidden any form of use for commercial purposes.
The electrical schematic for TTL - RS-232 conversion is well known. The same can be said concerning the read of logic levels of pushbuttons. The design of the printed circuit board is instead entirely personal, though I guess similar circuits can be found on the net. If, in whichever way, you wish to use this layout not just for personal purposes, or to divulge the material on this page, it is compulsory to ask a written permit to the author of this article (also by e-mail).
Any small change of the layout is also forbidden if not for didactical or personal purposes; should small changes be made, they must not take to any form of direct or indirect profit.
If, in whichever way, you wish to divulge such small changes, it is compulsory to ask a written permit to the author of this article (also by e-mail).
It is obviously allowed to make great changes at the layout, for any purposes.

The schematic, the circuit's layout and all the informations contained in this page are supplied "as they are", without any form of warranty. I don't assume of course any direct or indirect responsibility for direct or indirect damages to things or person coming from informations got from this article.
As an instance, though I have placed protection resistors in the circuit, I don't assume any responsibility for any possible damages to microcontrollers, PS/2 devices, PCs or their serial ports.
Suggestions of any kind to allow me to improve the circuit are well accepted.

In any case, be always aware of what you are doing!

The circuit has been designed with TARGET 3001! Light (400 pins license). It's a cheap and in the same time powerful PCB CAD.

The circuit

Note: the images on this page are low resolution ones (100 dpi). To have the same images, but at 300 dpi, in a new window, where you can print or save them, you can click directly on images on this page or on the links below each one. Further, in the section "Images needed to build the circuit", you can find all together the links to save 300 dpi images.

As you can see below here, the nine RS-232 port's signals are available on the K5 connector. The signals' direction are showed by the arrows near connecotrs' pins. Between K5 and K6, 330 Ohm protection resistors are mounted. The signals on K6 you wish to connect to the microcontroller must be connected to the proper pins of K7 and K8 (RS-232 levels); on K9 and K10, connected to the MAX 232 through protection resistors, you find the TTL signals corresponding to those on K7 and K8. The microcontroller should therefore be connected to K9 and K10. The two connectors K5 and K6 allow to make proper wiring for the "simulated" handshake: as an instance,you could connect DTR on K6 to DSR on K6 or K5, so placing between DTR and DSR a 2*330 Ohm resistor in the first case and a 330 Ohm resistor in the second one. Please read further the notes about protection resistors.

Here components placement and tracks view at 300 dpi

The supply, the same one of the microcontroller, must be connected to the K3 connector. As previously said, if supply provided to the board is not the same provided to the microcontroller (the same Vdd and Vss pins), the microcontroller could be damaged. If supply is not +5 V, the devices connected, that is the PS/2 mouse and the PC serial port, could work not properly or even being damaged. The K12 connector allows supply to be fed to other circuits.
Please NOTE: signals' name from 1 - DCD to 9 - RI in the components placement and tracks view image (just above here), refers to K5 connector's pins, on the left of names themeselves; numbers 1-9 of those signals are also the same of the physical numbering of K4 (SUB-9) connector's pins, as pins of K4 are numbered from 1 to 5 in one row and from 6 to 9 in the second row, but, please, note that in the schematic (further) the form of the SUB-9 connector and the pins' numbers, in a rising order and in alternate rows, it's not the same of the physical connector. In any case, to use this circuit you should refer to signals on K5 and K6, without taking care about the real SUB-9 connector's pinout.

On the K2 connector Clock and Data signals for PS/2 communication are available.

On the K11 connector the logic levels of the four pushbuttons are available; they are normally high, because of the pull-up; pressing a pushbutton, the related pin is brought to a low logic level.

Remarks about protection resistors

Protection resistors R1, R2, R13, R14, R15, R16, R17, R18, R19, R20.

They limit the current sourced/sunk by microcontroller's ports in case of improper wiring or wrong programming of I/O pins; the maximum current is about 5 V / 330 Ohm = 15 mA. If your microcontroller can't source/sink such a current, you must increment resistors' value. In some microcontrollers, also exist a maximum value of sourced/sunk current for a given set of ports: as an instance, with improper wiring and programming mistakes, having 15 mA sourced/sunk by the up to ten ports that it is possible to connect to this circuit, the maximum current rating could be overcome.

Protection resistors R5 to R12.

RS-232 electrical specifications set that devices must tolerate a short circuit, and that in such event the current must be limited. Protection resistor R5 to R12, in this case, should not be necessary. For precaution reasons, anyway, I have decided to insert protection resistors, whose value (330 Ohm) must be considered just a starting basis, and not the proper value for every RS-232 port. You should know that, implementing a "simulated" handshake by direct interwiring on the pins of K5 connector, in case you make a mistake, a RS-232 output pin could be connected to ground or to another output pin, therefore realizing a direct connection between something like +15 V and -15 V. In this case, the RS-232 drivers inside the PC should limit the current, but, cautiously, it is better to interwire pins of K6, or interwire pins of K5 and K6. The same for signals to be connected to K7 and K8, which, coming from K6 instead of K5, can pass through protection resistors R5-R12. PLEASE NOTE that the maximum current in case of improper wiring could be about (15 - (-15) ) V / 330 Ohm, that is 90 mA; if the driver limits current (and in this case protection resistors are probably not necessary), there will be no consequences; if the driver does not limits current, the value of 90 mA could be too high for the driver itself. In this case, it is necessary to increase the value of resistors. Protection resistors protects in the same way the MAX 232, too.

Please, pay attention: increasing too much the value of resistors R5 - R12 could lead to a wrong reception; the RS-232 standard sets a receiver input impedance between 3 KOhm and 7 KOhm; connecting as an instance DTR and DSR, and using a 3 KOhm protection resistor, voltage on DSR could even arrive at the half of that on DTR, maybe going outside noise margins; in case of improper wiring, anyway, current would be limited to about 30 V / 3 KOhm = 10 mA. It's up to you to chooes the right value depending on the 232 drivers of your PC and on the TTL-232 adapter you mount on the circuit.

In order to test possible changes in the waveforms caused by protection resistors, I have converted TD to TTL levels, sent it back to the first TTL input channel connecting together the two pins of K9, and connected to RD the first MAX232 output channel, that is, in short words, to connect TD to RD after two level conversions. Serial communication has been tested in the following conditions: 330 Ohm protection resistors, 115200 bps, TD on K6 connected to K7 (1 <--), pin 1 <-- of K9 (that is, TD converted to TTL levels) connected to 1--> of K9, and 1--> of K7 (that is TD converted back into 232 levels,) connected to RD on K6; the oscilloscope has displayed a small change of the RD waveform, but not enough to leave noise margins, and, testing hundreds/ thousands bytes, exactly what has been transmitted has been received (01010101 B).

Here the 300 dpi schematic

Components list

Note: all resistors are 5% ones.

C1-C2-C5 10µF ELKO2.5-6 50 V
C3-C4 1µF ELKO2.5-6 50 V
C6 100 nF MKS2.5X7.2
C7 47µF ELKO2.5-6.3 50 V
R1, R2, R5-R20 (18 off) 330 Ohm 1/4 W
R3, R4, R21, R22, R23, R24 4.7 KOhm 1/4 W
IC1 MAX232 DIL16
K1 MINI DIN 6-PINS connector
K2, K3, K7, K8, K9, K10, K12 2-pins 2.54 mm step connector
K11 4-pins 2.54 mm step connector
K5, K6 9-pins 2.54 mm step connector
K4 sub-D-9-pins female connector, P.C.B. mounting
S1, S2, S3, S4 7 x 10 mm pushbutton, P.C.B. mounting
80 x 100 mm single sided board (75 x 100 mm is also O.K.)

Here the 300 dpi silkscreen

Here the 300 dpi layout

 
Images needed to build the circuit

If you wish to build this circuit (after you have read the section "Acknowledgement and disclaimers"), you can find here the links to the images you need (at 300 dpi), images you can anyway view and save in other sections of this page.

Components placement and tracks view at 300 dpi (187 KB)
Schematic at 300 dpi (158 KB)
Components placement (silkscreen) at 300 dpi (140 KB)
Copper side layout at 300 dpi (128 KB)

 
 
 

If you wish, just send me your opinion (even in an anonymous form)

   
Your country

I think this circuit is

Useful

A little useful

Unuseful

It would be good to find the PCB already made

Yes

No

Your comments

If you wish an answer, please include your address

   
 
 
 
Buon lavoro!
 
 
Circuit designed with
 
 

If you wish to contact me for informations and suggestions:

f_iacopetti@libero.it

 
Last update: 17 November 2003, 20.40 HyperCounterHyperCounter