使用st的官网下载的stm32l152 discovery 的开发板的范例,但是GPIO中断却不行。
最后发现是 RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); // ----尤其注意这个位置,
没有进行syscfg的时钟初始化
void Board_GPIO_Init(void) //IO³õʼ»¯
{
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
//init GPIOC.13 ÉÏÀÊäÈë SENSOR_EN
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
// Connect Button EXTI Line to GPIO Pin 13
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); // ----尤其注意这个位置,
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC,EXTI_PinSource13);
EXTI_InitStructure.EXTI_Line = EXTI_Line13 ;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//EXTI_GenerateSWInterrupt(EXTI_Line13);
// ADD3: ADD2 : ADD1: ADD0
// ADD3 =PC12 ADD1 = PC14
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_14;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIO_InitStructure);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOD,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOD, &GPIO_InitStructure);
}
void EXTI15_10_IRQHandler(void)
{
static uint8_t state,Sensor_Module_Address;
uint8_t i;
if(EXTI_GetITStatus(EXTI_Line13) != RESET)
{
if(state == 1){
state=0;BOARD_LED_ON(LED3);
}
else{
state = 1;BOARD_LED_OFF(LED3);
}
Sensor_Module_Address = 0;
i = GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_12);
Sensor_Module_Address=i;
i = GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_9);
Sensor_Module_Address<<=1 ;Sensor_Module_Address+= i;
i = GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_14);
Sensor_Module_Address<<=1 ;Sensor_Module_Address+= i;
i = GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_2);
Sensor_Module_Address<<=1 ;Sensor_Module_Address+= i;
if(Sensor_Module_Address==9)
{
BOARD_LED_ON(LED1);
}
else
{
BOARD_LED_OFF(LED1);
}
// Clear the EXTI line 13 pending bit
EXTI_ClearITPendingBit(EXTI_Line13);
}
}