Template: UART TO ETH for STM32 use

From Waveshare Wiki
Jump to: navigation, search

STM32

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

Hardware Connection

STM32F103ZET connection pin correspondence
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:

2-CH UART TO ETH-STM32.png

Software Description

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.
CH9121 STM32 1.jpg

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.)
CH9121 STM32 2.jpg
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.
CH9121-Arduino-3.jpg

Code Analysis

  • This program 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