<STM32> STM32CubeMX-project creation and timer control LED flashing (2)

This section mainly explains the general timer control LED flashing...

For a detailed explanation of the timer, please refer to the "STM32F4XXX Chinese Reference Manual". The information has detailed explanations and instructions. The documentation can be obtained from the author, or Baidu search is also available.

Without further ado, let's start coding. .

1. Open STM32CubeMX, select the corresponding development chip, and then enter the configuration interface, as shown in the figure below, you can also refer to the first section of this series of articles: <STM32> STM32CubeMX-basic project creation and LED light control (1)

insert image description here
After selecting the development chip, enter the configuration interface as shown below:
insert image description here
2. Configure the crystal oscillator and Debug download method
1. Configure the crystal oscillator:
insert image description here
2. Configure the Debug download method
insert image description here
3. Configure the peripheral LEDs and timers used

Note: Mouse scrolling zooms the chip map on the right...

1. Configure LED
The development board used by the author has two LEDs, LED0->PF9 and LED1->PF10; readers can select the corresponding GPIO according to the actual pins of their own development board.

As shown in the figure below, the mouse finds PF9, then left-click -> select "GPIO_Output", that is, select the output mode of GPIO. The same is true for PF10.
insert image description here
Modify the name of the symbol label of GPIO
After selecting the output mode in the previous step, right-click on PF9 with the mouse, then select "Enter User Lable", and then enter the corresponding name, the author enters LED0 here; similarly, enter LED1 for PF10.
insert image description here
insert image description here
2. Configuration timer

Timer 3 is selected here, and the flashing frequency of the LED light is configured to be 1s, that is, 0.5s on and 0.5s off; the configuration is as follows:
Steps 1, 2, and 3: select timer 3
Step 4: select the clock source of the timer- "Use the internal clock
Step 5: Configure the parameter interface of the timer;
Step 6: Set the frequency division factor of the timer, the final frequency of the timer F=72MHz/(7199+1)
Step 7: Set the counting method, count up, It means to count from 0;
Step 8: Set the count value to 4999, that is, how many times to count;
Step 9: Set the reload count value;
Step 10: Check the timer interrupt;

The time calculation formula of timer timing is t = 72MHz/(7199+1) * (4999+1);

Note: The frequency division number will be automatically incremented by 1, and the load value will also be automatically incremented by 1.
insert image description here
insert image description here
Fourth, project file generation configuration
1, clock selection
Input 168 in step 2, then press Enter, and confirm, here is the chip Main frequency, F4 series is generally 168 or 180, F1 series is generally 72.
insert image description here
2. Project file output project name and path and IDE configuration
Step 3: The output project name is generally named after the function or project name;
Step 4: The path location where the project is stored;
Step 5: Project output IDE mode, that is, the project opening method, here select "MDK-ARM", and KEIL5 can be used to open the project.
insert image description here
3. Project file output method
The configuration method can refer to the options in the figure below. For details, please refer to the first section of this series of articles: <STM32> STM32CubeMX-Basic Project Creation and LED Light Control (1) After
configuring, click Step 6, you can Generate code projects.
insert image description here
4. Open the project
After clicking step 6 in the above figure, the following figure will be displayed. Click the position of step 7 to open the project;
Note: Keil5 software must be installed on the computer in advance.
insert image description here
5. The function of engineering code is supplemented and improved

1. Supplement the main function LED control code as shown in the figure below:
Note: If the + on the left side of the name of main.c is useless, you can compile it once first.

insert image description here
In the main function, LED1 switches the state every 200ms, as follows:
insert image description here
2. Supplement the timer control part of the code, as shown below:

LED0 control:
insert image description here
Timer 3 is on.
insert image description here

6. Compile and download to view the phenomenon

The blinking frequency of LED0 is 1S, and the blinking frequency of LED1 is 0.4s. Consistent with code design features.
Complete the process of using the general-purpose timer. .

Summary: So far, the creation and control of the entire timer control LED flickering project has been completed;

Welcome to communicate: QQ: 759521350

-------------------If there are any deficiencies in the above content, please point out and exchange ----------------

--------------------------------Reprinted to indicate the source--------------- -----------------

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324486548&siteId=291194637
Recommended