STM32外部触发中断
时间:10-02
整理:3721RD
点击:
使用GPIOD的11管脚和12管脚用外部中断方式检查有无信号,下拉输入,上升沿触发,为什么给11管脚一个脉冲,两个中断都触发了呢,求高人帮忙 急!
void Exti_Init(void)
{ GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO, ENABLE); //使能PD端口时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //下拉输入
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //下拉输入
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
EXTI_InitStructure.EXTI_Line = EXTI_Line11|EXTI_Line12|EXTI_Line15|EXTI_Line6;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/***指定中断源*****/
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource11);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource12);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource15);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource6);
NVIC_InitStructure.NVIC_IRQChannel=EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;//抢占优先级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //子优先级1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
NVIC_InitStructure.NVIC_IRQChannel=EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;//抢占优先级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //子优先级1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
EXTI_ClearITPendingBit(EXTI_Line11);
EXTI_ClearITPendingBit(EXTI_Line15);
EXTI_ClearITPendingBit(EXTI_Line12);
EXTI_ClearITPendingBit(EXTI_Line6);
}
void EXTI15_10_IRQHandler(void)
{//delay_ms(10);
if(EXTI_GetITStatus(EXTI_Line11)!=RESET)
{ TZHFLAG1=1;
EXTI_ClearFlag(EXTI_Line11);
EXTI_ClearITPendingBit(EXTI_Line11);
}
if(EXTI_GetITStatus(EXTI_Line15)!=RESET)
{ TZHFLAG2=1;
EXTI_ClearFlag(EXTI_Line15);
EXTI_ClearITPendingBit(EXTI_Line15);
}
if(EXTI_GetITStatus(EXTI_Line12)!=RESET)
{ HZHFLAG1=1;
EXTI_ClearFlag(EXTI_Line12);
EXTI_ClearITPendingBit(EXTI_Line12);
}
}
这是部分程序
void Exti_Init(void)
{ GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO, ENABLE); //使能PD端口时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //下拉输入
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //下拉输入
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
EXTI_InitStructure.EXTI_Line = EXTI_Line11|EXTI_Line12|EXTI_Line15|EXTI_Line6;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/***指定中断源*****/
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource11);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource12);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource15);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource6);
NVIC_InitStructure.NVIC_IRQChannel=EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;//抢占优先级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //子优先级1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
NVIC_InitStructure.NVIC_IRQChannel=EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;//抢占优先级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //子优先级1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
EXTI_ClearITPendingBit(EXTI_Line11);
EXTI_ClearITPendingBit(EXTI_Line15);
EXTI_ClearITPendingBit(EXTI_Line12);
EXTI_ClearITPendingBit(EXTI_Line6);
}
void EXTI15_10_IRQHandler(void)
{//delay_ms(10);
if(EXTI_GetITStatus(EXTI_Line11)!=RESET)
{ TZHFLAG1=1;
EXTI_ClearFlag(EXTI_Line11);
EXTI_ClearITPendingBit(EXTI_Line11);
}
if(EXTI_GetITStatus(EXTI_Line15)!=RESET)
{ TZHFLAG2=1;
EXTI_ClearFlag(EXTI_Line15);
EXTI_ClearITPendingBit(EXTI_Line15);
}
if(EXTI_GetITStatus(EXTI_Line12)!=RESET)
{ HZHFLAG1=1;
EXTI_ClearFlag(EXTI_Line12);
EXTI_ClearITPendingBit(EXTI_Line12);
}
}
这是部分程序
大侠们帮帮忙吧
得镨科技(上海)有限公司专注于烧录器研发,Dediprog 品牌,从手动到自动,从专用到通用,从工程到量产全系列产品,均自主研发,市场需求多。欢迎询问。