|
下面代码实现的是,用PB0捕获下降沿中断,然后在中断程序中计数Pulse_N。但是,我调试发现一只不能进入中断函数void EXTI0_IRQHandler(void) 里,请问为什么,哪里写的不对吗?
.... ....
RCC_Config();
GPIOConfig();
NVICConfig();
EXTIConfig();
.... ....
/***********************************/
void RCC_Config(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
}void GPIOConfig(void) /* 脉冲引脚配置 PB0 */
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; /* 上拉输入 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; /* 脉冲引脚--PB0 */
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
void NVICConfig(void)/* 嵌套中断配置 */
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; /* 设置外部中断,此处使能外部中断0 */
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void EXTIConfig(void)/* 外部中断配置 */
{
EXTI_InitTypeDef EXTI_InitStructure;
/* EXTI line(PB0) mode config */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource0);
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);
}
void EXTI0_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line0) != RESET) //确保是否产生了EXTI Line中断
{
if(0 == GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_0))
{
Pulse_N++;
}
EXTI_ClearITPendingBit(EXTI_Line0); //清除中断标志位
}
}
/****************************/
|
|