本人刚入门STM32F4系列(开发板为STM32F407VET6),在学习中断这一章节的时候出现了些问题.
拟设计代码实现功能: 使用中断完成 按下按键后led灯由点亮转向熄灭
问题: 编写完成代码后无法实现该功能
开发板部分原理图如下:(“LED指示灯”和“用户按键”)
设置按下K1按键(PE3)后,D3的LED灯熄灭(PA7)
以下为个人编写代码,可能会有不规范的地方,望见谅
#include "stm32f4xx.h"
#define PAout(n) *(volatile uint32_t *)(0x42000000 + (GPIOA_BASE + 0x10 - 0x40000000)*32 + n*4)
static GPIO_InitTypeDef GPIO_InitStructure;
static EXTI_InitTypeDef EXTI_InitStructure;
static NVIC_InitTypeDef NVIC_InitStructure;
//中断服务函数;
void EXTI3_IRQHandler(void) {
if (EXTI_GetITStatus(EXTI_Line3) == SET) {
PAout(7) = 1;
}
EXTI_ClearITPendingBit(EXTI_Line3);
}
int main(void) {
//初始化led灯;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//以下设置外部中断;
//初始化按键;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
//按下按键的外部中断设置;
RCC_AHB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);//系统时钟;
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE, EXTI_PinSource3); //设置PE3作为外部中断按键;
EXTI_InitStructure.EXTI_Line = EXTI_Line3;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
//配置外部中断的NVIC;
NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x08;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x08;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
while(1){
PAout(7) = 0;
}
}
恳请大佬帮忙分析解决(已被困扰一天)
谢谢!!!
|