When a CP210x device is connected to the USB host, the host will send a reset signal to the USB device to start the enumeration process. After reset, the host will read the USB device’s information and assign a unique address. If USB host has the driver for the device, the driver will be loaded after enumeration done.
Sometimes the USB enumeration may fail because of bad USB signal quality, incorrect USB driver for the specified VID/PID device, etc. So, it is important to check if the CP210x device is enumerated successfully.
This KBA introduces two methods for checking this.
The first way is to execute shell command, the steps are below.
a) Connect the CP210x device to USB host on Linux.
b) Start a terminal on Linux, type “lsusb” and press Enter. There will be one more USB devices, take the CP2104EK as an example, it named CP210x UART Bridge / myAVR mySmartUSB light (it's a wrong name because of Ubuntu OS, it should be "Silicon Labs CP210x USB to UART Bridge") in my case. The hex value 10c4:ea60 represents VID and PID as shown below. The PID and product name may different if the device is customized.
c) Typing“lsusb -d VID:PID -v” and press Enter, it is “lsusb -d 10c4:ea60 -v” in my case. Then the CP210x device descriptor will be printed out on the screen. By checking the descriptor information we should know if the device has been correctly enumerated. However, if all the data is zeroes (0x0000, for example) or if an error is reported, the device did not properly enumerated.
USBView is a graphical user interface application that enables you to browse USB controllers and connected USB devices on your computer. It displays the information on each of the USB devices (like VID, PID, Product String, descriptors, etc.). The driver for the device does not need to be installed or loaded for USBView to read the information, as the utility uses the low-level USB driver to talk to the device. This is useful when a CP210x is not enumerating because of an incorrectly programmed PID.
You can run USBView by double-click a USBView.exe package on Window. But there is difficulty to run it on Linux. This article will explain how to install and run USBView on Ubuntu.
Install gtk3.0
Gtk3.0 is required for running USBView, you can install gtk3.0 by typing below command and press Enter on terminal.
$ sudo apt-get install libgtk-3-dev
Install USBView
The Ubuntu website provides a .deb package and source code of USBView, you can download it from following link: http://manpages.ubuntu.com/manpages/trusty/man8/usbview.8.html. If you choose to install USBView with .deb package, you can finish it just by double-click .deb package. If you want to install it with source code, you should extract the source code package and enter the extracted directory, then follow three steps to install it.
Some CP210x devices include GPIO pins that can be controlled at runtime. This article discusses reading and writing the latch value of these pins with software on different operating system platforms.
On Windows
Before connecting to a device, the host must install relevant VCP driver, you can get the appropriate installation package from the link below:
After installing the VCP driver, the CP210x device is recognized by the host when it was plugged in the host USB port. Silabs offers a CP210x Port Read/Write Example application to read/write GPIO latch at runtime.
Taking CP2104EK as testing platform to show how to read/write the GPIO by the CP210x Port Read/Write Example, the CP210x Port Read/Write Example application can be found in AN223SW. Besides, reading AN223 for more information, you can get both of them from the website here https://www.silabs.com/community. we will write value to GPIOs and then read it back by three steps blow.
Install suitable VCP driver and the CP210x Port Read/Write Example.
Connect the CP2104EK to the USB host. Then, a new COM port appears in Device Manager Window, it’s “Silicon Labs CP210x USB to UART Bridge(COM4)” in my case.
Open the CP210x Port Read/Write Example, the main window of the CP210x Port Read/Write Example contains one section to write GPIO latch and another to read GPIO latch. Below that is a list to select the COM port and display boxes for the device part number, product string, and serial number. Select the correct COM port in the drop-down box at the bottom left of the software. Select GPIO0, GPIO1, GPIO2 and GPIO3, set the pins state as low (0) for each, press the “Write latch” button. The LED DS0-DS3 on CP2104EK turned on. At any time, press the “Read Latch” button can read the current GPIO latch value of the device.
The CP210x Port Read/Write Example illustrates how the GPIO latch can be read from and written to device by using the CP210xRuntime.DLL. You can develop a custom application using CP210xRuntime.DLL, the functions in this API (CP210xRT_ReadLatch() and CP210xRT_WriteLatch()) give host-based software access to the CP210x device’s GPIO latch using the USB connection.
On Linux
The CP210x driver has been distributed as part of the Linux kernel since v2.6.12, and GPIO operations also be supported by Linux 4.10.0 kernel or later.
If you are using an older kernel version, please download the latest Linux VCP driver from link below and merge the GPIO operation related source code into your kernel. The .zip package contains VCP driver and example code show how to control GPIOs.
After merging the VCP driver cp210x.c, compile it with make command and install it with command "insmod ". Note that the command "rmmod cp210x.ko" should be executed if VCP driver already exists before installing the driver that support GPIO control.
In the cp210x_gpio_example.c, use the following function to open a CP210x device.
Use the function below to read latch, where the third parameter gpioread is a buffer address of one-byte length for storing the read latch value.
ioctl(fd, IOCTL_GPIOGET, &gpioread);
The returned read latch value is represented as follows: bits 0–7: Current latch state, where bit 0 is GPIO0, bit 1 is GPIO1, etc. Up to GPIOn where n is the total number of GPIO pins the interface supports.
Use the function below to write latch, where the third parameter gpio is write latch value.
ioctl(fd, IOCTL_GPIOSET, &gpio);
The write latch value that is supplied in the Data phase represents as follows:
bits 0–7: Mask of the latch state (in bits 8-15) to write, where bit 0 is GPIO0, bit 1 is GPIO1, etc. Up to GPIOn where n is the total number of GPIO pins the interface supports.
bits 8–15: Latch state to write, where bit 8 is GPIO0, bit 9 is GPIO1, etc. Up to GPIOn where n is the total number of GPIO pins the interface supports.
Get more information from AN571.
Compile the application with “gcc cp210x_gpio_example.c”, a executable file “a.out” is generated. Execute it with “./a.out”.
On MacOS
The Mac VCP driver v5.0 or later version supports the GPIO control on the CP210x devices. Download the latest driver here:
For using the python, you should install libusb and Pyusb library on your Mac machine, please refer to the following code to write a Python script to control the CP210x GPIO.
import time
import usb.core
import usb.util
PID = 0xea60
VID = 0x10c4
dev = usb.core.find(idVendor=VID, idProduct=PID)
if not dev:
print "CP2104 was not found :("
exit(1)
print "Yeeha! Found CP2104"
reqType = 0x41
bReq = 0xFF
wVal = 0x37E1
while True:
wIndex = 0xffff
print "toggling On"
dev.ctrl_transfer(reqType, bReq, wVal, wIndex, [])
time.sleep(5)
print "toggling Off"
wIndex = 0x00ff
dev.ctrl_transfer(reqType, bReq, wVal, wIndex, [])
time.sleep(5)
You can learn more through this video from Lady Ada.
How are TouchXpress devices, such as CPT007B and CPT112s, immune to moisture?
Answer
TouchXpress devices can accommodate small droplets (water radius < sensor radius) as well as large droplets (water radius > sensor radius) of water.
Internal behavior depends on how much water is on the sensor, in terms of sensor radius.
Using Cap Sense Profiler and a CPT Evaluation Board is the easiest way to visualize this.
-------
Scenario #1: Below is the behavior when water radius is 1.5x - 2x the sensor radius. See picture below:
1. Start with no water on the board and touch a sensor.
2a. When the Raw CS value (in green) > the Active Threshold (in black), the device says the sensor is touched. 2b. When the Raw CS value (in green) < the Active Threshold (in black), the device says the sensor is untouched.
3. When you add a lot water (water radius is 1.5x -2x the sensor radius), the Raw CS value increases a lot. See picture below:
This amount of water causes the Raw CS value > Active threshold, resulting in a false "sensor is touched".
Notice the dynamic baseline did not change -- this is because the amount of water is large.
4. However, you can adjust the Active Threshold higher than the Raw CS value with water (ie to 14528 in this scenario), you can completely eliminate the false "sensor is touched".
-------
Scenario #2: With much larger water radius (water radius much greater than sensor radius), we have a touch timeout feature, which resets (forces new baseline) the device when the Raw CS value > the Active Threshold (eg from water, or real touch) after x number of seconds.
The idea here is that a user would not typically touch a sensor for multiple seconds.
------
Scenario #3: With small water radius, the baseline (red) will dynamically increase, and the Active Threshold will automatically increase relative to the baseline.
Dynamic baseline auto-adjusts only when the Raw CS value increase is < 0.25x the Touch Delta (max - min Raw CS value on board with no water).
When Raw CS value increase is < 0.25x the Touch Delta (Scenario #1), the baseline does not auto adjust.
While using a CP2114-B01 device, I found that the workaround for CP2114-E107 does restore the record feature. The only way record works is if the reset pin is used or the USB is reconnected.
Answer
Resetting the CP2114-B01 is a viable workaround for preventing the failure to resume recording (CP2114-B01 errata CP2114_E107).
The source file for the program is 'Reset_All_CP2114s.cpp'. The attached ZIP file contains the source and header files, and prebuilt EXE/DLL files for Windows 32-bit ('x86') and 64-bit ('x64') systems. These EXE files have been verified on Windows 7 and Windows 10 machines, but these are not tested on MacOS or Linux. Using the existing CP2114 SDK example source code and projects as a guide, it should not be difficult to port this code.
The appropriate EXE program can be run automatically at startup by placing a shortcut in the Windows Startup folder. One must ensure that the two library files are co-located with the executable, or otherwise able to be found.
The CP2130 USB Endpoint 1 uses a double-buffered FIFO, whereas Endpoint 2 uses a single-buffered FIFO. To improve SPI data transfer performance, Endpoint 1 can be used to double-buffer read data or write data transfer packets.
Table below shows the CP2130 USB Bulk endpoint usage for different device configuration.
Device Configuration
Bulk OUT
(Write)
Bulk IN
(Read)
High-Priority Write Mode
EP1
EP2
High-Priority Read Mode
EP2
EP1
By default, the CP2130 is configured in high-priority write mode.
AN792 describes CP2130 Interface Specification, and AN792SW contains an example for CP2130 Write and Read commands using libusb for Linux. Just a reminder that there is a known bug on the cp2130_libusb_read_example(), the endpoint for the 2nd libusb_bulk_transfer() call should be 0x82 indicating using Bulk IN endpoint 2.
Below is an example for the CP2130 WriteRead command.
bool cp2130_libusb_writeRead_example(libusb_device_handle* cp2130Handle)
{
// This example shows how to issue a bulk read request to the SPI MISO line
unsigned char read_command_buf[12] = {
0x00, 0x00, // Reserved
0x02, // WriteRead command
0x00, // Reserved
0x03, 0x00, 0x00, 0x00, // Read 3 bytes, little-endian
0x9F, 0xFF, 0xFF, 0xFF // Write 1 byte, the reset of bytes are dummy bytes
// in order to send the SPI clock for reading.
};
int bytesWritten,tmp;
int bytesToRead;
unsigned char read_input_buf[4];
int bytesRead;
int usbTimeout = 500;
if ((tmp = libusb_bulk_transfer(cp2130Handle, 0x01, read_command_buf, sizeof(read_command_buf), &bytesWritten, usbTimeout)) != 0)
{
if (tmp < 0) {
std::cout << tmp << std::endl;
}
std::cout << "ERROR: Error in bulk write transfer" << std::endl;
return false;
}
std::cout << "Successfully wrote to SPI MOSI , number of bytes written = " << std::dec << bytesWritten << std::endl;
if ((tmp = libusb_bulk_transfer(cp2130Handle, 0x82, read_input_buf, sizeof(read_input_buf), &bytesRead, usbTimeout)) != 0)
{
if (tmp < 0) {
std::cout << tmp << std::endl;
}
std::cout << "ERROR: Error in bulk read transfer" << std::endl;
return false;
}
std::cout << "Successfully read from SPI MISO, number of bytes read = " << std::dec << bytesRead << std::endl;
for (int i = 0; i < 4; i++) {
std::cout << std::hex << "0x" << int(read_input_buf[i]) << std::endl;
}
return true;
}
Interface Knowledge Base
CP2102N:“高级串口配置”选项
CP2102N具有一些其他CP210x器件所没有的附加配置选项。 它们显示在Xpress Configurator的[Advanced Serial Configuration]选项卡中。
这些设置仅适用于Windows和特定的应用。 这些设置适用于以下链接所描述的SERIAL_COMMPROP结构:
https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/ntddser/ns-ntddser-_serial_commprop
[Allowed Baudrates]选项用于设置结构体中的SettableBaud元素,而[Maximum Baudrate]用于设置结构体中的MaxBaud元素
SERIAL_COMMPROP结构体描述了串行端口的功能和属性,并由IOCTL_SERIAL_GET_PROPERTIES请求返回,详见如下所述:
https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/ntddser/ni-ntddser-ioctl_serial_get_properties
针对SERIAL_COMMPROP结构体对CP2102N做的这些配置对设备的行为没有直接影响。 例如,如果 [Maximum Baudrate] 设置为300,应用程序仍然可以请求更高的波特率,并且CP2102N能够支持请求。由应用程序读取SERIAL_COMMPROP结构,并决定是否阻止用户请求在该结构体中不支持的波特率。
CP2102N在自供电模式下,VBUS引脚连接方式和VBUS分压电阻
问题:
我使用的是CP2102N,还有一个外部的3.3 V稳压器,用于为VREGIN和VDD提供3.3 V电压。 我将VBUS引脚连接到USB 5 V。 VBUS是否需要分压电阻来降低输入电压? 或者,是否支持将VBUS引脚连接到3.3V稳压器输出引脚这样的配置?如果是,可以去掉VBUS上分压电阻吗?
回答:
如果上述电源配置是自供电配置,那么VBUS引脚上的需要分压电阻。 采用分压电阻的这种电源配置如CP2102N数据表第9页的图2.6所示。 请注意,在任何供电模式下(无论是自供电还是总线供电),USB的VBUS信号连接到CP2102N VBUS的引脚都需要分压电阻(如图2.6所示),以避免VBUS上可能出现的过压情况(参见https://www.silabs.com/community/interface/knowledge-base.entry.html/2018/03/31/cp2102n_requiresav-NFly)。
至于VBUS引脚连接到VDD和VREGIN的相同3.3V电源,只要CP2102N上的稳压器被旁路(即VDD = VREGIN =外部提供的3.3 V),该配置应该是可接受的。下面这种情况下不支持:如果器件是自供电的,内部稳压器用于为VDD供电(例如,如果USB 5V VBUS信号连接到VREGIN),VDD上升时间的延迟可能会导致其超出了VBUS PIN上最大额定电压的限定。 在这些情况下,都应使用VBUS分压电阻。
英文原文:https://www.silabs.com/community/interface/knowledge-base.entry.html/2018/10/02/self_powered_cp2102n-2gfe
How to check if the CP210x be enumerated successfully on Linux
When a CP210x device is connected to the USB host, the host will send a reset signal to the USB device to start the enumeration process. After reset, the host will read the USB device’s information and assign a unique address. If USB host has the driver for the device, the driver will be loaded after enumeration done.
Sometimes the USB enumeration may fail because of bad USB signal quality, incorrect USB driver for the specified VID/PID device, etc. So, it is important to check if the CP210x device is enumerated successfully.
This KBA introduces two methods for checking this.
a) Connect the CP210x device to USB host on Linux.
b) Start a terminal on Linux, type “lsusb” and press Enter. There will be one more USB devices, take the CP2104EK as an example, it named CP210x UART Bridge / myAVR mySmartUSB light (it's a wrong name because of Ubuntu OS, it should be "Silicon Labs CP210x USB to UART Bridge") in my case. The hex value 10c4:ea60 represents VID and PID as shown below. The PID and product name may different if the device is customized.
c) Typing“lsusb -d VID:PID -v” and press Enter, it is “lsusb -d 10c4:ea60 -v” in my case. Then the CP210x device descriptor will be printed out on the screen. By checking the descriptor information we should know if the device has been correctly enumerated. However, if all the data is zeroes (0x0000, for example) or if an error is reported, the device did not properly enumerated.
How to Install and Run USBView on Linux
USBView is a graphical user interface application that enables you to browse USB controllers and connected USB devices on your computer. It displays the information on each of the USB devices (like VID, PID, Product String, descriptors, etc.). The driver for the device does not need to be installed or loaded for USBView to read the information, as the utility uses the low-level USB driver to talk to the device. This is useful when a CP210x is not enumerating because of an incorrectly programmed PID.
You can run USBView by double-click a USBView.exe package on Window. But there is difficulty to run it on Linux. This article will explain how to install and run USBView on Ubuntu.
Gtk3.0 is required for running USBView, you can install gtk3.0 by typing below command and press Enter on terminal.
The Ubuntu website provides a .deb package and source code of USBView, you can download it from following link: http://manpages.ubuntu.com/manpages/trusty/man8/usbview.8.html. If you choose to install USBView with .deb package, you can finish it just by double-click .deb package. If you want to install it with source code, you should extract the source code package and enter the extracted directory, then follow three steps to install it.
After installation, you will see the following directory structure.
Running the USBView by typing “sudo ./usbview”, and the graphical display of connected USB devices are shown as below.
Detailed information may be displayed by selecting individual devices in the display.
How to control GPIOs of CP210x at runtime
Some CP210x devices include GPIO pins that can be controlled at runtime. This article discusses reading and writing the latch value of these pins with software on different operating system platforms.
On Windows
Before connecting to a device, the host must install relevant VCP driver, you can get the appropriate installation package from the link below:
https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers
After installing the VCP driver, the CP210x device is recognized by the host when it was plugged in the host USB port. Silabs offers a CP210x Port Read/Write Example application to read/write GPIO latch at runtime.
Taking CP2104EK as testing platform to show how to read/write the GPIO by the CP210x Port Read/Write Example, the CP210x Port Read/Write Example application can be found in AN223SW. Besides, reading AN223 for more information, you can get both of them from the website here https://www.silabs.com/community. we will write value to GPIOs and then read it back by three steps blow.
The CP210x Port Read/Write Example illustrates how the GPIO latch can be read from and written to device by using the CP210xRuntime.DLL. You can develop a custom application using CP210xRuntime.DLL, the functions in this API (CP210xRT_ReadLatch() and CP210xRT_WriteLatch()) give host-based software access to the CP210x device’s GPIO latch using the USB connection.
On Linux
The CP210x driver has been distributed as part of the Linux kernel since v2.6.12, and GPIO operations also be supported by Linux 4.10.0 kernel or later.
If you are using an older kernel version, please download the latest Linux VCP driver from link below and merge the GPIO operation related source code into your kernel. The .zip package contains VCP driver and example code show how to control GPIOs.
https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers .
After merging the VCP driver cp210x.c, compile it with make command and install it with command "insmod ". Note that the command "rmmod cp210x.ko" should be executed if VCP driver already exists before installing the driver that support GPIO control.
In the cp210x_gpio_example.c, use the following function to open a CP210x device.
Use the function below to read latch, where the third parameter gpioread is a buffer address of one-byte length for storing the read latch value.
The returned read latch value is represented as follows: bits 0–7: Current latch state, where bit 0 is GPIO0, bit 1 is GPIO1, etc. Up to GPIOn where n is the total number of GPIO pins the interface supports.
Use the function below to write latch, where the third parameter gpio is write latch value.
The write latch value that is supplied in the Data phase represents as follows:
bits 0–7: Mask of the latch state (in bits 8-15) to write, where bit 0 is GPIO0, bit 1 is GPIO1, etc. Up to GPIOn where n is the total number of GPIO pins the interface supports.
bits 8–15: Latch state to write, where bit 8 is GPIO0, bit 9 is GPIO1, etc. Up to GPIOn where n is the total number of GPIO pins the interface supports.
Get more information from AN571.
Compile the application with “gcc cp210x_gpio_example.c”, a executable file “a.out” is generated. Execute it with “./a.out”.
On MacOS
The Mac VCP driver v5.0 or later version supports the GPIO control on the CP210x devices. Download the latest driver here:
https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers. We can control the GPIO pins with python.
For using the python, you should install libusb and Pyusb library on your Mac machine, please refer to the following code to write a Python script to control the CP210x GPIO.
You can learn more through this video from Lady Ada.
https://www.youtube.com/watch?v=xH_y05pIDTo
The python script is also suitable for other OS including Window and Linux.
TouchXpress Moisture Immunity
USBXpress SDK Installer
Improving sensing of a CPT device through the Xpress Configurator
Problems implementing CP2114_E107 workaround in CP2114-B01
CP2130 WriteRead Command using LibUSB for Linux
The CP2130 USB Endpoint 1 uses a double-buffered FIFO, whereas Endpoint 2 uses a single-buffered FIFO. To improve SPI data transfer performance, Endpoint 1 can be used to double-buffer read data or write data transfer packets.
Table below shows the CP2130 USB Bulk endpoint usage for different device configuration.
Bulk OUT
(Write)
Bulk IN
(Read)
By default, the CP2130 is configured in high-priority write mode.
AN792 describes CP2130 Interface Specification, and AN792SW contains an example for CP2130 Write and Read commands using libusb for Linux. Just a reminder that there is a known bug on the cp2130_libusb_read_example(), the endpoint for the 2nd libusb_bulk_transfer() call should be 0x82 indicating using Bulk IN endpoint 2.
Below is an example for the CP2130 WriteRead command.