//==文件exit.h============================================================ #ifndef __EXIT_H #define __EXIT_H #include "stm32f0xx.h" extern void EXIT_HALL_Init(void); #endif /* __EXIT_H */ //==文件exit.c============================================================ #include "global.h" #include "exit.h" //========霍尔 外部中断 初始化=========================== void EXIT_HALL_Init(void) { GPIO_InitTypeDef GPIO_InitStruct; //GPIO 定义 EXTI_InitTypeDef EXTI_InitStruct; //外部中断定义 NVIC_InitTypeDef NVIC_InitStruct; //嵌套中断定义 /* config the extiline(PB3 PB4 PB5) clock and AFIO clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); /* Configyre P[A|B|C|D|E]3 NIVC */ NVIC_InitStruct.NVIC_IRQChannel = EXTI2_3_IRQn; NVIC_InitStruct.NVIC_IRQChannelPriority = 0x00; NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStruct); /* Configyre P[A|B|C|D|E]4 5 NIVC */ NVIC_InitStruct.NVIC_IRQChannel = EXTI4_15_IRQn; NVIC_InitStruct.NVIC_IRQChannelPriority = 0x00; NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStruct); /* EXTI line gpio config(PB3 PB4 PB5) */ GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_Level_2; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd_UP; // 上拉输入 GPIO_Init(GPIOB, &GPIO_InitStruct); /* EXTI line(PB3 PB4 PB5) mode config */ EXTI_ClearITPendingBit(EXTI_Line3); EXTI_ClearITPendingBit(EXTI_Line4); EXTI_ClearITPendingBit(EXTI_Line5); SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource3); SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource4); SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource5); EXTI_InitStruct.EXTI_Line = EXTI_Line3|EXTI_Line4|EXTI_Line5; EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling ;//EXTI_Trigger_Falling;//上 下降沿中断 EXTI_InitStruct.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStruct); }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-11-04 16:53:52