STM32 外部中断配置 2009-07-22 14:16 1 配置中断 1、 分配中断向量表: /* Set the Vector Table base location at 0x20000000 */ NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); 2、 设置中断优先级: NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); //设置中断优先级 3、 初始化外部中断: /*允许 EXTI4 中断 */ NVIC_InitStructure
NVIC_IRQChannel = EXTI4_IRQChannel; //中断通道 NVIC_InitStructure
NVIC_IRQChannelPreemptionPriority = PreemptionPriorityValue;//强占优先级 NVIC_InitStructure
NVIC_IRQChannelSubPriority = 0; //次优先级 NVIC_InitStructure
NVIC_IRQChannelCmd = ENABLE; //通道中断使能 NVIC_Init(&NVIC_InitStructure); //初始化中断 注意:如果我们配置的外部针脚为 PA4,或 PB4,或 PC4,PD4 等,那么采用的外部中断也必须是EXTI4,同样,如果外部中断针脚是 PA1,PB1,PC1,PD1 那么中断就要用 EXTI1,其他类推
2 配置GPIO 针脚作为外部中断的触发事件 1、 选择 IO 针脚 GPIO_InitStructure
GPIO_Pin = GPIO_Pin_4; 注意,如果的针脚是端口的 4 号针脚,配置的中断一定是 EXTI4 2、 配置针脚为输入 GPIO_InitStructure