NVIC中断使能

一直担心范例的中断的初始化或相互冲突,例如初始化一个外部中断

范例中的函数是

DWORD EINTInit( void )
{
 NVIC_InitTypeDef NVIC_InitStructure;
 
 PINSEL4 = 0x00100000; /* 设置set P2.10为EINT0以及设置P2.2~5为输出GPIO */
 
 IO2IntEnF = 0x200;  /* Port2.10为下降沿触发 */
 EXTMODE = EINT0_EDGE; /* INT0 edge trigger */
 EXTPOLAR = 0;   /* INT0 is falling edge by default */
 
 NVIC_InitStructure.NVIC_IRQChannel = EINT0_IRQChannel;
 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
 NVIC_Init(&NVIC_InitStructure);
 
 return( TRUE );
}

 

void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
{

  ...

 if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
  {

     ...

     /* Enable the Selected IRQ Channels --------------------------------------*/
     if (NVIC_InitStruct->NVIC_IRQChannel >> 0x05)
      {
        NVIC_ENABLE1 = 0x01 << (NVIC_InitStruct->NVIC_IRQChannel & 0x1F);
      }
     else
      {
        NVIC_ENABLE0 = 0x01 << (NVIC_InitStruct->NVIC_IRQChannel & 0x1F);
      }

    ...

  }

 咋一看,假如调用两个中断的话,给NVIC_ENABLE赋值,前者就会覆盖后者,在CortexM3 TRM第148页看到“Clearing an Interrupt Set-Enable Register bit does not affect currently active interrupts. It only prevents new activations.”

NVIC使能寄存器写零是无效的,如果要非使能,需要写1到NVIC非使能寄存器。 

你可能感兴趣的:(NVIC中断使能)