Template: UART TO ETH for Arduino use

From Waveshare Wiki
Jump to: navigation, search

This example has been tested on Arduino Uno. Just connect to Arduino uno as shown in the table below.

Working with Arduino

Hardware Connection

You can connect according to the following table.

Arduino connection pin correspondence
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

Direct connection

2-CH UART TO ETH-Arduino.png

Install and compile the software (Windows tutorial)

Run the demo

Download the demo 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.

CH9121-Arduino-2.jpg

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:
CH9121-Arduino-001.PNg

After configuration, you can compile and download the project in RX_TX, and 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.)
CH9121-Arduino-3.jpg

Code Analysis

Configure the parameters through the serial port (modify according to your needs):

  • Data type:
#define uint8_t unsigned char
#define uint16_t short unsigned int
#define uint32_t long unsigned int
  • This demo only has a simple configuration. If you need to configure other functions, you can refer to the serial port control command and configure it yourself:
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
  • According to the serial port control command, the following functions can be used to configure the parameters:
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