目的: 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语句求大神们给解释下
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
你跟我说了以后我这样改 #define ADS1_DR GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_0)
I/O那边配置 改为
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC, ENABLE);//ê1ÄüGPIOB/Cê±Öó
//ÅäÖÃADS_DR pb0
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_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);//3õê¼»ˉ
中断那边我换成上升沿触发,if语句改为==1,发现导线接触GND怎么进入if语句,接5V什么都没发送,能解释下吗
一周热门 更多>