As in the title, Is it possible to use the CD4066 as level driver through RS232 and TTL(USART)? If it's possible how this work. Thanks.
The answer, once again, is "it depends".
Figure 1. RS232 signal levels can be up to ±25 V. Source: 8051 projects.
- RS232 signal levels are bi-polar.
- Generally CMOS devices such as the CD4066 are used on single-ended supplies but the 4066 can be used on dual supplies of up to ±10 V but recommended limit is ±7.5 V and the switched signals would have to stay within that limit. You would be unfortunate to connect to a device that generated more than 7.5 V for switching but it could happen and the 4066 could be destroyed.
- Switching the CD4066 in this configuration becomes awkward as the switching logic now has to switch between +7.5 and -7.5 V so logic level conversion is required.
- The 4066 switches for the transmit signal would have to switch between +7.5 V and - 7.5 V to generate the transmitted signals.
- The received signal would also have to be level shifted and inverted.
In short, you will have a very complex circuit requiring:
- Voltage boost power supply for 'space' signal.
- Negative voltage power supply for 'mark' signal.
- Logic level conversion from TTL to RS232.
- Withstand ±25 V on the RX pins.
- Threshold discrimination (the ±3 V region in Figure 1).
Fortunately all these issues were solved by Maxim in 1987 when they brought out (you've guessed it) the MAX232. It's so good it is silly to consider any other way of doing it for true RS232 communication.
Figure 2. MAX232 pinout. Add four small capacitors for the voltage generators, a 5 V supply and you're done! Source: MAXIM
Firstly a MAX232 has both transmit and receive functions so a CD4066 won't work in any way as a receiver because the likely receive voltages it might see could be +/- 15V and this is way beyond the maximum power supply rating of 20V for this device.
As a transmitter it could work because, if you look at the MAX232 spec, it only generates typically +/- 7V on the RS232 transmit side. However, if someone misconnected the port wiring it could easily be destroyed if the receive wiring (potentially capable of +/-15V from some devices) were conencted to the output of the CD4066.
I'm not ruling out that some form of protection could be employed but it's all getting messy so, unless you have a convincing reason to use a CD4066 I would say "no".