我试图通过切换 PC14 来切换 PC13 上的 LED,问题是在不切换 PC14 的情况下一直调用中断处理程序,并且未使用 EXTI->PR 寄存器清除挂起的中断,也没有使用调试器手动清除。我也尝试在 NVIC->ICPR 中清除它,我不确定为什么有两个寄存器用于清除相同的中断。
这是我的代码,您可以在https://github.com/AymenSekhri/tinyHAL-STM32f103/tree/master/STM32F103-HAL/tinyHAL
中找到标题
/*
* Description:
* Toggle LED at C13 whenever C14 goes from HIGH to LOW.
*
*/
#include "tinyHAL/stm32f103_hal.h"
int main(){
//Enable AFIO clock from RCC
enablePeripheralClock(Peripheral_AFIO);
//Enable and configure C13 & C14
enablePeripheralClock(Peripheral_GPIOC);
configureGPIO(Peripheral_GPIOC, 13, GPIO_MODE_OUT_50MHZ, GPIO_CONF_OUT_PUSHPULL);
configureGPIO(Peripheral_GPIOC, 14, GPIO_MODE_IN, GPIO_CONF_IN_PUSHUP_PULLDOWN);
//Link EXTI14 to C14
AFIO->EXTICR[3] = (AFIO->EXTICR[3] & ~(0xF<<8)) | 2;
//Configure inturrput at EXTI14 falling edge
EXTI->FTSR |= 1<<14;
//Unmask interrupt 40 (EXTI10-15)
EXTI->IMR |= 1<<14;
//Set Priority to interrupt 40 (EXTI10-15)
NVIC->IP[40] |= 0x10;
//Enable interrupt 40 (EXTI10-15)
NVIC->ISER[40>>5] |= (1 << (40&0x1F));
while(1);
}
void EXTI15_10_IRQHandler(void){
toggleGPIOBit(Peripheral_GPIOC, 13);
if (EXTI->PR & (1 << 14)){
EXTI->PR |= (1 << 14);
}
//NVIC->ICPR[40>>5] |= (1 << (40&0x1F));
__COMPILER_BARRIER();
}