使用STM32F103,用它的GPIOE2、3、4、5、6五个口作为键盘输入,初始化这的程序为:
/* Configure EXTI line */
EXTI->EMR = 0x7C; //line 2,3,4,5,6 的中断MASK位
EXTI->IMR = 0x7C; // 事件MASK
EXTI->RTSR = 0x7C; // 上升沿触发
EXTI->FTSR = 0x7C; // 下降沿触发
EXTI->PR = 0xFFFFF; /// ------- 此句是后来加的。
/* Connect EXTI2,3,4,5,6 Line to PE.2,3,4,5,6 pin */
AFIO->EXTICR[0] = 0x4400; // 使用PE2、PE3
AFIO->EXTICR[1] = 0x0444; // 使用PE4、PE5、PE6
其NVIC设置:
NVIC_InitStructure.NVIC_IRQChannel = EXTI2_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 = EXTI4_IRQn;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
NVIC_Init(&NVIC_InitStructure);
-------------------------------------------------------------------------------
调试时,当设置完寄存器后,发现PR寄存器的位2(即对应PE2)有中断产生,但进入中断并清除标志后,不再产生中断。
而PR寄存器的位5、进入中断后也清除了,但还是产生中断!
我想问,开始就产生中断(象PE2)的原因是什么?
PE2~6与TRACE共用引脚,它们会影响吗?
此帖出自
小平头技术问答
我把
EXTI->PR = 6; // clear pending
改为:
EXTI->PR = 0x60; // clear pending
即正常
一周热门 更多>