





The principle and implementation method of USB to serial port
The principle and implementation method of USB to serial port
USB to serial port is a commonly used device. It is often used in the process of code debugging. It is very important to be familiar with this module.
First: Introduction to serial port module
Serial transmission data (USART) is a function often used in STM32 debugging, but the level standard of the computer USB is different from the TTL standard used by the serial port, so a USB to TTL line is required to complete the communication between them.
It can be seen that one end of it is connected to the USB port of the computer, and the other end leads out four DuPont lines for connecting to the serial port of STM32.
Next, plug it into your computer's USB port, without connecting anything on the other end, and start installing the driver.
When you just plug it in, the computer will pop up the option to install the driver by default. At this time, you can click to install the driver (if not, go to the next driver on the Internet)
Then check whether the driver is installed correctly -> right-click "My Computer", click "Properties", click "Device Manager" on the left, if you see the following icon under the "Port" column of the pop-up window, then congratulations, You have completed the driver installation for the USB to TTL cable.
However, if you find a question mark or exclamation mark on the icon, the driver is not installed correctly. Don't be discouraged, the author also had this situation at the time, because win10 will automatically update the driver to the latest version, but there is a problem with the latest version of the driver, which prevents the correct connection. The solution is as follows:
First go to the "Control Panel", find the "Change device installation settings" option under "Devices and Printers" (search directly in the upper right corner), and click it.
Then go to the Internet to find a USB to TTL driver, and then install it step by step. Finally, plug in the USB to TTL cable and go to the device manager to see if the driver is installed correctly.
Second: the basic principle of USB to serial port
1. Serial transmission
The serial port application sends data -> the USB serial port driver obtains the data -> the driver sends the data to the USB serial port device through the USB channel -> the USB serial port device receives the data and sends it through the serial port
2. Serial port reception
The USB serial device receives serial data -> uploads the serial data to the USB host after packaging the serial data through USB -> the USB serial driver obtains the serial data uploaded through the USB -> the driver saves the data in the serial buffer and provides it to the serial application for reading
Third: the characteristics of the serial port of the microcontroller and the USB to TTL line
Look at the end of the patch cord, there are four Dupont wires of different colors. they are, respectively:
Red—>VCC
White—>RX receiving end
Green—>TX sender
black -> ground
The serial port on the microcontroller is generally two ports, one is the TX transmitter and the other is the RX receiver.
When connecting, pay attention to the cross interconnection, that is, connect the RX end of the USB to TTL line to the TX end of the microcontroller, and connect the TX end to the RX end of the microcontroller, and the remaining two pins do not need to be connected.
Third: programming + testing
There are many tutorials on the Internet to write the serial port program, and different microcontroller programs are different, so I won't repeat them here. The following is part of the code written by the author, set the baud rate to 9600, and burn the program to the microcontroller
Then connect the microcontroller and the computer through the USB to TTL cable, and open the serial debugging assistant (there are many versions available for download on this website).
Open the serial port in the serial port debugging assistant, and set the baud rate to be the same as in the software. Then you can see the data sent from the microcontroller
USB to TTL cable
USB to serial port module
Serial port of the microcontroller and the USB to TTL line
Copyright 2020 Premier Cable CO.,LTD Suport:300.cn Dongguan 粤ICP备2020142126号