1.1.1 NVIC分组设置 void NVIC_SetPriorityGrouping(uint32_tPriorityGroup) 位置:misc.c的106行 作用:设置优先级分组 参数:PriorityGroup优先级分组组号,这里对内核的分组做了简化,即从NVIC_PriorityGroup_0到NVIC_PriorityGroup_4代表抢占优先级位数从0bit到4bit,响应优先级位数从4bit到0bit 举例:优先级分组设置为组2,则对应的代码为:NVIC_SetPriorityGrouping(NVIC_PriorityGroup_2); 1.1.2 NVIC初始化配置voidNVIC_Init(NVIC_InitType* NVIC_InitStruct) 位置:misc.c的121行 作用:NVIC初始化配置 参数:NVIC_InitStruct初始化结构体,其中关于中断优先级的成员为NVIC_InitStruct.NVIC_IRQChannelSubPriority和NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority,分别为抢占优先级和响应优先级,受限于优先级分组的简化,这里的优先级取值范围为0-15 举例:设置串口1全局中断抢占优先级为2,响应优先级为2,则对应的代码如下: 1. NVIC_InitType NVIC_InitStructure; 2. NVIC_SetPriorityGrouping(NVIC_PriorityGroup_2); 3. NVIC_InitStructure.NVIC_IRQChannel =USART1_IRQn; 4. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; 5. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; 6. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 7. NVIC_Init(&NVIC_InitStructure);
|