多外部中断的优先级配置

STM32固件库使用手册(中文版)P167
一, 抢占优先级的优先级别大于从优先级(响应优先级),而在抢占优先级内部,配置所给的抢占优先级(NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;)数字越小,代表的优先级别越高,从优先级同理;优先级大小:抢占优先级0>抢占优先级1>抢占优先级2>抢占优先级3>从优先级0>从优先级1>从优先级2>从优先级3

二,配置表格分组
多外部中断的优先级配置_第1张图片
1. 选中 NVIC_PriorityGroup_0,则参数 NVIC_IRQChannelPreemptionPriority 对中断通道的设置不产生影响。
2. 选中 NVIC_PriorityGroup_4,则参数 NVIC_IRQChannelSubPriority 对中断通道的设置不产生影响。
NVIC_IRQChannelCmd
该参数指定了在成员 NVIC_IRQChannel 中定义的 IRQ 通道被使能还是失能。这个参数取值为 ENABLE 或
者 DISABLE。

例:`
NVIC_InitTypeDef NVIC_InitStructure;

/* Configure the Priority Grouping with 1 bit */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

/* Enable TIM3 global interrupt with Preemption Priority 0 and Sub
Priority as 2 */
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStructure(&NVIC_InitStructure);

/* Enable USART1 global interrupt with Preemption Priority 1 and Sub
Priority as 5 */
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 5;
NVIC_InitStructure(&NVIC_InitStructure);

/* Enable RTC global interrupt with Preemption Priority 1 and Sub
Priority as 7 */
NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 7;
NVIC_InitStructure(&NVIC_InitStructure);

/* Enable EXTI4 interrupt with Preemption Priority 1 and Sub
Priority as 7 */
NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 7;
NVIC_InitStructure(&NVIC_InitStructure);

/* TIM3 interrupt priority is higher than USART1, RTC and EXTI4
interrupts priorities. USART1 interrupt priority is higher than RTC
and EXTI4 interrupts priorities. RTC interrupt priority is higher
than EXTI4 interrupt prioriy. */
`

你可能感兴趣的:(#,stm32)