
This article will show you how to use the STM32F407VET6 micro-controller to program the E22-400T22S module and perform simple communication. Of course, if you learn it, you can also apply it to all modules of E22, E220, and E32.
1. Zero-based construction of STM32 environment
The software used in this experiment is Kiel and STM32CubeMX. If you don’t have these two software, please download them online. This chapter teaches you how to build the fastest and simplest STM32 code running environment.
1.1 Download and install Kiel chip firmware package
The MCU used in this article is STM32F407VET6. For Kiel, the corresponding firmware package needs to be installed in advance. The firmware package download address is https://www.keil.arm.com/packs/stm32f4xx_dfp-keil/(of course, this is a foreign website that requires VPN to go to the external network). After downloading, double-click to run and install by default.
1.2 Codification files can be generated using STM32CubeMX.
To constitute a new project, launch the STM32CubeMX program and select “Serial No. 1” as illustrated in Figure 1.1. The interface in Figure 1.2 will then show up. To start out creating a new project, type STM32F407VET6 into the “Serial No. 1” input box, choose the chip in “Serial No. 2,” and then click “Serial No. 3”.
Figure 1.1
Enter the chip configuration interface, first configure the SWD burning port to facilitate program burning and debugging, as shown in Figure 1.3, click “Serial No. 1” SYS in the “System Core” tab, then find the selection box of “Serial No. 2”, we select “Serial Wire”, so that the program burning pin is configured
Then see Figure 1.4, find “Serial No. 1” RCC in the “System Core” tab, select the clock source of the micro-controller, click the drop-down menu of “Serial No. 2”, and select “Crystals/Ceramic Resonator”. Only high-speed clock is configured here. If a low-speed clock is required, you can configure the following tab “High Speed Clock (LSE)” by yourself.
Configure the GPIO of the LED. This pin is used to indicate the status of sending and receiving. The GPIO port of the MCU used in this article to control the LED is PC13. Here, select the IO port pin of your own MCU to control the LED. This article uses the PC13 port as an example. As shown in Figure 1.5, first find and click the PC13 chip pin of “Serial No. 1”, select “GPIO_Output”, and then click “Serial No. 3” to pop up the following selection box, as shown in “Serial No. 4”. You can refer to the configuration of “Serial No. 4”, and the GPIO port of the LED is configured.
Configure the GPIO of AUX. This pin is used to feedback the status of the E22 module. AUX is high, indicating that the battery is normal. The IO port of the micro-controller used in this article is PC1. The operation is shown in Figure 1.6. First, click “Serial No. 1”, then select
“Serial No. 2” mode to set it as input mode, then click “Serial No. 3”, then select “Serial No. 4”, and finally click “Serial No. 5”, and finally make a selection according to the content of “Serial No. 6”.
Configure the GPIO of M0. This pin is connected to the M0 pin of the E22 module and is used to control the mode of E22. The IO port of the micro-controller used in this article is PA1. The operation is shown in Figure 1.7. First, click “Serial No. 1”, then select “Serial No. 2” mode to set it as output mode, then click “Serial No. 3”, then select “Serial No. 4”, and finally click “Serial No. 5”, and finally make a selection according to the content of “Serial No. 6”.
Configure the GPIO of M1. This pin is connected to the M1 pin of the E22 module and is used to control the mode of E22. The IO port of the micro-controller used in this article is PD14. The operation is shown in Figure 1.8. First, click “Serial No. 1”, then select “Serial No. 2” mode to set it as output mode, then click “Serial No. 3”, then select “Serial No. 4”, and finally click “Serial No. 5”, and finally make a selection according to the content of “Serial No. 6”.
Next, configure the USART serial port. The operation is shown in Figure 1.9. Select “Serial No. 1”, click “Serial No. 2”, select “USART1”, then click the menu drop-down box of “Serial No. 3”, select “Asynchronous”, then click “Serial No. 4” to pop up the selection box, find “Serial No. 5”, and change the baud rate to “9600 Bit/s”. In this way, the serial port communication is configured successfully.
In order to realize USART serial port interrupt reception, the operation is shown in Figure 1.10. Select “Serial No. 1”, then check “Serial No. 4” to enable serial port interrupt.
Now let’s configure the system clock tree. The operation is shown in Figure 1.11. Click “Clock Configuration” in “Serial No. 1”, and then change the box in “Serial No. 2” to 8. We have selected an 8MHz crystal oscillator. You can modify it according to the actual crystal oscillator of your own micro-controller. Click “Serial No. 3” next, move by “Serial No. 4” and “Serial No. 5”; finally, alter the box to 72. The system clock frequency configured here is 72MHz. You can also choose to configure it to your desired and reasonable system clock frequency.
Finally, come to “Project Manager”, the operation is shown in Figure 1.12, first click “Serial No. 1”, then name your project file in the box of “Serial No. 2”, I named it “STM_T”, then select the storage location of your project file in “Serial No. 3”, and finally select “MD K-ARM” in the selection box “Serial No. 4”.
The last step, the operation is shown in Figure 1.13, we select “Serial No. 1”, then click “Serial No. 2”, the option here means that the project file only generates the necessary function library files, then check “Serial No. 3”, and finally click “Serial No. 4” to complete the generation of the project code.
2. One-way code transmission
2.1 Code writing
Double-click to open the Kiel project, and the operation is as shown in Figure 2.1. Follow the path shown in Figure 2.1, click “No. 1” Kiel’s run program, and the final page that opens should be as shown in Figure 2.2.
To achieve the function of sending information. The operation is shown in Figure 2.3. Click the mien.c file of “Serial No. 1”, and then write the code of “Serial No. 3” in the position of “Serial No. 2”, char msg[]= “Hello,Ebyte!\r\n”, Then proceed with the operation shown in Figure 2.4. Click the mien.c file of “Serial No. 1”, and then write the code of “Serial No. 3” in the position of “Serial No. 2”, #include “string.h”; Finally, proceed with the operation shown in Figure 2.5. Click the mien.c file of “Serial No. 1”, and then write the code of “Serial No. 3” in the position of “Serial No. 2”
2.2 Program burning and downloading
Prepare the MCU and the burner. The burner used in this article is St link. Connect St link to the pins of the MCU that need to be burned. The operation is shown in Figure 2.5. Click the magic wand of “Serial No. 1”, then click “Serial No. 2”, select ST-Link Debugger in the selection box on the left of “Serial No. 3”, then select “Settings”, and then a screen pops up. Check “Serial No. 4” to check whether the chip is detected, then compare “Serial No. 5” to modify, and click “Serial No. 6” to confirm.
Download the program according to Figure 2.7. First click “Serial No. 1” to compile, and then click “Serial No. 2” to download the program.
3. Practice
3.1 Physical preparation
Prepare two E22 modules, a single-chip microcomputer, a serial port tool, and several DuPont cables. The physical preparation for this article is shown in Figure 3.1. Use the serial port tool to open the corresponding host computer of E22. The host computer is downloaded from the official website. Reset all modules through the host computer first, as shown in Figure 3.2.
3.2 Connection
The E22 module is connected to the microcontroller. The connection is made according to the pins configured by yourself. The connection provided in this article is shown in Table 3.1. After the connection is completed, power on the micro-controller
The connection between another E22 and the serial port tool is similar. After the connection is completed, plug the serial port assistant into the computer, open the serial port assistant, open the corresponding COM port, and the received data information is shown in Figure 3.3. At this point, the one-way transmission function of the E22 module has been realized.