从D8脚输入标准的50HZ 3.3V方波,有以下的现象:
1、当Trigger在EXTI_Trigger_Rising时,在示波器里看到有时下降沿也能触发中断。
2、当Trigger在EXTI_Trigger_Falling时,在示波器里看到有时上升沿也能触发中断。
3、当Trigger在EXTI_Trigger_Rising_Falling时,在示波器里看到有时丢失触发中断。
请香主帮忙看看软件那里出问题了
#define P_D2_SET GPIOD->BSRR = GPIO_Pin_2
#define P_D2_CLR GPIOD->BRR = GPIO_Pin_2
int main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
SystemInit();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC| RCC_APB2Periph_GPIOD| RCC_APB2Periph_GPIOE|RCC_APB2Periph_AFIO, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOD, &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(GPIOD, &GPIO_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource8);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
EXTI_StructInit(&EXTI_InitStructure);
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Line = EXTI_Line8;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //EXTI_Trigger_Falling;//EXTI_Trigger_Rising_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
while(1)
{
;
}
}
unsigned char uExtLine8UpDownFlag=0;
void EXTI9_5_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line8) != RESET )
{
EXTI_ClearITPendingBit(EXTI_Line8);
if(uExtLine8UpDownFlag)
{
uExtLine8UpDownFlag =0;
P_D2_SET;
}
else
{
uExtLine8UpDownFlag =1;
P_D2_CLR;
}
}
} |