News Center

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:


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



Related News

What is a terminal block used for?

While there are many factors to consider when designing an overall system, terminal blocks are an optimal solution for complex electrical system connections. With a variety of color options and configurations, Premier Cable’ terminal blocks offer a range of options to meet your design challenges.

CANBus Applications

CAN-bus has been widely used in various automation control systems. For example, CAN-bus has incomparable advantages in various fields such as automotive electronics, automatic control, smart buildings, power systems, and security monitoring.

Introduction to M12 connector pin coding

M12 encoding types are A encoding, B encoding, D encoding and X encoding. A-code, B-code and X-code are some of the earliest developed and longest-available M12 connectors. The latest M12 coding types currently under development are K coding for AC and L coding for PROFINET DC.

Cables – What are the correct cable sizes for an NMEA 2000 network?

The three different sizes of NMEA 2000 certified DeviceNet standard cabling are "micro," "mid," and "mini."

What are the advantages of NMEA 2000?

The Premier Cable Starter Kits provide everything you need to get to create a basic NMEA 2000 network from scratch.

The role of DeviceNet terminal resistor

DeviceNet_network is a fieldbus network protocol based on Controller Area Network (CAN). In the DeviceNet network, the terminal resistor plays the role of compensation and protection for signal transmission. The function of the terminal resistor is to eliminate signal reflection and interference and ensure the signal transmission quality.