F407外部中断优先级设置问题——求解答

2019-07-20 15:40发布

在实验中发现一个奇怪的情况,将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内么??还是我理解错了??

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
5条回答
Fabby
2019-07-20 21:45
zmingwang 发表于 2017-4-1 00:35
首先要知道,STM32只用了4位优先级,占优先级分组的高4位,可全部划为抢占优先级或子优先级,共16个优先级 ...

  assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority));  //在NVIC_Init()函数中
这句的有效性判断为#define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY)  ((PRIORITY) < 0x10),为何当我NVIC_IRQChannelPreemptionPriority = 0x10;时不报错,既然都不满足有效性判断,按理说不能正常运行呀

一周热门 更多>