WAVESHARE CH9120 Serial Control Instruction Set Instructions

June 17, 2024
WAVESHARE

WAVESHARE-LOGO

WAVESHARE CH9120 Serial Control Instruction Set

WAVESHARE-CH9120-Serial-Control-Instruction-Set-
PRODUCT

Specifications

  • Model: CH9120
  • Version: V1.1
  • Control Interface: Serial
  • Supported Modes: TCP Server, TCP Client, UDP Server, UDP Client
  • Baud Rate: 9600
  • Packet Length: 512 bytes

Product Usage Instructions

Setting Network Configuration
To set up the network configuration of the CH9120, follow these steps:

  1. Set the mode using command code 0x10 (00 for TCP server, 01 for TCP client, 02 for UDP server, 03 for UDP client).
  2. Set the Device IP address using command code 0x11.
  3. Set the Subnet Mask using command code 0x12.
  4. Set the Gateway Address using command code 0x13.
  5. Set the Local Port using command code 0x14.
  6. Set the Destination IP Address using command code 0x15.
  7. Set the Destination Port using command code 0x16.
  8. Enable or disable the port randomly using the command code 0x17.

Setting Serial Port Configuration

To configure the serial port settings, follow these steps:

  1. Set the Baud Rate using command code 0x21.
  2. Set the Parity Bit, Data Bit, and Stop Bit using command code 0x22.
  3. Set the Packet Timeout Time using command code 0x23.
  4. Set the Network Disconnection using command code 0x24.
  5. Set the Packet Length using command code 0x25.
  6. Clear or not clear the serial port data using command code 0x26.
  7. Turn on or off the DHCP function using command code 0x33.

Reading Configuration
To read the configuration settings, use the corresponding command codes mentioned in the manual.

Overview

CH9120 supports two ways to enter the serial port configuration mode:

  1. The hardware CFG0 pin is pulled low to enter. When the CFG0 pin detects a low level, the CH9121 serial port data will be used as a configuration command. The CFG0 pin is pulled high to exit the configuration mode, and the configuration command is sent with a fixed baud rate of 9600bps.
  2. The serial port negotiation mode (which needs to be turned on through the network configuration software first) enters the serial port configuration mode. When the serial port idle time reaches 500ms, the serial data received by CH9121 is compared with {0x55,0xaa,0x5a}, the comparison is successful, CH9121 will reply one byte: 0xa5, after receiving the response data 0xa5 within 500ms, send 0xa5 to confirm entry Configuration mode. If there is an error in the data comparison of any link in the process, it is considered that these data bits are normal serial data, and this part of the data is sent to the network through the serial port, and the baud rate of the configuration command is sent to the actual baud rate of the serial port.

Command Code
The format of the command code sent by CH9121 is “0x57 0xab command code parameter (optional)”

Command code Parameter Return Command purpose
0x01 / Chip version number Query chip version

number

0x02| /| 0xaa| Reset chip
0x03| /| 0x00:TCP

disconnected

0x01:TCP connected

| Query TCP connection status
0x0d| /| 0xaa| Save parameters to

EEPROM

0x0e| /| 0xaa| Execute the configuration command,and Reset CH9121
0x5e| /| 0xaa| Exit serial port configuration mode (Only on the serial portnegotiating side is valid)
0x10| Setting mode: 00: TCP server 01: TCP client

02: UDP server

03: UDP client

| 0xaa| Set the network mode of the chip
---|---|---|---
0x11| Device IP address 0xc0 0xa8 0x01 0xc8(192.168.1.

| 0xaa| Set chip IP
0x12| Subnet mask:0xff 0xff 0xff

0x00(255.255.255.0

)

| 0xaa| Set chip mask
0x13| Gateway address:0xc0 0xa8 0x01 0x01(192.168.1.1)| 0xaa| Set chip gateway
0x14| The port number: 0xd0 0x07 (2000)| 0xaa| Set the local port of the chip
0x15| Destination IP address:0xc0 0xa8 0x01

0x64( 192.168.1.10

| 0xaa| Set the destination IP of the chip
0x16| Destination port: 0xe8 0x03(1000)| 0xaa| Set chip destination port
0x17| The port is enabled randomly: 0x00: disable

0x01: enable

| 0xaa| Set the local port of the chip in random
0x21| Baud rate: 0x80 0x25

0x00 0x00

(9600)

| 0xaa| Set the baud rate of serial port
0x22| 0x01 0x04 0x08

(1stop, no parity, 8data) Check:

00: Even

| 0xaa| Set serial port parity bit, data bit, stop bit
| 01: Odd

02: Mark

03: Space

04: None

| |
---|---|---|---
0x23| 0x01 0x00 0x00

0x00

(Serial timeout 1*5ms,after which four bytes need to be filled, and the

space is filled with zeros)

| 0xaa| Set serial port packet timeout time
0x24| 0x01: disconnect

0x00: no disconnection

| 0xaa| Network disconnected

Whether disconnect the network

0x25| 0x00 0x02 0x00

0x00

(Packing length 2*256=512 bytes)

| 0xaa| Set serial port receiving packet length
0x26| 0x01: clear

0x00: do not clear

| 0xaa| Set whether to clear theserial port data when port 1 is connected to

the network

0x33| 0x01: turn on 0x00: turn off| 0xaa| Turn on/off the DHCP function
0x60| /| Network mode(1 byte) 0x00: TCP server 0x01: TCP client 0x02: UDP

server

0x03: UDP client

| Read the working modeof chip port 1
0x61| /| Device IP address 0xc0 0xa8 0x01 0xc8(192.168.1.200)| Read the chip IP address
0x62| /| Subnet mask:0xff 0xff 0xff

0x00(255.255.255.0)

| Read chip mask
0x63| /| Gateway address: 0xc0 0xa8 0x01 0x01(192.168.1.1)| Read chip gateway
---|---|---|---
0x64| /| The port number: 0xd0 0x07 (2000)| Read chip port 1 source

port

0x65| /| Destination IP address:

0xc0 0xa8 0x01 0x64( 192.168.1.100)

| Read the destination IP address of chip port 1
0x66| /| Destination port: 0xe8 0xe3(1000)| Read the destination port number of chip port

1

0x71| /| Baud rate: 0x80 0x25

0x00 0x00

(9600)

| Read port 1 serial portbaud rate
0x72| /| 0x01 0x04 0x08

(1stop, no parity, 8data) Check: 00: Even

01: Odd

02: Mark

03: Space

04: None

| Read port 1 serial port check bit data bit stop bit
0x73| /| 0x01

(Serial timeout 1*5ms)

| Read port 1 serial porttimeout time
0x74| /| 0x01:Disconnect 0x00: No

disconnection

| Network disconnected

Whether disconnect the network

0x75| /| 0x00 0x02 0x00 0x00

(Packet length 2*256=512 bytes)

| Set the receiving packet length of the serial port
0x76| /| 0x01: Clear

0x000: Do not clear

| Whether to clear the serial port data when the network is connected

Specifications

Command code Parameter Return Command purpose
0x01 / 0xaa Query chip version number
0x02 / 0xaa Reset chip

Application Note

WAVESHARE-CH9120-Serial-Control-Instruction-Set-FIG-1

FAQ

  • How do you enter the configuration mode of CH9120?
    • You can enter the configuration mode by pulling the hardware CFG0 pin low or using the serial port negotiation mode.
  • What is the fixed baud rate for sending configuration commands when using the CFG0 pin?
    • The fixed baud rate is 9600bps.
  • How does the serial port negotiation mode work?
    • It compares the serial data received with a specific byte sequence and upon a successful match, CH9121 responds to confirm entry into the configuration mode.
  • What happens if there is an error in data comparison during serial port negotiation mode?
    • The data bits are considered normal serial data and are sent to the network through the serial port.
  • What is the format of command codes sent by CH9121?
    • The format is 0x57 0xab followed by the command code and an optional parameter.
  • Q: How to check the working mode of the chip?
    • A: Use command code 0x60 to read the network mode of chip port 1.
  • Q: What is the default baud rate?
    • A: The default baud rate is 9600 (0x80 0x25 0x00 0x00).

Read User Manual Online (PDF format)

Read User Manual Online (PDF format)  >>

Download This Manual (PDF format)

Download this manual  >>

WAVESHARE User Manuals

Related Manuals