配置中断优先级分组
优先级分组定义了抢占优先级和子优先级的划分比例。以下是配置优先级分组的示例:
c
#include "stm32f4xx.h" // 根据使用的具体型号包含相应的头文件
void NVIC_Configuration(void)
{
// 配置优先级分组,设为 Group 3(4 bits for pre-emption priority, 0 bits for subpriority)
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3);
// 配置具体中断通道的优先级
NVIC_InitTypeDef NVIC_InitStructure;
// 配置 USART1 中断
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
// 配置 EXTI Line0 中断
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
|