STM32中断为什么不行呢?
时间:10-02
整理:3721RD
点击:
- #include"stm32f10x.h"
- #include"stm32f10x_gpio.h"
- #include"stm32f10x_rcc.h"
- #include"delay.h"
- void RCC_Configuration(void)
- {
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOB,ENABLE);
- }
- void GPIO_Configuration(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
- GPIO_Init(GPIOD,&GPIO_InitStructure);
- GPIO_SetBits(GPIOD,GPIO_Pin_7);
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
- GPIO_Init(GPIOB,&GPIO_InitStructure);
- }
- void EXTI_Configuration(void)
- {
- EXTI_InitTypeDef EXTI_InitStructure;
- EXTI_ClearITPendingBit(EXTI_Line10);
- EXTI_InitStructure.EXTI_Line=EXTI_Line10;
- EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling;
- EXTI_InitStructure.EXTI_LineCmd=ENABLE;
- EXTI_Init(&EXTI_InitStructure);
- GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource10);
- }
- void NVIC_Configuration(void)
- {
- NVIC_InitTypeDef NVIC_InitStructure;
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
- NVIC_InitStructure.NVIC_IRQChannel=EXTI15_10_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
- NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
- void EXTI15_10_Handler(void)
- {
- if(EXTI_GetITStatus(EXTI_Line10)!=RESET)
- {
- GPIO_ResetBits(GPIOD,GPIO_Pin_7);
- EXTI_ClearFlag(EXTI_Line10);
- EXTI_ClearITPendingBit(EXTI_Line10);
- }
- }
- int main(void)
- {
- RCC_Configuration();
- GPIO_Configuration();
- EXTI_Configuration();
- NVIC_Configuration();
- while(1);
- }
哪位大哥给我看看!
管脚复用AFIO的时钟没有开启啊。RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);