News Center

The principle and implementation method of USB to serial port

www.premier-cable.net


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

 


 

Related News


10M Quad MATE-AX & HFM Mini FAKRA 4-in-1 Cable Assemblies Now Available – Stock Ready, No MOQ

The 10M Quad MATE-AX & HFM Mini FAKRA 4-in-1 Cable Assemblies is ideal for connecting cameras, sensors, radar modules, area controllers, and domain control units in modern vehicles, buses, coaches, passenger buses, trucks, and commercial transportation systems.


7/8" Power Cable Solution for AGV and AMR Robotics Applications

Premier Cable’s DeviceNet 7/8" power cables for AGV and AMR robots, deliver the stability, durability, and flexibility required for next-generation robotic systems. Start Your Custom Cable Project Today! Get reliable power solutions for your AGV or AMR system!


GMSL Camera Cables Solution for Automotive In-Vehicle Developer System and Robotic

Looking for reliable and customizable GMSL camera cables? Premier Cable provide GMSL, GMSL2, and GMSL3 camera cable with Fakra and Quad Fakra, customizable for NVIDIA DRIVE AGX Thor Developer Kit, automotive, unmanned vehicles, robotics, AMR, and smart cities.


Premier Cable MATE-AX & H-MTD GMSL Ethernet Cable for NVIDIA DRIVE AGX Thor Developer Kit

Premier Cable provide custom MATE-AX & H-MTD breakout cables for NVIDIA DRIVE AGX Thor, supporting humanoid robots, machine vision, Industrial Vehicles, Robotics, and Autonomous Machines.


How H-MTD Cable Empower Robotaxi and Autonomous Driving Systems

H-MTD cable assemblies enable high-speed automotive Ethernet for Robotaxi, supporting cameras, LiDAR, and ADAS with customizable solutions.


Premier Cable Launches TE 282762-1 2 Way Automotive Cable Assembly

Premier Cable introduces the TE 282762-1 AMP Junior Power Timer automotive wiring harness, customizable, and widely used in sensors, fuel injection, ignition systems, and turn signals.