I'm using cp210xmanufacturing library for Linux, why is my device not recognized when calling CP210x_GetNumDevices()?
It could be a permissions problem. Try running your program as root. If the device is recognized when your program is run as root but not when run with normal permissions, the SiliconLabs.rules file may not be installed properly.
root should always have read/write permissions to USB device files.
To automatically grant global read/write permissions to all USB devices with the Silicon Labs Vendor ID (0x10c4), copy the SiliconLabs.rules file to /etc/udev/rules.d/:
$ sudo cp SiliconLabs.rules /etc/udev/rules.d/
Refer to SiliconLabs.rules for more information. Also it may be necessary to create your own udev rules file by modifying SiliconLabs.rules to include your own Vendor ID and optionally Product ID.
Attention: The udev rules file may not have been applied. udev should monitor the /etc/udev/rules.d/ directory for new rules file, but this does not always work. You may need to unplug/replug your device and possibly reboot for the udev rule to take affect.
CP2102N具有一些其他CP210x器件所没有的附加配置选项。 它们显示在Xpress Configurator的[Advanced Serial Configuration]选项卡中。
[Allowed Baudrates]选项用于设置结构体中的SettableBaud元素，而[Maximum Baudrate]用于设置结构体中的MaxBaud元素
针对SERIAL_COMMPROP结构体对CP2102N做的这些配置对设备的行为没有直接影响。 例如，如果 [Maximum Baudrate] 设置为300，应用程序仍然可以请求更高的波特率，并且CP2102N能够支持请求。由应用程序读取SERIAL_COMMPROP结构，并决定是否阻止用户请求在该结构体中不支持的波特率。
我使用的是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分压电阻。
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.
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.
$ sudo apt-get install libgtk-3-dev
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.
$ sudo ./configure $ sudo ./make $ sudo ./make install
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.
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.
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.
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.
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.
fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);
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”.
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.
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.
The python script is also suitable for other OS including Window and Linux.