目的: PB0作为外部中断IO口,当低电平时进入中断通过串口发送字符串
配置如下 :IO配置如下 #define Shi_0 GPIO_Pin_0
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB);
//ÅäÖÃADS_DR pb0
GPIO_InitStructure.GPIO_Pin =Shi_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//¸′
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//
GPIO_Init(GPIOB, &GPIO_InitStructure);//
void EXTIX_Init(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_Init();//初始化IO
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);//ê1ÄüSYSCFGê±Öó
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource0);//Pb0 ᬽóμ½ÖD¶ÏÏß0
//
/* ÅäÖÃEXTI_Line0 */
EXTI_InitStructure.EXTI_Line = EXTI_Line0;//LINE0
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;//ÖD¶Ïê¼t
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //ϽμÑØ′¥·¢
EXTI_InitStructure.EXTI_LineCmd = ENABLE;//ê1ÄüLINE0
EXTI_Init(&EXTI_InitStructure);//ÅäÖÃ
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;//ía2¿ÖD¶Ï0
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;//ÇàÕ¼óÅÏ輶0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02;//×óóÅÏ輶2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//ê1Äüía2¿ÖD¶Ïí¨μà
NVIC_Init(&NVIC_InitStructure);//ÅäÖÃ
}
void EXTI0_IRQHandler(void)
{
if(Shi_0==0)
{
printf("进入中断
“);
}
printf("发送
“);
EXTI_ClearITPendingBit(EXTI_Line0); //Çå3yLINE0éÏμÄÖD¶Ï±ê־λ
}
串口发送可以用已调试,我用的下降沿出发;用导线的一头接触GND当程序跑起来串口显示“发送”无法进入if语句求大神们给解释下
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>