Usb to Uart_i2c_spi_jtag - Waveshare Wiki
Usb to Uart_i2c_spi_jtag - Waveshare Wiki
Specification
(https://www.waveshare.com/usb-
to-uart-i2c-spi-jtag.htm)
Function Description
USB TO UART/I2C/SPI/JTAG is a high-speed USB bus adapter device that supports USB to 2-
ch UART, USB to 1-ch UART + 1-ch I2C + 1-ch SPI, USB to 1-ch UART + 1-ch JTAG.
In Mode 0, the product provides 2x high-speed UART channels.
In Mode 1 or Mode 2, the product provides 1x high-speed UART channel, 1x I2C interface
(SCL and SDA lines), and 1 4-wire SPI interface (CS line, SCK line, SDI/MISO line, SDO/MOSI
line).
In Mode 3, the product provides a JTAG interface, supporting either a 4-wire or 5-wire
interface (TMS, TCK, TDI, TDO, and TRST lines).
In Mode 2, it operates as an HID plug-and-play device (Human Interface Device) and does
not require drivers. Therefore, the newly added device may not be visible as a new port in the
Device Manager.
I2C and SPI are for Host/Master mode.
Mode Description
Interface Description
(/wiki/File:USB_TO_UART02.png)
Windows
Environment Building
Driver Installtion
(/wiki/File:USB_TO_UART_I2C02.png)
Another viewing way: Go to Device Manager -> click "View" at the top -> "List Devices by
Connection" -> select "ACPI x64 based computers" -> "PCI Express Root Complex" ->
"Intel(R) USB 3.20 Scalable Host Controller - 1.20 (Microsoft)" (varies from computer to
computer). "PCI Express Root Complex" -> "Intel(R) USB 3.20 Scalable Host Controller - 1.20
(Microsoft)" (may vary from computer to computer) -> "USB Root Hub (USB 3.0)" -> CH347
related devices can be found in "USB Composite Device" of multiple "Universal USB Hubs".
Note: A serial port exists for all modes except mode 0.
(/wiki/File:UART_Interface_Demo.png)
The following is using two serial ports of the product to perform self-transmission and
reception. Please switch to mode0.
Hardware Connection
Software Operation
(/wiki/File:Usb_to_uart_sscom01.png)
Set to the same baud rate, enter the characters to be sent, select "Add time stamp and packet
display", and set "50ms/time, timed send".
(/wiki/File:Usb_to_uart_sscom02.png)
The following is a demonstration of self-sending and receiving using the product's two serial
ports. (Sample demo (https://files.waveshare.com/upload/2/2b/USB-TO-UART-I2C-SPI-JTAG-D
emo.zip))
Hardware Connection
Software Operation
Open Python IDLE, click "File -> Open..." at the top. ", go to the sample demo"... /USB-TO-
UART-I2C-SPI-JTAG-Demo/Windows/Code".
Go to the UART folder, and choose to open the UART.py file (please check if it is the
corresponding port.)
(/wiki/File:USB_to_UART_I2C34.png)
Click "Run" -> "Run Module" or directly click F5 to run the demos.
(/wiki/File:USB_TO_UART_I2C2.png)
The following is a sample demo that demonstrates how to acquire data (TF-Luna-related
information (https://www.waveshare.com/tf-luna-lidar-range-sensor.htm) and pinout (https://fil
es.waveshare.com/upload/a/ac/SJ-PM-TF-Luna_A05_Product_Manual.pdf)) from the TF-Luna in
I2C mode using the product's I2C function. (Sample demo (https://files.waveshare.com/uploa
d/2/2b/USB-TO-UART-I2C-SPI-JTAG-Demo.zip)).
Hardware Connection
Please set the mode switch to mode 1 or mode 2 and connect the computer after connecting
the cable.
Software Operation
Enable Python IDLE, click "File" -> Open... Enter the sample demo "../USB-TO-UART-I2C-SPI-
JTAG-Demo/Windows/Code" (Sample demo (https://files.waveshare.com/upload/2/2b/USB-T
O-UART-I2C-SPI-JTAG-Demo.zip)).
Enter the I2C file folder and select open I2C.py file.
① If you are using multiple USB TO UART/I2C/SPI/JTAG devices at the same time, please select
the device at ① (similar to the device serial number, 0, 1, 2... etc.)
②Modify the I2C device address according to the actual need to operate.
(/wiki/File:USB_TO_UART_I2C33.png)
Click "Run" -> "Run Module" or directly click F5 to run the demo.
(/wiki/File:USB_TO_UART_I2C2.png)
The following is a demonstration of using the I2C function of the product to turn on and off
the data output of TF-Luna in I2C mode (TF-Luna-related information (https://www.waveshare.
com/tf-luna-lidar-range-sensor.htm)).
Download the I2C debugging software (USB TO UART_I2C_SPI_JTAG Software demo (https://fil
es.waveshare.com/upload/b/bc/CH347Demo.zip)), no need to install it, directly open it to use.
Hardware Connection
Please switch the mode to mode 1 or mode 2 and connect the computer after connecting the
cable.
(/wiki/File:USB_TO_UART_I2C_SPI_JTAG_TO_I2C_Hardware_Connection.png)
Software Operation
Enable USB TO UART_I2C_SPI_JTAG Demo software to enter the I2C debugging interface, and
enable the device.
(/wiki/File:USB_TO_UART_Software01.png)
Click Initialize SPI (the software and SPI share the same interface), don't care about those
parameters before the initialization button.
Input the data to be sent in the I2C input box (the input is hexadecimal data), and click
Write/Read.
20 5A 05 07 00 66
Input 20 5A 05 07 01 67, clicking Write/Read will turn on the TF-Luna's data output (the TF-
Luna's red light is on again).
20 5A 05 07 01 67
(/wiki/File:USB_TO_UART_Software03.png)
The phenomenon is as follows (the shooting effect is more conspicuous than the human eye
observation, please turn the TF-Luna to prevent the angle from not observing it).
(/wiki/File:Software_Operation01.png)
The following is a demonstration of using the product's SPI function to turn on an OLED in SPI
mode (OLED-related information (https://www.waveshare.com/0.96inch-oled-a.htm)) (sample
demo (https://files.waveshare.com/upload/2/2b/USB-TO-UART-I2C-SPI-JTAG-Demo.zip))
The current example has already been set up, so there is no need to do the following
operation:
The DLL file should be placed in the directory where the demo program is located, there are
two DLL files stored in the sample file (corresponding to 64-bit system and 32-bit system
respectively), please adjust according to the system.
(/wiki/File:USB_TO_UART_I2C_09.png)
Or you can modify the file path in the demo as the DLL file storage path.
(/wiki/File:USB_TO_UART_I2C_10.png)
Hardware Connection
Please set the mode switch to mode 1 or mode 2 and connect the computer after connecting
the cable.
(/wiki/File:USB_TO_UART_I2C_SPI_JTAG_TO_SPI_Hardware_Connection.png)
Software Operation
Open Python IDLE, click "File -> Open..." at the top. ", go to the sample demo "... /USB-TO-
UART-I2C-SPI-JTAG-Demo/Windows/Code" (example demo (https://files.waveshare.com/uplo
ad/2/2b/USB-TO-UART-I2C-SPI-JTAG-Demo.zip)).
Go to the SPI folder, and choose to open the example.py file.
① If you are using more than one USB TO UART/I2C/SPI/JTAG device at the same time, please
select the device at ① in the CH347T_Config.py file (similar to the device serial number, 0, 1, 2...
etc.)
(/wiki/File:USB_TO_UART_OLED.png)
The following is a demonstration of using the SPI function of the product to light up the OLED
in SPI mode (OLED-related information (https://www.waveshare.com/0.96inch-oled-a.htm))
Download the SPI debugging software (USB TO UART_I2C_SPI_JTAG Software demo (https://fil
es.waveshare.com/upload/a/ac/CH347T_Driver.zip)), no need to install, and directly open the
use.
Hardware Connection
Please set the mode switch to mode 1 or mode 2 and connect the computer after connecting
the cable.
(/wiki/File:USB_TO_UART_I2C_SPI_JTAG_TO_SPI_Hardware_Connection_0.png)
Software Operation
Enable USB TO UART_I2C_SPI_JTAG Demo software to enter the SPI debugging interface, and
enable the device.
(/wiki/File:USB_TO_UART_Software01.png)
Initialize SPI parameters according to the use of the environment, after selecting the
parameters click on the initialization of SPI (more clicks on the initialization of SPI, to prevent
initialization failure).
(/wiki/File:USB_TO_UART_Software_SPI_01.png)
Enter the data to be sent in the SPI input box and select SPI Read, SPI Write or SPI Read/Write
according to the desired operation.
(/wiki/File:USB_TO_UART_Software_SPI_02.png)
The data below are OLED initialization commands (use the right mouse button to paste the
data, keyboard shortcuts cannot be used):
AE D5 80 A8 3F D3 00 40 8D 14 20 00 A1 C8 DA 12 81 CF D9 F1 DB 40 A4 A6 AF 21 00 7F 22 00 0
7
(/wiki/File:USB_TO_UART_Software_SPI_03.png)
Connect the D/C pin of the OLED to VCC (Connecting to GND for sending commands, to VCC
for sending data):
(/wiki/File:USB_TO_UART_initilization2.png)
Sending data to clear the screen (use the right mouse button to paste the data, keyboard
shortcuts cannot be used), click SPI once and clear part of them:
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0
0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0
0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Sending data to light on (use the right mouse button to paste the data, keyboard shortcuts
cannot be used), click SPI once and clear part of them:
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F
F FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
(/wiki/File:USB_TO_UART_initilization3.png)
Hardware Connection
Preparation
(/wiki/File:USB_TO_UART_I2C_Pre.png)
Click the Win+R key, and input "cmd" to enter the command window.
Go to the "USB-TO-UART-I2C-SPI-JTAG-Demo\Windows\Software\OpenOCD-CH347\bin"
directory in the path of the package (the demo is for the desktop).
cd Desktop\USB-TO-UART-I2C-SPI-JTAG-Demo\Windows\Software\OpenOCD-CH347\bin
(/wiki/File:USB_TO_UART_Win.png)
Connect CH347 and STM32F4 (openocd.exe -f ch347.cfg -f + parameter: here the parameter
is the configuration file of the connected chip, you can copy the file to the bin folder in the
2nd point, otherwise you need to add the path of the configuration file.)
(/wiki/File:USB_TO_UART_CH347.png)
(/wiki/File:USB_TO_UART_CH34703.png)
Demo Download
Note: In the example file, there is a Test folder under the bin file, and there are two files under
the folder that correspond to the clockwise and counterclockwise control of the light source by
pressing the key under the Open429I-C (Package A).
halt
program STM32F429_439xx.hex
(/wiki/File:USB_TO_UART_Demo_Download.png)
Demo Debug
The debugging command "halt" has already been used in the program download to pause
the running program.
Use "flash probe 0" to scan the flash.
Execute various debugging commands for functional debugging (e.g. reset, halt, resume, etc.).
(/wiki/File:USB_TO_UART_Demo_Debug.png)
Porting Description
Porting Reference
DLL files should be placed in the directory where the demo program is located. There are two
DLL files in the sample files (corresponding to 64-bit and 32-bit systems respectively). Please
adjust it according to your system.
(/wiki/File:USB_TO_UART_I2C_09.png)
Or you can modify the file path of the demo as a DLL file storage path.
(/wiki/File:USB_TO_UART_Environment02.png)
Example Reference
Note: The demo is modified based on the Raspberry Pi driver OLED demo.
Reference link: OLED related resource (https://www.waveshare.com/0.96inch-oled-a.htm)
Reference example is the file under "../OLED_Module_Code /RaspberryPi/python". (Sample
demo (https://files.waveshare.com/upload/2/2c/OLED_Module_Code.7z))
File Description
For more functions description, you can refer to CH347 Application Development Manual (ht
tps://files.waveshare.com/upload/2/2b/CH347-applicationa-development-manual-en.pdf)
Driver Installation
Download the file package to the Raspberry Pi and unzip the file:
wget https://files.waveshare.com/wiki/USB-TO-UART-I2C-SPI-JTAG/USB-TO-UART-I2C-SPI-JTAG-Dem
o.zip
unzip USB-TO-UART-I2C-SPI-JTAG-Demo.zip -d ./USB-TO-UART-I2C-SPI-JTAG-Demo
Execute example:
(/wiki/File:USB_TO_UART_Linux.png)
(/wiki/File:USB_TO_UART_Linux-AB.png)
Enter the driver file directory:
cd USB-TO-UART-I2C-SPI-JTAG-Demo/Raspberry/Driver/driver/
make
sudo insmod ch34x_pis.ko
Install serial library: (If you fail, you can execute sudo pip3 install pyserial)
Switch to Mode1 and connect to the Raspberry Pi, view the device, and see "ch34x_pis*".
ch34x_pis*"
(/wiki/File:CH34X_ch.pg.png)
Preparation
View the system information:
uname - a
armv61 (32-bit)
armv71 (32-bit)
aarch64 (64-bit)
x86_64 (64-bit but not Raspberry Pi)
If the return value is armv61 or armv71, it means it is 32-bit ARM architecture (for Raspberry
Pi). If the return value is aarch64, it means it is 64-bit ARM architecture (for Raspberry Pi). If the
return value is x86_64, it is not Raspberry Pi. Select x64 folder.
(/wiki/File:USB_TO_UART_AARCH.png)
Currently using the Raspberry Pi 64-bit libraries, if your query result is aarch64, then you do
not need to do the following operations.
cd
cd USB-TO-UART-I2C-SPI-JTAG-Demo/Raspberry/Lib/aarch64
(/wiki/File:USB_TO_UART_AARCH2.png)
Copy the files with the ".so" extension to the program folder. If there is already a ".so" file in
the folder that is intended for use on aarch64 architecture, replace it with the ".so" file that is
compatible with your current system.
For instance, copy the appropriate ".so" file into the I2C example:
(/wiki/File:USB_TO_UART_AARCH23.png)
Or copy to SPI example:
When using UART, it is the same as other normal UART devices (the device number identified
by the Raspberry is ttyACM*, and the new devices can be queried by plugging and
unplugging devices.)
1. Do not connect USB TO UART/I2C/SPI/JTAG first, use the commands to query the current
device:
ls /dev/tty*
2. Connect the Raspberry Pi and USB TO UART/I2C/SPI/JTAG, and query "ls /dev/tty*", the new
device is the device number of the product:
ls /dev/tty*
(/wiki/File:USB_TO_UART_SPI_EXA.png)
Hardware Connection
Software Operation
1. Do not connect USB TO UART/I2C/SPI/JTAG first, and use commands to query the current
device.
ls /dev/tty*
2. Connect the Raspberry Pi and USB TO UART/I2C/SPI/JTAG, query "ls /dev/tty*" again, and
the new device is the device number of the product.
ls /dev/tty*
(/wiki/File:USB_TO_UART_SPI_EXA.png)
Enter the UART example directory, and edit the program UART.py.
cd USB-TO-UART-I2C-SPI-JTAG-Demo/Raspberry/Code/UART/
vi UART.py
(/wiki/File:USB_TO_UART_I2C_SPI_JTAG_TO_Linux_UART_2.png)
Move the cursor to position ① and change it to the recognized device number (move the
cursor using 'up, down, left and right keys' -> click 'i' and then modify it -> click 'Esc' after
modifying it -> input ':wq' to save and exit).
(/wiki/File:USB_TO_UART_I2C_SPI_JTAG_TO_UART_02.png)
Execute demo:
Hardware Connection
Please switch to Mode 1 or Mode 2, and connect to the computer by connecting the cables.
Software Operation
Query the current identified device number (connect the Raspberry Pi and USB TO
UART/I2C/SPI/JTAG, query the device).
Mode 1 Query 'ch34x_pis*' and 'tty*', can be queried once when the device is connected and
once when the device is not connected(('ch34x_pis*' for SPI/I2C,'tty*' for UART)).
ls /dev/ch34x_pis*
(/wiki/File:USB_TO_UART_I2C_SPI_JTAG_TO_Linux_I2C_1.png)
Mode 2 Query 'hidraw*', can be queried once when the device is connected and once when
the device is not connected.
ls /dev/hidraw*
(/wiki/File:USB_TO_UART_SPI_EXA02.png)
Enter the I2C example directory, and edit the demo I2C.py:
cd USB-TO-UART-I2C-SPI-JTAG-Demo/Raspberry/Code/I2C/
vi I2C.py
(/wiki/File:USB_TO_UART_SPI_EXA03.png)
Move the cursor to position ① and change it to the recognized device number (move the
cursor using 'up, down, left and right keys' -> click 'i' and then modify it -> click 'Esc' after
modifying it -> input ':wq' to save and exit).
(/wiki/File:USB_TO_UART_SPI_EXA04.png)
Hardware Connection
Please set the mode switch to mode 1 or mode 2 and connect the computer after connecting
the cable..
(/wiki/File:USB_TO_UART_I2C_SPI_JTAG_TO_SPI_Hardware_Connection.png)
Software Operation
Query the current identified device number (connect the Raspberry Pi and USB TO
UART/I2C/SPI/JTAG, query the device).
Mode 1 Query 'ch34x_pis*' and 'tty*' once for both connected and unconnected devices
('ch34x_pis*' for SPI/I2C,'tty*' for UART).
ls /dev/ch34x_pis*
(/wiki/File:USB_TO_UART_I2C_SPI_JTAG_TO_Linux_SPI_1.png)
Mode 2 Query 'hidraw*' once for both connected and unconnected devices.
ls /dev/hidraw*
(/wiki/File:USB_TO_UART_SPI_EXA02.png)
Enter the SPI example directory, and edit the demo CH347T_Config.py.
cd USB-TO-UART-I2C-SPI-JTAG-Demo/Raspberry/Code/SPI/
vi CH347T_Config.py
(/wiki/File:USB_TO_UART_I2C_SPI_JTAG_TO_Linux_SPI_3.png)
Move the cursor to position ① and change it to the recognized device number (move the
cursor using 'up, down, left and right keys' -> click 'i' and then modify it -> click 'Esc' after
modifying it -> input ':wq' to save and exit).
(/wiki/File:USB_TO_UART_I2C_SPI_JTAG_TO_Linux_SPI_4.png)
(/wiki/File:USB_TO_UART_I2C_SPI_JTAG_TO_Linux_SPI_5.png)
Resource
Demo and Materials
Demo (https://files.waveshare.com/wiki/USB-TO-UART-I2C-SPI-JTAG/USB-TO-UART-I2C-SPI-J
TAG-Demo.zip)
CH347 Applicationa Development Manual (https://files.waveshare.com/upload/2/2b/CH347-a
pplicationa-development-manual-en.pdf)
Linux use information (https://github.com/WCHSoftGroup/ch341par_linux)
CH347 (https://github.com/WCHSoftGroup/ch347)
FAQ
Question:Mode switching has no effect?
Answer:
This may be the case of switching modes after not carrying out the power-off operation:
1. First disconnect the device from the computer.
2. Toggle the mode switch to adjust to the desired mode.
3. Reconnect the device with the computer.
Answer:
In this case, the TF-Luna (external device) may not be configured to I2C mode.
1. Disconnect all the wires between TF-Luna and the device.
2. Connect the fifth wire of TF-Luna first, and then connect the other wires in turn.
Answer:
1: It may be caused by the mismatch between the device communicating with this product
and the current communication level of the device.
1. Please check whether the allowable level of the equipment communicating with this
product is 3.3V or 5V.
2. Toggle the level switch to adjust the communication level to be consistent with the
external equipment.
2: It may be caused by the high power consumption of the device communicating with this
product or more devices using the VCC port of this product for power supply.
1. Please use an external power supply for the device connected to the product and
connect the GND of the power supply device to the GND of the product.
2. Please note that the GND of each device needs to be connected together.
Answer:
(/wiki/File:USB_TO_UART_-FAQ01.png)
If it can not be downloaded normally, you can use other sources to download:
Answer:
Please enter the device address + register address in the I2C output box as follows:
(/wiki/File:USB_TO_UART_I2C_SPI_JTAG_TO_problem_I2C_1.png)
A0 indicates the address after the device address is shifted to the left by 1 bit (the
read/write bit will be handled automatically, just offset the device address by one bit), 00
00 indicates the address of the register to be read.
If the register address is 16 bits, send the low byte first (according to the requirements of
the slave device, some devices need to send the high byte first), such as reading the 10
bytes of the 0x0004 address (the input length position needs to be filled in the number of
bytes to be read):
(/wiki/File:USB_TO_UART_I2C_SPI_JTAG_TO_problem_I2C_2.png)
Please note that if the slave device has other corresponding operations for data
acquisition, please make adjustments according to the specific operations of the slave
device.
Answer:
Please check whether the communication device supports 5V.
Support
Technical Support
If you need technical support or have any
feedback/review, please click the Submit
Submit Now (https://service.w
Now button to submit a ticket, Our support
team will check and reply to you within 1 to aveshare.com/)
2 working days. Please be patient as we
make every effort to help you to resolve the
issue.
Working Time: 9 AM - 6 PM GMT+8
(Monday to Friday)