USB To UART Serial Port Module CP2102

Overview

This product is used for USB to UART. This serial port module is a convenient and powerful electronic product designed for communication with a computer and a UART serial port device through a USB interface. It adopts high-quality CP2102-GMR chip, which has reliable performance and stable data transmission capability. It supports multiple operating systems, including Windows, Mac, and Linux, etc., providing users with extensive compatibility. No additional drivers are required, and the plug-and-play feature makes the use process easier and more convenient. Support baud rate from 300bps to 1Mbps, which can meet the needs of most serial communication. It provides a standard UART interface, including TX (transmit) and RX (receive) lines, and also has CTS (clear to send) and RTS (request to send) lines for more flexible control of data flow.

Parameters

Supply voltage5V(from USB Type-C)
Logic voltage3.3V
Serial communication interface chipCP2102-GMR
Baudrate12Mb/s(MAX)
Size45mm(Length) x 20mm(width)
Weight4.2g

Resource Profile

① Onboard power indicator

②&⑥ Reserve 2.54mm pitch control pin pad

③ TXD LED indicator

④ UART(TTL) interface pin header

⑤ RXD LED indicator

⑦ 3.3V/5V voltage output level switching slide switch

⑧ USB Type-C connector

Usage

UART interface description

VOUT5V or 3.3V(switching with slide switch)
GNDGround
TXDSerial data transmit pin, connect to MCU.RX
RXDSerial data receive pin, connect to MCU.TX
RTSRequest to send, used to control data sending, connect to MCU.CTS
CTSClear sending for controlling data sending, connect to MCU.RTS

Computer driver installation

Open the following official website:

https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers

Then select "DOWNLOADS" at the bottom of the page, you can see the driver software download for the corresponding operating system, as shown in the figure below:

SG-C2102-01C

Raspberry Pi configuration and testing

Raspberry Pi Hardware Interface Configuration Instructions

1. Connect one end of aUSBdata cable directly to a USB port on the Raspberry Pi.

2.Connect the other end of theUSBdata cable's Type-C port to the Type-Cconnectorof the module.

3. Use dupont cables to connect the TXD and RXD pins of the module together.

4. On the Raspberry Pi terminal, run the following command to check if the device is recognized:

lsusb

After running the command, the Raspberry Pi terminal displays the following.

SG-C2102-01C

Then run the command to view the recognized serial port number.

ls -l /dev/tty*

The terminal displays the following,ttyUSB0 is the recognized serial port number;

SG-C2102-01C

Run the command to view the baud rate of the serial port (note: the USB number here is written according to the USB identified above).

stty -F /dev/ttyUSB0

The terminal displays the following:

SG-C2102-01C

Run the command to view the serial port connection information.

dmesg | grep ttyUSB0

The terminal displays the following:

SG-C2102-01C

Enter the following code to test the UART to serial port module.

SG-C2102-01C

Demo code analysis:

pi@raspberrypi:~ $ python3 # open editable interface
Python 3.7.3 (default, Oct 31 2022, 14:04:00)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import serial # import the module
>>> ser = serial. Serial('/dev/ttyUSB0',115200,timeout = 0.5) #Set parameters: serial port number, baud rate, read time
>>> ser.isOpen() # determine whether the serial port is open
True # serial port is open return True, otherwise return False
>>> ser.write('123456'.encode()) # input data, data can be input multiple times
6# read returns the number of bytes written
>>> ser.inWaiting() #Read the total input bytes
6# return, display the accumulated number of bytes
>>> ser.read(6) #read six bytes, assuming a total of 24 bits of data are input, this time the first six bits will be output; if changed to ser.read(24) then only the input 24 bits will be output data

Computer and Raspberry Pi Connection Test

The computer is connected to the module through a USB data cable, and the module is connected to the Raspberry Pi through a Dupont cable. The wiring method is as follows:

Module -> Raspberry Pi

GND -> GND

TXD -> RXD

RXD -> TXD

Run the command to view the serial port

ls -l /dev/*serial*

The terminal displays the following

SG-C2102-01C
The default serial port is serial0 mapped to ttyS0, that is, the main serial port points to the mini serial port, but the efficiency of the mini serial port is low and unstable, so here we need to point the main serial port to the hardware serial port, which is ttyAMA0; enter the command in the Raspberry Pi terminal to open config.txt file.sudo nano /boot/config.txt
sudo nano /boot/config.txt

Add the following two lines at the end of the config.txt file.

dtoverlay=pi3-miniuart-bt
force_turbo=1

The terminal displays the following:

SG-C2102-01C

Then save and exit. At this time, open the terminal again and enter "ls /dev -al", you can see that the serial port mapping has been forcibly changed, and the main serial port Serial0 has pointed to the hardware serial port ttyAMA0.

SG-C2102-01C

Computer and Raspberry Pi Connection Test

Open the terminal, enter "sudo apt-get install minicom" and wait for the installation to complete. After the installation is complete, the terminal displays the following:

SG-C2102-01C

Enter the command in the terminal: "minicom -D /dev/ttyAMA0 -b 115200" to open the serial port assistant.

Here -D /dev/ttyAMA0 points to the serial port number we opened, which is the same as COM1. -b 115200 is the configuration baud rate. We can enter Ctrl+A in minicom to see it below. For our baud rate, if -b is not set, the baud rate will be 115200 by default.

SG-C2102-01C

Run minicom -D /dev/ttyAMA0 -b 115200 to enter the serial port tool.

SG-C2102-01C

(1) First press Crtl+A in the minicom serial port, then click Z to enter the help option:

(2) Click O to enter the Configure Minicom option;

(3) Select the Serial port setup option, press F to change Hardware Flow Contorl to No; that is, disable the hardware flow, and then exit. All configurations have been completed here, and then you can verify it.

Go back to the computer side, open the serial port debugging assistant on the computer side, and set the serial port parameters at both ends to be the same;

SG-C2102-01C

If your minicom input is not displayed, press Crtl+A, then press E to open the echo function.

The computer side can send a series of data, but the Raspberry Pi side can only send data one by one, and will not automatically wrap;

When opening the minicom serial port assistant, if you got unresponsive keyboard input, you can refer to the following. But if you do not got this situation, you can skip this section.

Check the documentation and find this Note in the documentation:

Note: If you haven't configured minicom before (i.e: first use after installation), or if you find that your keyboard key presses are not sent to the RPi, you should make sure Hardware Flow Control is disabled. See Tedious Old-Fashioned Way Using

It reminds us to make sure to disable hardware control flow, and follow the documentation.

Resources

Schematic

Product

Data Sheet

CP2102-GMR

Software

Serial port assistant for PC

UartAssist.exe

PL2303 series chip and driverdownload:

https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers

Technical Support

Technical Support and Product Notes