In the last article, we introduced the download process of STC microcontroller, and mentioned that the program download of STC microcontroller adopts a unique serial port burning method, and the program burning function is realized through the UART port of the microcontroller. However, the laptops we all use cannot communicate directly with the serial port of the microcontroller. To realize the communication between the microcontroller and the laptop, we need to use a USB serial port conversion chip, which can realize the conversion of the USB communication protocol and the standard UART serial communication protocol, and then realize The communication function between the microcontroller and the notebook computer. CH340G is a USB bus adapter chip, which can realize USB to serial port, USB to IrDA infrared or USB to print port. It is a relatively mature domestic chip, and the price is relatively cheap. It is also the most used solution for USB to serial port. Its circuit principle is shown in the figure below.
In the circuit, the TXD of CH340G is connected with the RXD of the single-chip microcomputer, and the RXD of the CH340G is connected with the TXD of the single-chip microcomputer. The VCC of CH340G is connected to the output VDD of the USB interface, which is 5V power supply. VD+ and UD- are connected to the USB data bus. In addition, the CH340 series requires an external crystal oscillator chip, and an external 12MHz quartz crystal. The bypass capacitor can choose a 22pF monolithic or high-frequency ceramic capacitor. In addition, it should be noted that when the 5V power supply is used, the V3 pin needs to be connected to a 104 capacitor to the ground, and a 0.1uf filter capacitor (ordinary capacitor will do) is added to VCC and GND.
As mentioned in the previous article, the download of the single-chip microcomputer should be completely powered off and cold-started, so it must be noted that the power supply of the CH340G and the power supply of the single-chip microcomputer are separated. controlling. In addition, it should be noted that for the download circuit, attention should be paid to the situation that the MCU is not completely powered off due to current inversion. Therefore, in the circuit design, a reverse diode can be connected to the transmit pin TXD of the CH340 chip, and then connected to the opposite end IC. , as shown in D1 in the figure, the unidirectional conductivity of the diode D1 is used to prevent the CH340G from pouring electricity back into the MCU. Also add a current-limiting resistor R1 to the receiving pin to prevent the opposite IC from charging back the CH340.
The principle of passing the reverse diode is: when the CH340 sends data, the diode is turned off when the high level is sent, but since the default pull-up of the opposite end RXD is also high, there is no sampling problem, and when the low level is sent, the diode is turned on, and the opposite end is turned on. RXD receives a low level, so it can communicate normally. And prevent the TXD sending pin of CH340 from pouring current back to the opposite end IC.
The principle of passing the current limiting resistor is that the reverse current causes the chip to work or even latch up. It is because the pin current is too large and exceeds the upper limit tolerated by the chip design, resulting in an abnormality in the internal circuit of the chip. Therefore, it is enough to add a current limiting resistor, and other communication scenarios can also be tried by imitating this method.
Reviewing Editor: Liu Qing