Detailed Analysis of Marquee Experiment Based on STM32

We use C language to learn STM32 to deepen our understanding and apply relevant materials and official firmware standard library. So let's write a marquee experiment

Previous preparation

First, the development environment

Install MDK5 and import the official STM32 standard library.

STM32 official standard library name: stm32f4_dsp_stdperiph_lib

This STM32 official firmware standard library was previously available for download on the ST official website, and now it seems to be found on the official website.

Second, related application materials: STM32F4XX Chinese Reference Manual

related functions

First, because you want to use GPIO, you need to enable the IO port clock when using GPIO.

The RCC register is used to enable the IO clock. For knowledge of the RCC register, see section 6.3 of the Chinese Reference Manual.

Detailed Analysis of Marquee Experiment Based on STM32

Call the function: RCC_AHB1PeriphClockCmd();

Second, because the GPIO configuration is used, the GPIO library function is used.

1, GPIO library file

Header file: stm32f4xx_gpio.h

Source file: stm32f4xx_gpio.c

2, important GPIO library functions

(1) GPIO initialization function

Void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);

(2) Set the level output function

Output high level:

Void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);

Output low level:

Void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);

Programming

First, the implementation of the program:

LED1, LED2, LED3, and LED4 on the development board are cycled to achieve a water-light effect.

Hardware circuit diagram:

Second, write LED subroutine

1, led.h header file

2, led.c source file

Detailed Analysis of Marquee Experiment Based on STM32

3, how to enable GPIO clock in led.c

Detailed Analysis of Marquee Experiment Based on STM32

(1) Find "RCC_AHB1PeriphClockCmd(); in the library file rcc.hk" and copy and paste it down

Detailed Analysis of Marquee Experiment Based on STM32

(2) Click on the function and right click Go To Definition......... to find the entry parameters.

(3) Find the first entry parameter

Note: The role of assert_param is to determine whether the parameters passed to the function are valid;

Detailed Analysis of Marquee Experiment Based on STM32

Find the C group GPIO, copy and paste it into parentheses

Detailed Analysis of Marquee Experiment Based on STM32

Complete the first entry parameter:

If there are other IO ports enabled, use the or symbol "|" and add it later.

(4) Find two entry parameters:

Detailed Analysis of Marquee Experiment Based on STM32

To enable it, select ENABLE to copy and paste it.

Complete the second entry parameter and complete the call of the GPIO clock enable function:

4, how to configure GPIO function in led.c: For example, configure D group IO port

(1) Enter the function GPIO_Init(); , use the above method to configure the first entry function, complete the first entry function as follows:

(2) The second entry parameter is a structure

Copy and paste it first, remove the *, and define the structure:

Complete the second entry parameter:

(3) Using the structure to complete the GPIO configuration

GPIO_InitStructure adds points for each type of register configuration:

Configure the GPIO_Mode register, click GPIO_Mode, right click Go To Definition.........Query as follows:

Click GPIOMode_TypeDef again and the query is as follows:

Select the appropriate type, copy and paste it, and complete the configuration of GPIO_Mode:

Complete the GPIO configuration:

Third, write the main function

French Power Strip

French Power Strip,Surge Protector Power Strip,Power Strip With Flat Plug,Overload Protector Power Strip

CIXI KYFEN ELECTRONICS CO.,LTD, , https://www.kyfengroup.com