stm32f10x NVIC_Init()函数

                                                                                    函数 NVIC_Init()

函数名

NVIC_Init

函数原型 void NVIC_Init(NVIC_InitTypeDdf *  NVIC_InitStruct)
功能描述 根据 NVIC_InitStruct 中指定的参数初始化外设NVIC寄存器
输入参数 NVIC_InitStruct:指向结构体 NVIC_InitTypeDdf 的指针
输出参数
返回值
先决条件
被调用函数

NVIC_InitTypeDdf 定义于文件“stm32f10x_nvic.h":

typedef struct
{
  uint8_t NVIC_IRQChannel;                    /*!< Specifies the IRQ channel to be enabled or disabled.
                                                   This parameter can be a value of @ref IRQn_Type 
                                                   (For the complete STM32 Devices IRQ Channels list, please
                                                    refer to stm32f10x.h file) */

  uint8_t NVIC_IRQChannelPreemptionPriority;  /*!< Specifies the pre-emption priority for the IRQ channel
                                                   specified in NVIC_IRQChannel. This parameter can be a value
                                                   between 0 and 15 as described in the table @ref NVIC_Priority_Table */

  uint8_t NVIC_IRQChannelSubPriority;         /*!< Specifies the subpriority level for the IRQ channel specified
                                                    in NVIC_IRQChannel. This parameter can be a value
                                                    between 0 and 15 as described in the table @ref NVIC_Priority_Table */

  FunctionalState NVIC_IRQChannelCmd;         /*!< Specifies whether the IRQ channel defined in NVIC_IRQChannel
                                                    will be enabled or disabled. 
                                                    This parameter can be set either to ENABLE or DISABLE */   
} NVIC_InitTypeDef;

 

例:

void Extix_Init(void)//外部中断初始化
{
	EXTI_InitTypeDef Exti_initStructure;
	NVIC_InitTypeDef Nvic_initStructure;
	
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//外部中断,需使能AFIO时钟
	key_Init();//按键初始化 PC1、PC13  

    //PC.1 PC.13 中断线以及中断初始化配置                                   
	GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource1);
        GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource13);
	
	Exti_initStructure.EXTI_Line = EXTI_Line1 | EXTI_Line13;
	Exti_initStructure.EXTI_Mode = EXTI_Mode_Interrupt;
	Exti_initStructure.EXTI_Trigger = EXTI_Trigger_Falling;
	Exti_initStructure.EXTI_LineCmd = ENABLE;
	EXTI_Init(&Exti_initStructure);
	
    //NVIC 配置	
	Nvic_initStructure.NVIC_IRQChannel = EXTI1_IRQn ;
	Nvic_initStructure.NVIC_IRQChannelPreemptionPriority = 2;
	Nvic_initStructure.NVIC_IRQChannelSubPriority = 1;
	Nvic_initStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&Nvic_initStructure);
	
	Nvic_initStructure.NVIC_IRQChannel =  EXTI15_10_IRQn;
	Nvic_initStructure.NVIC_IRQChannelPreemptionPriority = 2;
	Nvic_initStructure.NVIC_IRQChannelSubPriority = 1;
	Nvic_initStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&Nvic_initStructure);
}

 

一开始这样写,结果两个中断都没响应

Nvic_initStructure.NVIC_IRQChannel = EXTI1_IRQn | EXTI15_10_IRQn;

 

你可能感兴趣的:(stm32)