新手:EXTI9_5_IRQChannel undefined http://bbs.elecfans.com/jishu_560431_1_1.html (出处: 中国电子技术论坛) 如题:想做成按K1键灯亮 K1 = USERBUTTON = PA.8 灯 = PF.8 问题是: 配置NVIC,EXTI9_5_IRQChannel 一直undefined。。注释掉就没问题了 报错内容如下: ..\..\..\stm32library\STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Template\main.c(16): error: #20: identifier "EXTI9_5_IRQChannel" is undefined ..\..\..\stm32library\STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Template\main.c: NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQChannel; //选择中断通道5 ..\..\..\stm32library\STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Template\main.c: ^ ..\..\..\stm32library\STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Template\main.c: ..\..\..\stm32library\STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Template\main.c: 0 warnings, 1 error ..\..\..\stm32library\STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Template\main.c - 1 Error(s), 0 Warning(s). 程序如下 割线-------------------------------------------------------- 程序如下 #include "stm32f10x.h" //配置RCC void rcc_cfg() { RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOF,ENABLE); } //配置NVIC void nvic_cfg() { NVIC_InitTypeDef NVIC_InitStructure; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQChannel; //选择中断通道8 //注释掉上面这句就没问题 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //抢占式中断优先级设置为2 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //响应式中断优先级设置为2 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能中断 NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化nVIC寄存器 } //这里一直报错 //配置GPIO void io_cfg() { GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA,&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOF,&GPIO_InitStructure); } //配置EXTI void exti_cfg() { EXTI_InitTypeDef EXTI_InitStructure; EXTI_ClearITPendingBit(EXTI_Line8); //清楚中断标志位 GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource8); //选择中断管脚PA.8 EXTI_InitStructure.EXTI_Line = EXTI_Line8 ; //选择中断线8 EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //设置为中断请求,非事件请求 EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; //设置中断触发方式为上下降沿触发 EXTI_InitStructure.EXTI_LineCmd = ENABLE; //外部中断使能 EXTI_Init(&EXTI_InitStructure); } void EXTI9_5_IRQHandler(void) { //点亮LED灯 GPIO_ResetBits(GPIOF,GPIO_Pin_8); //清空中断标志位,防止持续进入中断 EXTI_ClearITPendingBit(EXTI_Line8); } int main() { rcc_cfg(); io_cfg(); nvic_cfg(); exti_cfg(); GPIO_SetBits(GPIOF,GPIO_Pin_8); while(1); } |
如果MDK环境的话,
option for target\c/c++\define:\USE_STDPERIPH_DRIVER, STM32F10X_???, 你这里有配置吗?
新手的话,可以先从一个现存的工程开始。了解下基本的框架。