I am using NXP P89LPC954 Microcontroller in my design.It has two UART ports. As it is known that UART are point to point connections between two devices. Hence i can only use two devices to connect to the two UART.

Now if i want to connect third device to the microcontroller is it possible to use normal I/O pins as UART pin through a MAX232 driver. If so what should the microcontroller code contain to make the pin act as UART TXD or RXD.

  • 1
    \$\begingroup\$ It's called bit-banging \$\endgroup\$
    – Andy aka
    Sep 27, 2015 at 13:18
  • \$\begingroup\$ Or use an external multiplexer. \$\endgroup\$
    – jippie
    Sep 27, 2015 at 13:41
  • \$\begingroup\$ You don't have to use a UART for point to point communications. You could implement a simple 'bus' with many devices, e.g. RS485. In this case, you don't need to use normal I/O oins to implement a soft 'bit-banging' UART. Also, you don't need to use a MAX232 unless you want 'real' RS232 signal levels. \$\endgroup\$
    – gbulmer
    Sep 27, 2015 at 17:45

1 Answer 1


Of course it's possible. However, it will take significantly more CPU resources than having a UART do all the low level timing for you.

Transmitting is easier than receiving because you own the clock. You know when the leading edge of the start bit is, so you don't have to do any sub-bit timing.

For receiving, you have to synchronize to the leading edge of the start bit. A method I used once is to interrupt on the falling edge when not in a character. This then sets up a timer to interrupt in the middle of subsequent bits. Note that the first interrupt period is 1½ bit times and the remaining intervals 1 bits times. If you know the interrupt latency, you can compensate for it by loading the timer with a shorter value. In the interrupt for the last bit, you turn off the timer interrupt and re-enable the falling edge interrupt, which arms the system ready to receive the next byte.

There are also external UART chips. These can interface over IIC, SPI, or parallel lines. That takes more hardware, but a lot less CPU.

There are lots of methods, each with its own tradeoffs between criteria.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.