Occasionally, when designing with microcontrollers, it’s necessary to include a bidirectional serial communications capability, but, only a single I/O line is available. This situation can be accommodated, though, if the transmission and reception directions are well defined. In other words, the microcontroller system and the peripheral system should work as a transmitter/receiver pair or vice versa, and never as a transmitter/transmitter pair.
An RS-232 driver like the MAX232 needs to be included in the design to meet the requirements specified for EIA232-C voltage levels. The TTL-side of this interface driver enters into a single microcontroller line (see the figure). Only resistor R has to be determined to detect the incoming data and the transmission within the proper voltage range possible. The possible scenarios are as follows:
- The microcontroller tries to output a low to the RS-232 driver. For this situation, the current flowing into the microcontroller must be maintained at less than its maximum specification (see Equations 1 and 2).
- The MAX232 outputs a low at the TTL side. For this scenario, R must hold a value that keeps the input voltage of the microcontroller under its VILMAX level (see Equations 3 and 4).
- The microcontroller tries to output a high to the RS-232 driver. This case is not a concern, since both R and the 5k internal resistor pull up the input of the RS-232 driver.
- The MAX232 tries to output a high to the microcontroller. This is exactly the same as the previous case.
When using a MAX232 line driver and a PIC microcontroller, R needs to be between 263 Ω and 476 Ω. A value of 370 Ω lies in the middle of these two, and thus is a good choice.
Finally, a software consideration must be taken into account: Any data transmitted from the peripheral system to the microcontroller will also be received by the peripheral. This feedback may be used to check data corruption or it simply can be discarded.