stm32f10x NVIC_Init()函数

本文详细介绍了STM32外部中断初始化与NVIC配置的过程,包括使用EXTI_InitTypeDef与NVIC_InitTypeDef结构体进行配置,以及正确设置中断优先级的方法。通过实例展示了如何使能外部中断并正确响应中断请求。

                                                                                    函数 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;

 

#include "stm32f10x.h" void GPIO_Configuration(void); void NVIC_Configuration(void); void EXTI_Configuration(void); void EXTI9_5_IRQHandler(void); int main(void) { GPIO_Configuration(); NVIC_Configuration(); EX以上是单击独立按键SW3 ,此时LED3 实现亮灭翻转的代码,运行后报错*** Using Compiler 'V5.06 update 5 (build 528)', folder: 'D:\danpianji\keil5\ARM\ARMCC\Bin' Build target 'Target 1' compiling stm32f10x_bkp.c... compiling core_cm3.c... compiling misc.c... compiling stm32f10x_crc.c... compiling stm32f10x_dac.c... compiling stm32f10x_adc.c... compiling stm32f10x_can.c... compiling stm32f10x_dbgmcu.c... compiling stm32f10x_dma.c... compiling stm32f10x_cec.c... compiling stm32f10x_exti.c... compiling stm32f10x_gpio.c... compiling stm32f10x_fsmc.c... compiling stm32f10x_flash.c... compiling stm32f10x_i2c.c... compiling stm32f10x_iwdg.c... compiling stm32f10x_rtc.c... compiling stm32f10x_pwr.c... compiling stm32f10x_sdio.c... compiling stm32f10x_rcc.c... compiling stm32f10x_spi.c... assembling startup_stm32f10x_hd.s... compiling stm32f10x_usart.c... compiling stm32f10x_wwdg.c... compiling stm32f10x_it.c... compiling stm32f10x_tim.c... linking... .\Objects\1021.axf: Error: L6200E: Symbol NVIC_Init multiply defined (by misc_1.o and misc.o). .\Objects\1021.axf: Error: L6200E: Symbol NVIC_PriorityGroupConfig multiply defined (by misc_1.o and misc.o). .\Objects\1021.axf: Error: L6200E: Symbol NVIC_SetVectorTable multiply defined (by misc_1.o and misc.o). .\Objects\1021.axf: Error: L6200E: Symbol NVIC_SystemLPConfig multiply defined (by misc_1.o and misc.o). .\Objects\1021.axf: Error: L6200E: Symbol SysTick_CLKSourceConfig multiply defined (by misc_1.o and misc.o). .\Objects\1021.axf: Error: L6200E: Symbol EXTI_ClearFlag multiply defined (by stm32f10x_exti_1.o and stm32f10x_exti.o). .\Objects\1021.axf: Error: L6200E: Symbol EXTI_ClearITPendingBit multiply defined (by stm32f10x_exti_1.o and stm32f10x_exti.o). .\Objects\1021.axf: Error: L6200E: Symbol EXTI_DeInit multiply defined (by stm32f10x_exti_1.o and stm32f10x_exti.o). .\Objects\1021.axf: Error: L6200E: Symbol EXTI_GenerateSWInterrupt multiply defined (by stm32f10x_exti_1.o and stm32f10x_exti.o). .\Objects\1021.axf: Error: L6200E: Symbol EXTI_GetFlagStatus multiply defined (by stm32f10x_exti_1.o and stm32f10x_exti.o). .\Objects\1021.axf: Error: L6200E: Symbol EXTI_GetITStatus multiply defined (by stm32f10x_exti_1.o and stm32f10x_exti.o). .\Objects\1021.axf: Error: L6200E: Symbol EXTI_Init multiply defined (by stm32f10x_exti_1.o and stm32f10x_exti.o). .\Objects\1021.axf: Error: L6200E: Symbol EXTI_StructInit multiply defined (by stm32f10x_exti_1.o and stm32f10x_exti.o). Not enough information to list image symbols. Not enough information to list load addresses in the image map. Finished: 2 information, 0 warning and 13 error messages. ".\Objects\1021.axf" - 13 Error(s), 0 Warning(s). Target not created. Build Time Elapsed: 00:00:04
最新发布
11-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值