Files
stm32-cnn/SYSTEM/gpio/gpio.c
2024-12-19 14:06:05 +08:00

41 lines
1.0 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "gpio.h"
#include "Function.h"
extern unsigned char flag_spi;
// GPIO初始化结构体
GPIO_InitTypeDef GPIO_InitStruct = {0};
// 初始化PB5引脚
void GPIO_Init(void)
{
__HAL_RCC_GPIOB_CLK_ENABLE(); // 使能GPIOB时钟
// 配置PB5为输入选择上升沿中断
GPIO_InitStruct.Pin = PPS_PIN; // 配置PB5引脚
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; // 配置为上升沿中断
GPIO_InitStruct.Pull = GPIO_NOPULL; // 不启用上拉或下拉电阻
HAL_GPIO_Init(PPS_GPIO_PORT, &GPIO_InitStruct); // 初始化PB5
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 2, 0); // 设置外部中断优先级
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn); // 使能中断
HAL_GPIO_WritePin(PPS_GPIO_PORT,PPS_PIN,GPIO_PIN_RESET); //开始为低电平 检测上升沿 可不设置
}
// 外部中断服务函数
void EXTI9_5_IRQHandler(void)
{
// 判断PB5的中断标志是否被设置
if (__HAL_GPIO_EXTI_GET_IT(PPS_PIN) != RESET)
{
// 清除中断标志
__HAL_GPIO_EXTI_CLEAR_IT(PPS_PIN);
// 处理上升沿事件
flag_spi = 0;
}
}