/******************************************************************************* * Function Name : EXTI_Configuration * Description : Configures the used EXTI lines. * Input : None * Output : None * Return : None *******************************************************************************/ void EXTI_Configuration(void) { /* Connect EXTI Line0 to PA.00 */ GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0); /* Configure EXTI Line0 to generate an interrupt on falling edge */ EXTI_InitStructure.EXTI_Line = EXTI_Line0; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Connect EXTI Line13 to PC.13 */ GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource13); /* Configure EXTI Line13 to generate an event on falling edge */ EXTI_InitStructure.EXTI_Line = EXTI_Line13; EXTI_Init(&EXTI_InitStructure); /* Connect Key Button EXTI Line to GPIO Key Button Pin */ GPIO_EXTILineConfig(GPIO_PORT_SOURCE_KEY_BUTTON, GPIO_PIN_SOURCE_KEY_BUTTON); /* Configure Key Button EXTI Line to generate an event on falling edge */ EXTI_InitStructure.EXTI_Line = EXTI_LINE_KEY_BUTTON; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Event; EXTI_Init(&EXTI_InitStructure); }
/******************************************************************************* * Function Name : EXTI_Configuration. * Description : Configure the EXTI lines for Key and Tamper push buttons. * Input : None. * Output : None. * Return value : The direction value. *******************************************************************************/ void EXTI_Configuration(void) { EXTI_InitTypeDef EXTI_InitStructure; /* Configure gpio as input : Button Left-WKUP */ /* Connect EXTI Line to gpio pin */ GPIO_EXTILineConfig(GPIO_PORTSOURCE_KEY, GPIO_PINSOURCE_KEY1); /* Configure EXTI Line to generate an interrupt */ EXTI_InitStructure.EXTI_Line = GPIO_EXTI_Line_KEY1; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Configure gpio as input : Button Right-USER */ /* Connect EXTI Line to gpio pin */ GPIO_EXTILineConfig(GPIO_PORTSOURCE_KEY, GPIO_PINSOURCE_KEY2); /* Configure EXTI Line to generate an interrupt */ EXTI_InitStructure.EXTI_Line = GPIO_EXTI_Line_KEY2; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* USB Wakeup from suspend event */ EXTI_ClearITPendingBit(EXTI_Line18); EXTI_InitStructure.EXTI_Line = EXTI_Line18; // USB resume from suspend mode EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); }
//================================================================================================ // //================================================================================================ void ExtI_Configuration(void) { EXTI_InitTypeDef EXTI_InitStruct; GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0); EXTI_InitStruct.EXTI_Line = EXTI_Line0; EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStruct.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStruct); EXTI_ClearITPendingBit(EXTI_Line0); GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource1); EXTI_InitStruct.EXTI_Line = EXTI_Line1; EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStruct.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStruct); EXTI_ClearITPendingBit(EXTI_Line1); }
/** * @file Exti_Config * @brief 调用函数库,初始化中断配置 * @param 无 * @retval 无 */ void Exti_Config(void) { /*查看外部中断/事件线路映像 PA0、PB0、PC0、PD0、PE0、PF0、PG0 ————>映像于 EXTI0 PA1、PB1、PC1、PD1、PE1、PF1、PG1 ————>映像于 EXTI1 PA2、PB2、PC2、PD2、PE2、PF2、PG2 ————>映像于 EXTI2 PA3、PB3、PC3、PD3、PE3、PF3、PG3 ————>映像于 EXTI3 .......依次类推,每个外部中断都有一个事件线路映射*/ //定义一个EXTI_InitTypeDef 类型的结构体 EXTI_InitTypeDef EXTI_InitStructure; //使能AFIO功能的时钟 RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); //设置PB14,PB15,PB5作为中断线路 GPIO_EXTILineConfig(KEY1_BUTTON_EXTI_PORT_SOURCE, KEY1_BUTTON_EXTI_PIN_SOURCE); GPIO_EXTILineConfig(KEY2_BUTTON_EXTI_PORT_SOURCE, KEY2_BUTTON_EXTI_PIN_SOURCE); GPIO_EXTILineConfig(KEY3_BUTTON_EXTI_PORT_SOURCE, KEY3_BUTTON_EXTI_PIN_SOURCE); //选择中断线路14,15,5 EXTI_InitStructure.EXTI_Line = KEY1_BUTTON_EXTI_LINE | KEY2_BUTTON_EXTI_LINE | KEY3_BUTTON_EXTI_LINE; //设置为中断请求触发模式 EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //设置为下降沿触发 EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;//下降沿触发 //设置为使能中断线 EXTI_InitStructure.EXTI_LineCmd = ENABLE; //调用库函数,初始化中断 EXTI_Init(&EXTI_InitStructure); }
void EXTI_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; //EXTI IN GPIO Config GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4; //PB3-Pitch PB4-Yaw GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //Set to Inpit GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //GPIO Speed GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource3); GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource4); EXTI_InitStructure.EXTI_Line = EXTI_Line3 | EXTI_Line4; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); EXTI_GenerateSWInterrupt(EXTI_Line3 | EXTI_Line4); EXTI_ClearITPendingBit(EXTI_Line3 | EXTI_Line4); NVIC_EnableIRQ(EXTI3_IRQn); // Enable interrupt NVIC_EnableIRQ(EXTI4_IRQn); // Enable interrupt }
/** * @brief Configures the different EXTI lines. * @param None * @retval None */ void EXTI_Configuration(void) { EXTI_InitTypeDef EXTI_InitStructure; #ifdef STM32F10X_HD_VL /* Select the EXTI Line11 the GPIO pin source */ GPIO_EXTILineConfig(GPIO_PortSourceGPIOF, GPIO_PinSource11); #else GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource11); #endif /* EXTI line11 configuration -----------------------------------------------*/ EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Event; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_Line = EXTI_Line11; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Select the EXTI Line15 the GPIO pin source */ GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource15); /* EXTI line15 configuration -----------------------------------------------*/ EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Event; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_Line = EXTI_Line15; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); }
//外部中断初始化程序 //初始化PA0,PA13,PA15为中断输入. void EXTIX_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; //NVIC_InitTypeDef NVIC_InitStructure; GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE); //关闭jtag RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO,ENABLE); //init GPIOA.13,GPIOA.15 上拉输入 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOA, &GPIO_InitStructure); //init GPIOA.0 下拉输入 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; GPIO_Init(GPIOA, &GPIO_InitStructure); //GPIOA.13 GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_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); //GPIOA.15 GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource15); EXTI_InitStructure.EXTI_Line=EXTI_Line15; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); //GPIOA.0 GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0); EXTI_InitStructure.EXTI_Line=EXTI_Line0; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); // NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //使能按键所在的外部中断通道 // NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //先占优先级4位,共16级 // NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01; //先占优先级0位,从优先级4位 // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道 // NVIC_Init(&NVIC_InitStructure); // NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; //使能按键所在的外部中断通道 // NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //先占优先级4位,共16级 // NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02; //先占优先级0位,从优先级4位 // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道 // NVIC_Init(&NVIC_InitStructure); }
/******************************************************************************* * unction Name : EXTI_Configuration. * Description : Configure the EXTI lines for Key and Tamper push buttons. * Input : None. * Output : None. * Return value : The direction value. ******************************************************************************/ void EXTI_Configuration(void) { /* Connect Button EXTI Line to Button GPIO Pin */ GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource14); //GPIOb14 GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource8); /* Configure EXTI_Line8 line to generate an interrupt on rising & falling edges */ EXTI_InitStructure.EXTI_Line = EXTI_Line8; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Clear the EXTI_Line1 line pending bit */ EXTI_ClearITPendingBit(EXTI_Line8); /* Configure EXTI_Line14 line to generate an interrupt on rising & falling edges */ EXTI_InitStructure.EXTI_Line = EXTI_Line14; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Clear the EXTI_Line1 line pending bit */ EXTI_ClearITPendingBit(EXTI_Line14); }
/** * @brief Configure PA.13 in interrupt mode * @param None * @retval None */ void EXTIX_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE); //关闭jtag RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO,ENABLE); //初始化 KEY0-->GPIOA.13,KEY1-->GPIOA.15 上拉输入 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOA, &GPIO_InitStructure); // 初始化 WK_UP-->GPIOA.0 下拉输入 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; GPIO_Init(GPIOA, &GPIO_InitStructure); //GPIOA.13 中断线以及中断初始化配置 GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_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); //根据EXTI_InitStruct中指定的参数初始化外设EXTI寄存器 //GPIOA.15 中断线以及中断初始化配置 GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource15); EXTI_InitStructure.EXTI_Line=EXTI_Line15; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); //根据EXTI_InitStruct中指定的参数初始化外设EXTI寄存器 //GPIOA.0 中断线以及中断初始化配置 GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0); EXTI_InitStructure.EXTI_Line=EXTI_Line0; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); //根据EXTI_InitStruct中指定的参数初始化外设EXTI寄存器 NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //使能按键所在的外部中断通道 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //抢占优先级2, NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01; //子优先级1 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道 NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; //使能按键所在的外部中断通道 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //抢占优先级2 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02; //子优先级2 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道 NVIC_Init(&NVIC_InitStructure); //根据NVIC_InitStruct中指定的参数初始化外设NVIC寄存器 }
void EXTIX_Init(void) { EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; KEY_Init(); //IO口初始化 RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); //打开AFIO时钟以操作中断配置寄存器? GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource13); //PC3 映射到中断线EXTI13上 GPIO_EXTILineConfig(GPIO_PortSourceGPIOE,GPIO_PinSource0); //PE0 映射到中断线exti0上 //初始化外部中断线 EXTI_InitStructure.EXTI_Line = 0x2000; //使用线路为:13, EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //中断 EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //下降沿 EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); EXTI_InitStructure.EXTI_Line = EXTI_Line0; //使用线路为:0, EXTI_Init(&EXTI_InitStructure); //=设置中断优先级 NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //外部中断线15-10中断 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; //外部中断线0中断 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; NVIC_Init(&NVIC_InitStructure); }
static void EXTI_Configuration() { /* key1, key2 */ { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(key1_rcc, ENABLE); RCC_APB2PeriphClockCmd(key2_rcc, ENABLE); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Pin = key1_pin; GPIO_Init(key1_gpio, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = key2_pin; GPIO_Init(key2_gpio, &GPIO_InitStructure); } GPIO_EXTILineConfig(key1_portsource, key1_pinsource); GPIO_EXTILineConfig(key2_portsource, key2_pinsource); /* Configure EXTI */ EXTI_Enable(1, 1); EXTI_Enable(2, 1); }
void EXTIX_Init(void) { EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource6); GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource7); EXTI_InitStructure.EXTI_Line=EXTI_Line6; //KEY2 EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); EXTI_InitStructure.EXTI_Line=EXTI_Line7; //KEY2 EXTI_Init(&EXTI_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); }
/******************************************************************************* * Function Name : EXTI_Configuration. * Description : Configure the EXTI lines for Key and Tamper push buttons. * Input : None. * Output : None. * Return value : The direction value. *******************************************************************************/ void EXTI_Configuration(void) { EXTI_InitTypeDef EXTI_InitStructure; /* Configure gpio as input : Button Left-WKUP */ /* Connect EXTI Line to gpio pin */ GPIO_EXTILineConfig(GPIO_PORTSOURCE_KEY, GPIO_PINSOURCE_KEY1); /* Configure EXTI Line to generate an interrupt */ EXTI_InitStructure.EXTI_Line = GPIO_EXTI_Line_KEY1; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Configure gpio as input : Button Right-USER */ /* Connect EXTI Line to gpio pin */ GPIO_EXTILineConfig(GPIO_PORTSOURCE_KEY, GPIO_PINSOURCE_KEY2); /* Configure EXTI Line to generate an interrupt */ EXTI_InitStructure.EXTI_Line = GPIO_EXTI_Line_KEY2; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); }
void KEY_Initialize (void) { /******************** Clock Enable ********************/ /* Enable GPIOA clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); /******************** GPIO configure ********************/ GPIO_InitTypeDef GPIO_InitStructure; /* Configure gpio as input : Button WKUP & USER */ GPIO_InitStructure.GPIO_Pin = GPIO_KEY1_PIN | GPIO_KEY2_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIO_KEY, &GPIO_InitStructure); /******************** Fuction configure ********************/ EXTI_InitTypeDef EXTI_InitStructure; /* Configure gpio as input : Button Left-WKUP */ /* Connect EXTI Line to gpio pin */ GPIO_EXTILineConfig(GPIO_PORTSOURCE_KEY, GPIO_PINSOURCE_KEY1); /* Configure EXTI Line to generate an interrupt */ EXTI_InitStructure.EXTI_Line = GPIO_EXTI_Line_KEY1; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Configure gpio as input : Button Right-USER */ /* Connect EXTI Line to gpio pin */ GPIO_EXTILineConfig(GPIO_PORTSOURCE_KEY, GPIO_PINSOURCE_KEY2); /* Configure EXTI Line to generate an interrupt */ EXTI_InitStructure.EXTI_Line = GPIO_EXTI_Line_KEY2; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /******************** Interrupt configure ********************/ NVIC_InitTypeDef NVIC_InitStructure; /* Enable the EXTI0 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Enable the EXTI1 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); }
/******************** - 传感器IO中断设置 *********************/ void SENSOR_EXTI_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; // RCC_APB2PeriphResetCmd(RCC_APB2Periph_AFIO, ENABLE); // RCC_APB2PeriphResetCmd(RCC_APB2Periph_AFIO,DISABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE);//PB1 ACCER_INT2 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);//PA6 GYRO_DR NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); GPIO_ResetBits(GPIOB, GPIO_Pin_1); GPIO_ResetBits(GPIOA, GPIO_Pin_6); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;//PB1 ACCER_INT2 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;//PA6 GYRO_DR GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); EXTI_DeInit(); GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource1); GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource6); EXTI_InitStructure.EXTI_Line = EXTI_Line1;//参考手册9.2.5节 EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); EXTI_InitStructure.EXTI_Line = EXTI_Line6;//参考手册9.2.5节 EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); EXTI_GenerateSWInterrupt(EXTI_Line1); EXTI_GenerateSWInterrupt(EXTI_Line6); }
/************************************************************* 初始化按键和蜂鸣器 *************************************************************/ void init_key(void) { uint8 x; NVIC_InitTypeDef NVIC_InitStructure; //=====================下面初始化开关量的状态读取函数============== key1.read_start = Read_Key1; key2.read_start = Read_Key2; key3.read_start = Read_Key3; l_lidi.read_start = Read_L_LIDI; r_lidi.read_start = Read_R_LIDI; charge_dc.read_start = Read_Charge_Dc; charge_seat.read_start = Read_Charge_Seat; s_current.read_start = Read_S_Current; l_bump.read_start = Read_L_Bump; r_bump.read_start = Read_R_Bump; for(x=0; x<4; x++) { //当有按键时为1,那么开始就为0 hightaction[x]->sign = 0; hightaction[x]->number = 0; hightaction[x]->key = 0; } for(x=0; x<6; x++) { //当有按键时为0,那么开始就为1 lowaction[x]->sign = 1; lowaction[x]->number = 0; lowaction[x]->key = 1; } key_time = FALSE; GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource1); GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource2); GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource3); GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource11); GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource12); EXTI->FTSR |= 0xe; EXTI->RTSR |= 0x1800; NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 13; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQChannel; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQChannel; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQChannel; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQChannel; NVIC_Init(&NVIC_InitStructure); }
/******************************************************************************* * Function Name : NVIC_Configuration * Description : Configures Vector Table base location. * Input : None * Output : None * Return : None *******************************************************************************/ void NVIC_Configuration(void) { EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; /* Configure one bit for preemption priority */ #if defined (VECT_TAB_RAM) /* Set the Vector Table base location at 0x20000000 */ NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); #elif defined(VECT_TAB_FLASH_IAP) NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x2000); #else /* VECT_TAB_FLASH */ /* Set the Vector Table base location at 0x08000000 */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); #endif /* Configure the NVIC Preemption Priority Bits */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); /* Enable the USART1 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; //设置串口1中断 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Connect Key Button EXTI Line to Key Button GPIO Pin */ GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource12); /* Configure Key Button EXTI Line to generate an interrupt on falling edge */ EXTI_InitStructure.EXTI_Line = EXTI_Line12; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Enable the EXTI15_10 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE; NVIC_Init(&NVIC_InitStructure); /* Connect Key Button EXTI Line to Key Button GPIO Pin */ GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource0); /* Configure Key Button EXTI Line to generate an interrupt on falling edge */ EXTI_InitStructure.EXTI_Line = EXTI_Line0; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = DISABLE; EXTI_Init(&EXTI_InitStructure); /* Enable the EXTI15_10 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE; NVIC_Init(&NVIC_InitStructure); }
void initStepDirInput() { GPIO_InitTypeDef GPIO_InitStructure; //PA6 as STEP input GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; GPIO_Init(GPIOA, &GPIO_InitStructure); //PA7 as DIR pin GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; GPIO_Init(GPIOA, &GPIO_InitStructure); //PA5 as ENA pin GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource6); //STEP pin GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource5); //ENA pin EXTI_InitTypeDef EXTI_initStructure; EXTI_initStructure.EXTI_Line = EXTI_Line6; EXTI_initStructure.EXTI_Mode = EXTI_Mode_Interrupt; #if STEP_POLARITY == 1 EXTI_initStructure.EXTI_Trigger = EXTI_Trigger_Rising; #else EXTI_initStructure.EXTI_Trigger = EXTI_Trigger_Falling; #endif EXTI_initStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_initStructure); EXTI_initStructure.EXTI_Line = EXTI_Line5; EXTI_initStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_initStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; EXTI_initStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_initStructure); NVIC_InitTypeDef nvicStructure; nvicStructure.NVIC_IRQChannel = EXTI9_5_IRQn; nvicStructure.NVIC_IRQChannelPreemptionPriority = 0; nvicStructure.NVIC_IRQChannelSubPriority = 2; nvicStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&nvicStructure); }
void EXTILine_Config(void)//外部中断配置 { EXTI_InitTypeDef EXTI_InitStructure; GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, AxisEXTIPinSource[0]); GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, AxisEXTIPinSource[0]); GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, AxisEXTIPinSource[0]); GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, AxisEXTIPinSource[0]); EXTI_InitStructure.EXTI_Line = AxisEXTILine[0] | AxisEXTILine[1] | AxisEXTILine[2] | AxisEXTILine[3]; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); }
/** * @fun void bsp_KeyInit * @brief 按键初始化函数 * @author huangzibo * @param None * * @retval */ void bsp_KeyInit(void) { EXTI_InitTypeDef EXTI_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; //步骤一:开启GPIOC时钟和辅助功能IO时钟 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO, ENABLE); //步骤二:配置PC0为浮空输入 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOC, &GPIO_InitStructure); //步骤三:连接EXTI0外部中断线到端口PC0 GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource0); GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource1); GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource2); //步骤四:配置EXTI0外部中断线 EXTI_InitStructure.EXTI_Line = EXTI_Line0 | GPIO_Pin_1 | GPIO_Pin_2 ; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); //步骤五:配置中断优先级组(同一个工程中,优先级组必须相同,这里设置为组2) NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//优先级组2:2位抢占优先级,2为子优先级 //步骤六:配置中断通道优先级 NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;//中断通道 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); //步骤六:配置中断通道优先级 NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;//中断通道 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); //步骤六:配置中断通道优先级 NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn;//中断通道 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); }
void Button_GPIO_Config(void) { /* GPIOA Periph clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_Init(GPIOD, &GPIO_InitStructure); EXTI_InitTypeDef EXTI_InitStructure; /* Connect EXTI0 Line to PA.00 pin */ GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0); GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource8); GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource13); GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource3); /* Configure EXTI0 line */ EXTI_InitStructure.EXTI_Line = EXTI_Line0 | EXTI_Line3 | EXTI_Line8 | EXTI_Line13; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); NVIC_InitTypeDef NVIC_InitStructure; /* Enable and set EXTI0 Interrupt to the lowest priority */ NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; NVIC_Init(&NVIC_InitStructure); }
void enable_button_interrupts(void) { EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; /* Enable the AFIO clock. GPIO_EXTILineConfig sets registers in * the AFIO. */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); /* Connect EXTI Line 0 to the button GPIO Pin */ GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0); /* Configure the EXTI line to generate an interrupt when the button is * pressed. The button pin is high when pressed, so it needs to trigger * when rising from low to high. */ EXTI_InitStructure.EXTI_Line = EXTI_Line0; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Enable and set Button EXTI Interrupt to the lowest priority */ NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); }
void SENSOR_Init(Sensor_TypeDef SensorIndex, Sensor_Mode_TypeDef Sensor_Mode) { GPIO_InitTypeDef GPIO_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB2PeriphClockCmd(SENSOR_GPIO_CLK[SensorIndex],ENABLE); GPIO_InitStructure.GPIO_Pin=SENSOR_GPIO_PIN[SensorIndex]; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(SENSOR_GPIO_PORT[SensorIndex],&GPIO_InitStructure); if (Sensor_Mode==Mode_EXTI) { // RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); GPIO_EXTILineConfig(SENSOR_GPIO_PORT_SOURCE[SensorIndex], SENSOR_GPIO_PIN_SOURCE[SensorIndex]); EXTI_StructInit(&EXTI_InitStructure); EXTI_InitStructure.EXTI_Line=SENSOR_GPIO_EXTI_LINE[SensorIndex]; EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Rising;//EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd=ENABLE; EXTI_Init(&EXTI_InitStructure); NVIC_InitStructure.NVIC_IRQChannel=SENSOR_GPIO_IRQn[SensorIndex]; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0x0F; NVIC_InitStructure.NVIC_IRQChannelSubPriority=0x0F; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init(&NVIC_InitStructure); } }
/* ************************************************** 外部中断初始化 参数1:GPIO中断源组别 GPIO_PortSourceGPIOA-G 参数2:中断线路 GPIO_PinSource0-15 参数3:外部中断模式 EXTI_Mode_Event 事件请求 EXTI_Mode_Interrupte 中断请求 参数4:触发方式 EXTI_Trigger_Falling 下降沿触发 EXTI_Trigger_Rising 上升沿触发 EXTI_Trigger_Rising_Falling 上升沿或下降沿触发 ************************************************** */ void abba_EXIT_Init(uint8_t GPIO_PortSource,uint8_t GPIO_PinSource,EXTIMode_TypeDef EXTI_Mode,EXTITrigger_TypeDef EXTI_Trigger) { uint32_t EXTI_Line; uint8_t i,GPIO_Pin_temp = GPIO_PinSource0; EXTI_InitTypeDef EXTI_temp; GPIO_EXTILineConfig(GPIO_PortSource, GPIO_PinSource); EXTI_Line = EXTI_Line0; for(i=0;i<16;i++) { if(GPIO_PinSource == GPIO_Pin_temp) { break; } GPIO_Pin_temp++; EXTI_Line += EXTI_Line; } EXTI_temp.EXTI_Line = EXTI_Line; EXTI_temp.EXTI_Mode = EXTI_Mode; EXTI_temp.EXTI_Trigger = EXTI_Trigger; EXTI_temp.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_temp); }
void iNEMO_Button_Init(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode) { EXTI_InitTypeDef EXTI_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* Enable Push Button GPIO clocks */ RCC_APB2PeriphClockCmd(BUTTON_CLK[Button], ENABLE); /* Configure Push Button pin as input floating */ GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button]; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure); if (Button_Mode == BUTTON_MODE_EXTI) { /* Connect Button EXTI Line to Button GPIO Pin */ GPIO_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]); /* Configure Button EXTI line */ EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button]; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = BUTTON_EDGE[Button]; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); } }
static void I2C_INT_Config(void) { // Periph CLK init RCC_APB2PeriphClockCmd(I2C_INT_CLK, ENABLE); // Pin configuration for nINT_Joy GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = I2C_INT; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(I2C_INT_PORT, &GPIO_InitStructure); GPIO_EXTILineConfig(GPIO_PortSourceGPIOF, GPIO_PinSource10); // EXTI configuration EXTI_InitTypeDef EXTI_InitStructure; EXTI_InitStructure.EXTI_Line = EXTI_Line10; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_Init(&EXTI_InitStructure); // NVIC configuration NVIC_InitTypeDef NVIC_InitStructure; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); }
void LSM303DLH_Magn_DRDY_Config(void) { NVIC_InitTypeDef NVIC_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* Enable _MAG_DRDY pad GPIO clocks */ RCC_APB2PeriphClockCmd(LSM_M_DRDY_RCC_Port, ENABLE); /* Configure MAG_DRDY pin as input floating */ GPIO_InitStructure.GPIO_Pin = LSM_M_DRDY_Pin; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(LSM_M_DRDY_Port, &GPIO_InitStructure); /* Connect MAG_DRDY_EXTI_Line to MAG_DRDY Pin */ GPIO_EXTILineConfig(LSM_M_DRDY_Port_Source, LSM_M_DRDY_Pin_Source); /* Configure MAG_DRDY_EXTI_Line to generate an interrupt on MAG_DRDY_Edge edge */ EXTI_InitStructure.EXTI_Line = LSM_M_DRDY_EXTI_Line; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = LSM_M_DRDY_Edge; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Enable the MAG_DRDY_EXTI_IRQCHANNEL Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = LSM_M_DRDY_EXTI_IRQCHANNEL; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = LSM_M_DRDY_Preemption_Priority; NVIC_InitStructure.NVIC_IRQChannelSubPriority = LSM_M_DRDY_Sub_Priority; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); }
bool hcsr04_init(sonar_config_t config) { bool returnvalue = false; GPIO_InitTypeDef GPIO_InitStructure; EXTI_InitTypeDef EXTIInit; uint8_t bufdaddy[2]; // Dummy for i2c testread // enable AFIO for EXTI support - already done is drv_system.c // RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph, ENABLE); // cfg.snr_type = X; 0 = PWM56, 1 = RC78, 2 = I2C (DaddyWalross), 3 = MBPWM56, 4 = MBRC78 switch(config) { case sonar_pwm56: trigger_pin = GPIO_Pin_8; // PWM5 (PB8) - 5v tolerant echo_pin = GPIO_Pin_9; // PWM6 (PB9) - 5v tolerant exti_line = EXTI_Line9; exti_pin_source = GPIO_PinSource9; exti_irqn = EXTI9_5_IRQn; returnvalue = true; break; case sonar_rc78: trigger_pin = GPIO_Pin_0; // RX7 (PB0) - only 3.3v ( add a 1K Ohms resistor ) echo_pin = GPIO_Pin_1; // RX8 (PB1) - only 3.3v ( add a 1K Ohms resistor ) exti_line = EXTI_Line1; exti_pin_source = GPIO_PinSource1; exti_irqn = EXTI1_IRQn; returnvalue = true; break; case sonar_i2cDW: // Deal with I2C daddy walross sonar delay(1000); // sleep for 1000ms to startup sonar returnvalue = i2cRead(SONARDW_ADDRESS, SONARDW_DISTANCE_OUT, 2, bufdaddy); break; } if (config == sonar_pwm56 || config == sonar_rc78) { if (cfg.snr_type == 0 || cfg.snr_type == 1) // Check for HC-SR04 PulseLimitInUs = 24000; // HC-SR04 Limit 413 cm if (cfg.snr_type == 3 || cfg.snr_type == 4) // Check for Maxbotics (no "else" stuff here to make it expandable) PulseLimitInUs = 62000; // Datasheet Limit 62ms // tp - trigger pin GPIO_InitStructure.GPIO_Pin = trigger_pin; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); // ep - echo pin GPIO_InitStructure.GPIO_Pin = echo_pin; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOB, &GPIO_InitStructure); // setup external interrupt on echo pin GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, exti_pin_source); EXTI_ClearITPendingBit(exti_line); EXTIInit.EXTI_Line = exti_line; EXTIInit.EXTI_Mode = EXTI_Mode_Interrupt; EXTIInit.EXTI_Trigger = EXTI_Trigger_Rising_Falling; EXTIInit.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTIInit); NVIC_EnableIRQ(exti_irqn); last_measurement = 0; // Force 1st measurement in XXX_get_distance } return returnvalue; // Return the status of initialization }
/** * @brief Configures the IO expander Interrupt line and GPIO in EXTI mode. * @param None * @retval None */ static void IOE_EXTI_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; /* Enable Button GPIO clock */ RCC_APB2PeriphClockCmd(IOE_IT_GPIO_CLK | RCC_APB2Periph_AFIO, ENABLE); /* Configure Button pin as input floating */ GPIO_InitStructure.GPIO_Pin = IOE_IT_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(IOE_IT_GPIO_PORT, &GPIO_InitStructure); /* Connect Button EXTI Line to Button GPIO Pin */ GPIO_EXTILineConfig(IOE_IT_EXTI_PORT_SOURCE, IOE_IT_EXTI_PIN_SOURCE); /* Configure Button EXTI line */ EXTI_InitStructure.EXTI_Line = IOE_IT_EXTI_LINE; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Enable and set Button EXTI Interrupt to the lowest priority */ NVIC_InitStructure.NVIC_IRQChannel = IOE_IT_EXTI_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); }
/** * @brief Initializes the GPIO pins used by the IO expander. * @param None * @retval None */ static void IOE_GPIO_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; /* Enable IOE_I2C and IOE_I2C_PORT & Alternate Function clocks */ RCC_APB1PeriphClockCmd(IOE_I2C_CLK, ENABLE); RCC_APB2PeriphClockCmd(IOE_I2C_SCL_GPIO_CLK | IOE_I2C_SDA_GPIO_CLK | IOE_IT_GPIO_CLK | RCC_APB2Periph_AFIO, ENABLE); /* Reset IOE_I2C IP */ RCC_APB1PeriphResetCmd(IOE_I2C_CLK, ENABLE); /* Release reset signal of IOE_I2C IP */ RCC_APB1PeriphResetCmd(IOE_I2C_CLK, DISABLE); /* IOE_I2C SCL and SDA pins configuration */ GPIO_InitStructure.GPIO_Pin = IOE_I2C_SCL_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_Init(IOE_I2C_SCL_GPIO_PORT, &GPIO_InitStructure); /* IOE_I2C SCL and SDA pins configuration */ GPIO_InitStructure.GPIO_Pin = IOE_I2C_SDA_PIN; GPIO_Init(IOE_I2C_SDA_GPIO_PORT, &GPIO_InitStructure); /* Set EXTI pin as Input PullUp - IO_Expander_INT */ GPIO_InitStructure.GPIO_Pin = IOE_IT_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(IOE_IT_GPIO_PORT, &GPIO_InitStructure); /* Connect IO Expander IT line to EXTI line */ GPIO_EXTILineConfig(IOE_IT_EXTI_PORT_SOURCE, IOE_IT_EXTI_PIN_SOURCE); }