[stm32]中断优先级设置
- 设置优先级组
NVIC_PriorityGroupConfig
- 设置中断源的抢占优先级(pre-emption priority)和响应优先级(sub-priority),然后使能
- 初始化
NVIC_Init(&NVIC_InitStructure)
void NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the NVIC Preemption Priority Bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
/* Enable the USARTy Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
NOTE
-
NVIC_PriorityGroupConfig
可设置多次,但以最后一次为准 -
设定的中断源优先级不能超过优先级组设置的范围,否则结果不可知
-
抢占式优先级别相同的中断源之间没有嵌套关系
-
当两个中断源的抢占式优先级相同时,这两个中断将没有嵌套关系
-
抢占式优先级或响应优先级相同时,根据他们在中断表中的排位顺序决定先处理哪一个
Good Good Study! Day Day Up!