With the development of technology, RS232 serial communication is still widely used in industry. However, in commercial applications, the USB to UART technology has gradually replaced RS232 serial ports. Most laptops no longer have serial ports. So, how can we achieve communication between a microcontroller and a computer?
We only need to add a USB to serial chip to the circuit to successfully convert between the USB communication protocol and the standard UART serial communication protocol. On our development board, we use the CH340T chip, as shown in Figure 11-5.
Figure 11-5 USB to Serial Circuit
In the lower left corner of the figure, J1 and J2 are two jumper combinations. You can find them at the lower left position of our board. We need to short the middle and lower pins together with a jumper cap. The circuit on the right side with the CH340T is very simple. After connecting the power supply and crystal oscillator, connect pins 6 and 7 (DP and DM) to the two data pins of the USB port. Pins 3 and 4 are connected to the TXD and RXD of our microcontroller via jumpers.
A small trick in the CH340T circuit is to add a 4148 diode at pin 3. This is because the STC89C52 microcontroller requires a cold start when downloading programs, meaning you have to click download before powering on. At the moment of powering on, the microcontroller will first check whether it needs to download a program. Although the microcontroller’s VCC is controlled by a switch, since pin 3 of the CH340T is an output pin, without this diode, when the switch is off, pin 3 of the CH340T and pin P3.0 (RXD) of the microcontroller are connected, causing current to flow into the subsequent circuit and charge the capacitors, resulting in a certain voltage in the subsequent stage. This voltage, although only around two to three volts, can affect the normal cold start. By adding the diode, it does not affect communication and can eliminate this undesirable effect. This part can be understood temporarily. If you are making such circuits yourself, you can refer to this.