[stm32]中断优先级设置

pic

  1. 设置优先级组NVIC_PriorityGroupConfig
  2. 设置中断源的抢占优先级(pre-emption priority)响应优先级(sub-priority),然后使能
  3. 初始化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

  1. NVIC_PriorityGroupConfig可设置多次,但以最后一次为准

  2. 设定的中断源优先级不能超过优先级组设置的范围,否则结果不可知

  3. 抢占式优先级别相同的中断源之间没有嵌套关系

  4. 当两个中断源的抢占式优先级相同时,这两个中断将没有嵌套关系

  5. 抢占式优先级或响应优先级相同时,根据他们在中断表中的排位顺序决定先处理哪一个

posted on 2014-12-26 11:18  kdurant  阅读(1990)  评论(0编辑  收藏  举报

导航