Google Chat: zj734465502@gmail.com
+86-0755-88291180
sales01@spotpear.com
dragon_manager@163.com
services01@spotpear.com
manager01@spotpear.com
WhatsApp:13246739196
The 2-CH UART TO ETH provides an easy way to communicate between UART TTL and RJ45 Ethernet, allowing bi-directional transparent data transmission. It is easy to use, along with features like fast data rate, low power consumption, high stability, suits applications such as safety & security, IoT, and so on.
5V/3V3 | power positive, use any pin of 5V/3.3V pins for power supply |
GND | ground |
RST1 | external reset input, low active |
RESET | restore to factory setting, detected when chip power on, low active |
TXD1 | asynchronous UART 1 data output (enabled by default) |
TXD2 | asynchronous UART 2 data output (disabled by default) |
RXD1 | asynchronous UART 1 data input (enabled by default) |
RXD2 | asynchronous UART 2 data input (disabled by default) |
CFG0 | UART config mode, low level to enter configuration, high level to exit configuration |
RUN | Operating status indicating pin |
DIR1 | UART 1 RS485 RX/TX switch (connects to external RS485 controller) |
DIR2 | UART 2 RS485 RX/TX switch (connects to external RS485 controller) |
CH9121 is the chip for network serial port transparent transmission, which can realize the two-way transparent transmission of serial data and network data. It supports 4 working modes such as TCP CLIENT, SERVER, UDP CLIENT and SERVER, and the serial port baud rate is 300bps~921600bps. Before use, it is necessary to configure the network parameters and serial port parameters of the chip through the host computer software NetModuleConfig.exe or serial commands. After the configuration is completed, CH9121 will save the parameters to the internal storage space. After the chip is reset, CH9121 will work according to the saved configuration values.
The UART2 is disabled, UART1 works in TCP CLIENT mode by default. The default setting of ETH is as below:
The default setting of the UART1 is as below:
1. Select SSCOM to select the protocol type as TCPServre, and then view the target IP and target port number through SSCOM (that is, 1 and 2 in the figure).
2. Run NetModuleConfig.exe to set the module parameters, as follows:
(1). Click "Search Device", and the device list will show the modules in the subnet;
(2). Double-click the module in the device list, modify the parameters on the left, and then click "Configure Device Parameters";
(3). After the configuration is completed, the module will restart, wait a while, click "Search Device", find the module, and view the configuration result.
(4). Modify the module parameters according to actual needs, for example: set the network mode to TCP CLIENT, destination IP, destination port and TCP SERVER.
The IP and port are the same, and then modify the baud rate and other parameters as required. Then click Configure Device Parameters.
3. After the configuration is complete, click on SSCOM to connect to it.
1. Run NetModuleConfig.exe to set the module parameters, as follows:
(1). Click "Search Device", the device list will show the modules in the subnet;
(2). Double-click the module in the device list, modify the network mode to TCPServre on the left, then modify the module parameters as required, and finally click "Configure Device Parameters";
2. Connect to the module configured as TCP SERVER through SSCOM, the connection will be shown as follows:
1. Run NetModuleConfig.exe to set the module parameters, as follows:
(1). Click "Search Device", the device list will show the modules in the subnet;
(2). Double-click the module in the device list, modify the network mode to UDP CLIENT/Servre on the left, then modify the module parameters as required, and finally click "Configure Device Parameters";
2. Connect the module configured as UDP CLIENT/Servre through SSCOM (the UDP mode of SSCOM will automatically connect, no matter your mode is configured as CLIENT/Servre), the connection will be shown as follows:
You can connect according to the following table.
ETH | Pico | Function |
5V | VSYS | Power input |
GND | GND | Power ground |
RXD1 | GP0 | Serial data input |
TXD1 | GP1 | Serial data output |
RXD2 | GP4 | Serial data input |
TXD2 | GP5 | Serial data output |
CFG0 | GP14 | Network configuration enable pin |
RST1 | GP17 | Reset |
Open the Raspberry Pi terminal and execute:
sudo apt-get install p7zip-full cd ~ sudo wget https://www.waveshare.com/w/upload/3/37/2-CH_UART_TO_ETH_CODE.7z 7z x Pico_ETH_CH9121_CODE.7z -o./2-CH UART TO ETH_CODE cd ~/2-CH UART TO ETH_CODE cd Pico/c/build/
To compile, make sure to be in the c directory:
cd ~/2-CH UART TO ETH_CODE/Pico/C/
2-CH UART TO ETH_CODE/Pico/C/Serial Port Parameter Configuration:Used to configure the mode through the serial port.
2-CH UART TO ETH_CODE/Pico/C/RX_TX:Used to send and receive information, and return what is received.
Enter one of the folders to create and enter the build directory, and add the SDK: Where ../../pico-sdk is the directory of your SDK. There is a build in our sample program, just enter it directly.
cd build export PICO_SDK_PATH=../../pico-sdk (Note: Be sure to write the path where your own SDK is located)
Execute cmake to automatically generate Makefile
cmake ..
Executing make to generate executable files, the first compilation time is relatively long
make -j9
After the compilation is complete, the uf2 file will be generated. Press and hold the button on the Pico board, connect pico to the USB port of the Raspberry Pi via the Micro USB cable, and then release the button. After connecting, the Raspberry Pi will automatically recognize a removable disk (RPI-RP2). Copy the main.uf2 file in the build folder to the recognized removable disk (RPI-RP2).
cp main.uf2 /media/pi/RPI-RP2/
This example provides two programs:
Serial Port Parameter Configuration.py:This program is used to configure the mode through the serial port.
RX_TX.py:This is used to send and receive information, and return what is received.
To ensure that your version has the Pico support package, you can also click Tools -> Options... -> Interpreter to select MicroPython (Raspberry Pi Pico and ttyACM0 port
as the picture shows:
If your current Thonny version does not have pico support package, enter the following command to update Thonny IDE
sudo apt upgrade thonny
Click File->Open...->python/RX_TX.py and run the script
Configure the parameters through the serial port (modify according to your needs):
#define UCHAR unsigned char #define UBYTE uint8_t #define UWORD uint16_t #define UDOUBLE uint32_t
void CH9121_init(void);
UCHAR CH9121_Mode //Mode selection UCHAR CH9121_LOCAL_IP[4] //Local IP UCHAR CH9121_GATEWAY[4] //Gateway UCHAR CH9121_SUBNET_MASK[4] //Subnet mask UCHAR CH9121_TARGET_IP[4] //Target IP UWORD CH9121_PORT1 //Local port UWORD CH9121_TARGET_PORT //Target port UDOUBLE CH9121_BAUD_RATE //Serial port baud rate
void CH9121_TX_4_bytes(UCHAR data, int command); //Used for mode, whether the port is random, whether the port is disconnected from the network, whether to clear the serial port data, whether to open DHCP, //whether to open the serial port 2 void CH9121_TX_5_bytes(UWORD data, int command); //Used to set the port number of the serial port void CH9121_TX_7_bytes(UCHAR data[], int command);//Used to set IP, subnet mask, gateway void CH9121_TX_BAUD(UDOUBLE data, int command); //Used to set the baud rate of the serial port void CH9121_Eed(); //Update configuration parameters to EEPROM, execute configuration, reset 9121, leave configuration mode
Users only need to modify the values shown below in Serial Port Parameter Configuration.py to configure the serial port parameters of the module:
MODE = 1 #0:TCP Server 1:TCP Client 2:UDP Server 3:UDP Client GATEWAY = (169, 254, 88, 1) # GATEWAY TARGET_IP = (169, 254, 88, 17) # TARGET_IP LOCAL_IP = (169,254,88,70) # LOCAL_IP SUBNET_MASK = (255,255,255,0) # SUBNET_MASK LOCAL_PORT1 = 5000 # LOCAL_PORT1 LOCAL_PORT2 = 4000 # LOCAL_PORT2 TARGET_PORT = 3000 # TARGET_PORT BAUD_RATE = 115200 # BAUD_RATE
Provide WiringPi, RPI (Python) library demos.
Please refer to the pin correspondence table below
ETH | Raspberry Pi | |
Wiring encoding | Board physical pin number | |
5V | 5V | 5V |
GND | GND | GND |
RXD1 | 15 | 8 |
TXD1 | 16 | 10 |
CFG0 | 4 | 16 |
RST1 | 5 | 18 |
Execute the following command to enter the Raspberry Pi configuration:
sudo raspi-config
Choose Interfacing Options -> Serial -> No -> Yes:
You need to disable the login shell and enable the srial port hardware:
Reboot Raspberry Pi:
sudo reboot
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.71.tar.gz tar zxvf bcm2835-1.71.tar.gz cd bcm2835-1.71/ sudo ./configure sudo make sudo make check sudo make install #For more details, please refer to http://www.airspayce.com/mikem/bcm2835/
sudo apt-get install wiringpi #For Pi 4, you need to update it: cd /tmp wget https://project-downloads.drogon.net/wiringpi-latest.deb sudo dpkg -i wiringpi-latest.deb gpio -v #You will get 2.52 information if you install it correctly
#python2 sudo apt-get update sudo apt-get install python-pip sudo apt-get install python-pil sudo apt-get install python-numpy sudo pip install RPi.GPIO sudo pip install spidev #python3 sudo apt-get update sudo apt-get install python3-pip sudo apt-get install python3-pil sudo apt-get install python3-numpy sudo pip3 install RPi.GPIO sudo pip3 install spidev
Open the Raspberry Pi terminal and execute:
sudo apt-get install p7zip-full wget https://www.waveshare.com/w/upload/3/37/2-CH_UART_TO_ETH_CODE.7z 7z x 2-CH UART TO ETH_CODE. 7z -O./2-CH UART TO ETH_CODE sudo chmod 777 -R 2-CH UART TO ETH_CODE cd 2-CH UART TO ETH_CODE/RPi
cd WiringPi
If you configure the parameters through the upper computer, you can directly run RX_TX to test whether there is a problem with the transmission and whether the packet is lost. Otherwise, you can use the Serial Port Parameter Configuration to configure the device parameters. (Functions will be introduced later)
#Configure device parameters cd Serial Port Parameter Configuration make clean make ./CH9121_Config #Run the send and receive program cd .. cd RX_TX make clean make ./CH9121_RX_TX
cd Python
python3 Serial Port Parameter Configuration.py #You can directly run the following statement through the configuration parameters of the host computer, otherwise modify the parameters in the Serial Port Parameter Configuration.py according to your needs, and then run it. python3 RX_TX.py
Configure the parameters through the serial port (modify according to your needs):
uint8_t CH9121_Mode //Mode selection uint8_t CH9121_LOCAL_IP[4] //Local IP uint8_t CH9121_GATEWAY[4] //Gateway uint8_t CH9121_SUBNET_MASK[4] //Subnet mask uint8_t CH9121_TARGET_IP[4] //Target IP uint16_t CH9121_PORT1 //Local port uint16_t CH9121_TARGET_PORT //Target port uint32_t CH9121_BAUD_RATE //Serial port baud rate
void CH9121_TX_4_bytes(UCHAR data, int command); //Used for mode, whether the port is random, whether the port is disconnected from the network, whether to clear the serial port data, whether to open DHCP, //whether to open the serial port 2 void CH9121_TX_5_bytes(UWORD data, int command); //Used to set the port number of the serial port void CH9121_TX_7_bytes(UCHAR data[], int command);//Used to set IP, subnet mask, gateway void CH9121_TX_BAUD(UDOUBLE data, int command); //Used to set the baud rate of the serial port void CH9121_Eed(); //Update configuration parameters to EEPROM, execute configuration, reset 9121, leave configuration mode
Users only need to modify the values shown below in Serial Port Parameter Configuration.py to configure the serial port parameters of the module:
MODE = 1 #0: TCP Server 1: TCP Client 2: UDP Server 3: UDP Client GATEWAY = (169, 254, 88, 1) # GATEWAY TARGET_IP = (169, 254, 88, 17) # TARGET_IP LOCAL_IP = (169,254,88,70) # LOCAL_IP SUBNET_MASK = (255,255,255,0) # SUBNET_MASK LOCAL_PORT1 = 5000 # LOCAL_PORT1 LOCAL_PORT2 = 4000 # LOCAL_PORT2 TARGET_PORT = 3000 # TARGET_PORT BAUD_RATE = 115200 # BAUD_RATE
This example has been tested on Arduino uno. Just connect to Arduino uno as shown in the table below.
You can connect according to the following table.
ETH | Arduino | Function |
5V | 5V | Power input |
GND | GND | Power Ground |
RXD1 | TX | Serial data input |
TXD1 | RX | Serial data output |
CFG0 | D2 | Network configuration enable pin |
RST1 | D4 | Reset |
arduino IDE installation tutorial
Download the program in the information we provide, unzip it, and then enter the 2-CH UART TO ETH_CODE/Arduino directory
If you don't want to configure the parameters through the host computer, you can run the project in Serial_Port_Parameter_Configuration and double-click to open the .ino file.
Choose your development board and the corresponding port.
Change the corresponding parameters according to your needs, and then compile and download (you don't need to connect the RXD and TXD of ETH to the Arduino during the download process, otherwise the download will fail), as shown below:
After configuration, you can compile and download the project in RX_TX, double-click to open the .ino file.
After the download is successful, run SSCOM to connect to the ETH module, and you can send data to ETH, and ETH will return everything you sent to it.
(Remember to connect RXD and TXD to Arduino)
Configure the parameters through the serial port (modify according to your needs):
#define uint8_t unsigned char #define uint16_t short unsigned int #define uint32_t long unsigned int
uint8_t CH9121_Mode //Mode selection uint8_t CH9121_LOCAL_IP[4] //Local IP uint8_t CH9121_GATEWAY[4] //Gateway uint8_t CH9121_SUBNET_MASK[4] //Subnet mask uint8_t CH9121_TARGET_IP[4] //Target IP uint16_t CH9121_PORT1 //Local port uint16_t CH9121_TARGET_PORT //Target port uint32_t CH9121_BAUD_RATE //Serial port baud rate
void CH9121_TX_4_bytes(UCHAR data, int command); //Used for mode, whether the port is random, whether the port is disconnected from the network, whether to clear the serial port data, whether to open //DHCP,whether to open the serial port 2 void CH9121_TX_5_bytes(UWORD data, int command); //Used to set the port number of the serial port void CH9121_TX_7_bytes(UCHAR data[], int command);//Used to set IP, subnet mask, gateway void CH9121_TX_BAUD(UDOUBLE data, int command); //Used to set the baud rate of the serial port void CH9121_Eed(); //Update configuration parameters to EEPROM, execute configuration, reset 9121, leave configuration mode
The sample program we provide is based on STM32F103RBT6, and the connection method provided is also the pin of the corresponding STM32F103RBT6. If there is a need to transplant the program, please connect according to the actual pin
ETH | STM32 |
5V | 5V |
GND | GND |
RXD1 | PC10 |
TXD1 | PC11 |
CFG0 | PC12 |
RST1 | PD2 |
Take our STM32F103RBT6 as an example, the connection is as follows:
The routine is developed based on the HAL library. Please download the program in the data, find the STM32 program file directory, and open STM32\Serial_Port_Parameter_Configuration\MDK-ARM
CH9121.uvprojx under the directory, you can see the program.
Open main.c, you can see the program that can be modified by the user, modify the corresponding parameters according to your own needs, and then recompile and download.
(This function is mainly used to configure the serial port parameters. If you use the upper computer configuration, you can directly run the program in the RX_TX file to test the data transmission and reception, whether it will lose packets, etc.)
After the parameters are configured, download the program in the RX_TX folder to STM32.
After the download is successful, run SSCOM to connect to the ETH module, and you can send data to ETH, and ETH will return everything you sent to it.
uint8_t CH9121_Mode //Mode selection uint8_t CH9121_LOCAL_IP[4] //Local IP uint8_t CH9121_GATEWAY[4] //Gateway uint8_t CH9121_SUBNET_MASK[4] //Subnet mask uint8_t CH9121_TARGET_IP[4] //Target IP uint16_t CH9121_PORT1 //Local port uint16_t CH9121_TARGET_PORT //Target port uint32_t CH9121_BAUD_RATE //Serial port baud rate
void CH9121_TX_4_bytes(UCHAR data, int command); //Used for mode, whether the port is random, whether the port is disconnected from the network, whether to clear the serial port data, whether to open DHCP, //whether to open the serial port 2 void CH9121_TX_5_bytes(UWORD data, int command); //Used to set the port number of the serial port void CH9121_TX_7_bytes(UCHAR data[], int command);//Used to set IP, subnet mask, gateway void CH9121_TX_BAUD(UDOUBLE data, int command); //Used to set the baud rate of the serial port void CH9121_Eed(); //Update configuration parameters to EEPROM, execute configuration, reset 9121, leave configuration mode