今天才发现stm32的外部中断,每条中断线只能有一个中断源啊!!! 我的PA4,PA5,PA6,PA7,PC4,PC5,PB0,PB1,PE7这几个引脚只能PA4,PA5,PA6,PA7,PB0,PB1用外部中断了, 大家有什么好的办法,能让其他的几个引脚也用上外部中断吗? 分时开启的办法就算了,不实用。 #ifndef _COUNTER_H_ #define _COUNTER_H_ #include"driver_about.h" #define COUNTER1_PORT GPIOE #define COUNTER1_PIN GPIO_Pin_7 #define COUNTER2_PORT GPIOB #define COUNTER2_PIN GPIO_Pin_1 #define COUNTERCTRL_PORT GPIOE #define COUNTERCTRL_PIN GPIO_Pin_8 #define COUNTER1_GPIO_PortSource GPIO_PortSourceGPIOE #define COUNTER1_GPIO_PinSource GPIO_PinSource7 #define COUNTER2_GPIO_PortSource GPIO_PortSourceGPIOB #define COUNTER2_GPIO_PinSource GPIO_PinSource1 #define COUNTER1_EXTI_Line EXTI_Line7 #define COUNTER2_EXTI_Line EXTI_Line1 #define Counter1_IRQn EXTI9_5_IRQn #define Counter1_IRQHandler EXTI9_5_IRQHandler #define Counter2_IRQn EXTI1_IRQn #define Counter2_IRQHandler EXTI1_IRQHandler #define COUNTERCTRL_Open() GPIO_ResetBits(COUNTERCTRL_PORT,COUNTERCTRL_PIN) #define COUNTERCTRL_Close() GPIO_SetBits(COUNTERCTRL_PORT,COUNTERCTRL_PIN) void Counter_Init(void); void Set_Coin1(u8 coin); void Set_Coin2(u8 coin); u8 Get_Coin1(void); u8 Get_Coin2(void); u8 Add_Coin1(u8 value); u8 Add_Coin2(u8 value); #endif //////////////////////////////////////////////////////// #include"counter.h" static u8 Coin1=0; static u8 Coin2=0; void Counter_GPIO(void) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = COUNTER1_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(COUNTER1_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = COUNTER2_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(COUNTER2_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = COUNTERCTRL_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(COUNTERCTRL_PORT, &GPIO_InitStructure); COUNTERCTRL_Open(); } void Counter1_EXIT_Init(void) { EXTI_InitTypeDef EXTI_InitStructure;//定义外部中断初始化参数的结构体 GPIO_EXTILineConfig(COUNTER1_GPIO_PortSource,COUNTER1_GPIO_PinSource);//选择中断管脚 EXTI_ClearITPendingBit(COUNTER1_EXTI_Line);//清除外部中断挂起标志 EXTI_InitStructure.EXTI_Line = COUNTER1_EXTI_Line; //选择中断线路 EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;//设置为中断请求,非事件请求 EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;//设置中断触发方式为下降沿触发 EXTI_InitStructure.EXTI_LineCmd = ENABLE; //外部中断使能 EXTI_Init(&EXTI_InitStructure);//初始化外部中断 } void Counter1_NVIC_EXIT_Init(void) { NVIC_InitTypeDef NVIC_InitStructure;//定义NVIC的结构体变量 NVIC_InitStructure.NVIC_IRQChannel = Counter1_IRQn;//选择中断通道 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0;//抢占式中断优先级设置 NVIC_InitStructure.NVIC_IRQChannelSubPriority =5;//响应式中断优先级设置 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//使能中断 NVIC_Init(&NVIC_InitStructure); } void Counter2_EXIT_Init(void) { EXTI_InitTypeDef EXTI_InitStructure;//定义外部中断初始化参数的结构体 GPIO_EXTILineConfig(COUNTER2_GPIO_PortSource,COUNTER2_GPIO_PinSource);//选择中断管脚 EXTI_ClearITPendingBit(COUNTER2_EXTI_Line);//清除外部中断挂起标志 EXTI_InitStructure.EXTI_Line = COUNTER2_EXTI_Line; //选择中断线路 EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;//设置为中断请求,非事件请求 EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;//设置中断触发方式为下降沿触发 EXTI_InitStructure.EXTI_LineCmd = ENABLE; //外部中断使能 EXTI_Init(&EXTI_InitStructure);//初始化外部中断 } void Counter2_NVIC_EXIT_Init(void) { NVIC_InitTypeDef NVIC_InitStructure;//定义NVIC的结构体变量 NVIC_InitStructure.NVIC_IRQChannel = Counter2_IRQn;//选择中断通道 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0;//抢占式中断优先级设置 NVIC_InitStructure.NVIC_IRQChannelSubPriority =4;//响应式中断优先级设置 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//使能中断 NVIC_Init(&NVIC_InitStructure); } void Counter_Init(void) { Counter_GPIO(); Counter1_EXIT_Init(); Counter1_NVIC_EXIT_Init(); Counter2_EXIT_Init(); Counter2_NVIC_EXIT_Init(); } void Set_Coin1(u8 coin) { Coin1=coin; } u8 Get_Coin1(void) { return Coin1; } u8 Add_Coin1(u8 value) { Coin1+=value; return Coin1; } void Set_Coin2(u8 coin) { Coin2=coin; } u8 Get_Coin2(void) { return Coin2; } u8 Add_Coin2(u8 value) { Coin2+=value; return Coin2; } void Counter1_IRQHandler(void) { OS_ERR err; OSIntEnter(); if(EXTI_GetITStatus(COUNTER1_EXTI_Line)!= RESET) { OSTaskQPost (&CounterStkTCB,&Coin1,1,OS_OPT_POST_FIFO,&err); EXTI_ClearITPendingBit(COUNTER1_EXTI_Line); } else { EXTI9_5_IRQHandler_Input();//输入产生的中断 } //EXTI_ClearITPendingBit(COUNTER1_EXTI_Line); OSIntExit(); } void Counter2_IRQHandler(void) { OS_ERR err; OSIntEnter(); if(EXTI_GetITStatus(COUNTER2_EXTI_Line)!= RESET)//后半部分判断中断来源 { OSTaskQPost (&CounterStkTCB,&Coin2,2,OS_OPT_POST_FIFO,&err); EXTI_ClearITPendingBit(COUNTER2_EXTI_Line); } //EXTI_ClearITPendingBit(COUNTER2_EXTI_Line); OSIntExit(); } |