外部中断初始化和中断如下,遇到的问题:
1、触发单个PB3或者PB4时,EXTI->PR有时显示外部中断3,4都发生,也的确进入外部中断3,4的子程序。由于优先级的关系,先进4,而我有清除EXTI->PR,所以进3后没执行if后的语句直接跳出来了。
2、我注释掉外部中断3或4的使能位,有时还会进入被注释掉的那个中断程序里
3、我注释掉外部中断线3或是4的屏蔽位,中断正常工作
求高手指点个方向,谢谢!
void EXTI_Init(void)
{
SCB->AIRCR = 0x05AF0000 | 0x400;
/*****************PB ********************/
RCC->AHB1ENR |= (1<<1);
RCC->APB2ENR |= (1<<14);
GPIOB->MODER &= ~(3<<8);
GPIOB->MODER &= ~(3<<6);
GPIOB->OTYPER &= 0xFFFFFFFF;
GPIOB->OSPEEDR |= (3<<8);
GPIOB->OSPEEDR |= (3<<6);
SYSCFG->CMPCR |= (1<<0);
GPIOB->PUPDR |= 0x5<<6;
GPIOB->BSRRH = 0xffff;
/***********************************************/
EXTI->IMR=0;
EXTI->IMR |= ( 1 << 4 );
EXTI->FTSR |= ( 1 << 4 );
SYSCFG->EXTICR[1] = 0x0000fff1;
NVIC->IP[EXTI4_IRQn] = 0xc0;
NVIC->ISER[0] |= (1<<10);
EXTI->IMR |= ( 1 << 3 );
EXTI->FTSR |= ( 1 << 3 );
SYSCFG->EXTICR[0] = 0x00001fff;
NVIC->IP[EXTI3_IRQn] = 0xe0;
NVIC->ISER[0] |= (1<<9);
}
u32 pr;
void EXTI3_IRQHandler(void)
{
pr=EXTI->PR;
if ((EXTI->PR & 0x00008) != 0)
{
EXTI->PR|=0x00008;
pr=EXTI->PR;
}
}
void EXTI4_IRQHandler(void)
{
pr=EXTI->PR;
if ((EXTI->PR & 0x00010) != 0)
{
EXTI->PR|=0x00010;
pr=EXTI->PR;
}
} |