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
Pin assignment :
PC14 pin: GPIO_Input (input mode)
PC15 pin: GPIO_Output (output mode)
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
PC14 pin configuration
GPIO mode: input mode
GPIO pull-up resistor/pull-down resistor: no pull-up resistor/pull-down resistor
Clock source: bypass clock source
Clock frequency: 16MHz
Fill in the project name, save path, IDE is MDK-ARM V5 and other information
Keil5 programming
New project, select STM32L071KBUx chip
Function analysis
Macro definition
Define key variables
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.
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.