zondag 16 november 2008

Serial port for input


To allow a microcontroller to read from a serial port (but not write to it) is relatively simple. In principle it is a matter of hooking up a 10 kOhm resistor from the output of the serial cable to any pin of the microcontroller, at which point the microcontroller can read the incoming data using software (note that this could push the microcontroller outside of its specification, as you're using the protection diodes for another purpose). Usually, however, one does not want to rely on software to do the reading, as this is slow, time consuming and prone to errors. Most PIC microcontrollers, including the PIC16F628A, have a so-called UART, which handles the reading and writing of serial ports. Unfortunately you can not use the resistor trick in this case, as the signal is inverted and the UART can not handle an inverted serial signal. Fortunately a simple RTL circuit can solve two issues: the illegal use of the protection diodes inside the microcontroller and inverting the signal so it can be properly read, and this with only one additional transistor and resistor.

The provided circuit can handle almost any serial port, even if the voltage is out of specification. It assumes a male connector, for a female connector it needs to connect to pin 3 (as this is a read operation there is no problem if you make a mistake). Note that transistors are much slower at inverting than regular inverters, and that you should therefore not use very high baud rates.

2 opmerkingen:

Boog zei

What kind of baud rate is too high for RTL inverters?

Maarten Hofman zei

It depends on your transistor's switching speed. I would become worried at 200 kb/s, but it might already fail below that speed. I've never really looked into it, but I have noticed occasional failures at 250 kb/s.