Lanqiao Cup Internet of Things Basic Experiment 1.2--ex2 GPIO input experiment

Experiment name—GPIO input experiment

Experiment description

The purpose of the experiment : to master the input function of GPIO.

Experimental phenomenon : Press the USER button, LD5 lights up, and then goes out after release.

STM32CubeMX configuration

Insert picture description here

Pin assignment :
PC14 pin: GPIO_Input (input mode)
PC15 pin: GPIO_Output (output mode)

Insert picture description here

PC15 pin configuration

GPIO output level: high
GPIO mode: push-pull output
GPIO pull-up resistor/pull-down resistor: no pull-up resistor/pull-down resistor
Output speed: very fast

Insert picture description here

PC14 pin configuration

GPIO mode: input mode
GPIO pull-up resistor/pull-down resistor: no pull-up resistor/pull-down resistor

Insert picture description here

Clock source: bypass clock source
Clock frequency: 16MHz

Insert picture description here

Fill in the project name, save path, IDE is MDK-ARM V5 and other information

Insert picture description here

Keil5 programming

New project, select STM32L071KBUx chip

Insert picture description here

Function analysis

Macro definition

Insert picture description here

Define key variables

Insert picture description here

Read the PC14 pin level and judge after the USER button. If it is zero, the button is pressed and the LD5 indicator light is on. If it is 1, the button is released and the LD5 indicator light is turned off.

Insert picture description here

HAL library function analysis

GPIO input read function: HAL_GPIO_ReadPin(GPIOx, x_KEY)

Entry parameter description
GPIOx GPIO port, GPIOA~
GPIOC x_KEY, x button

GPIO output write function: HAL_GPIO_WritePin(GPIOx, GPIO_Pin, PinState)

Entry parameter description
GPIOx GPIO port, GPIOA~
GPIOC GPIO_Pin port corresponding Pin number (0-15)
PinState level state, GPIO_PIN_RESET (low level) and GPIO_PIN_SET (high level) two states.

Guess you like

Origin blog.csdn.net/m0_52468208/article/details/113880421