Template: UART TO ETH for STM32 use
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
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.
- 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 //Local IP uint8_t CH9121_GATEWAY //Gateway uint8_t CH9121_SUBNET_MASK //Subnet mask uint8_t CH9121_TARGET_IP //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