在实验中发现一个奇怪的情况,将NVIC的抢占优先级设置为0X10,为何中断也能正常工作?程序如下:
/*设置NVIC中断优先级*/
NVIC_InitStruct.NVIC_IRQChannel=EXTI0_IRQn;//外部中断0
NVIC_InitStruct.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority=0x00;
NVIC_InitStruct.NVIC_IRQChannelSubPriority= 0x10;
NVIC_Init(&NVIC_InitStruct);
NVIC_InitStruct.NVIC_IRQChannel=EXTI2_IRQn;//外部中断2
NVIC_InitStruct.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority=0x01;//抢占优先级为1
NVIC_InitStruct.NVIC_IRQChannelSubPriority= 0x10;
NVIC_Init(&NVIC_InitStruct);
NVIC_InitStruct.NVIC_IRQChannel=EXTI3_IRQn;//外部中断3
NVIC_InitStruct.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority=0x10;
NVIC_InitStruct.NVIC_IRQChannelSubPriority= 0x10;
NVIC_Init(&NVIC_InitStruct);
主函数设置为:NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置系统中断优先级分组为2,即2为抢占优先级和2位响应优先级
为何将抢占优先级和响应优先级设置为0x10,中断也能正常工作???响应优先级和抢占优先级不应该都在0~3内么??还是我理解错了??
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority)); //在NVIC_Init()函数中
这句的有效性判断为#define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY) ((PRIORITY) < 0x10),为何当我NVIC_IRQChannelPreemptionPriority = 0x10;时不报错,既然都不满足有效性判断,按理说不能正常运行呀
一周热门 更多>