程序接收的是26或34的韦根数据。设置断点的时候看得出来能进入中断,但为啥read函数里没数据
void RCC_cfg()
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
}
void IO_cfg(void)
{
GPIO_InitTypeDef GPIO_InitStruct ;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_9|GPIO_Pin_10;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_IPU;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStruct);
}
void NVIC_cfg(void)
{
NVIC_InitTypeDef NVIC_InitStruct;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStruct.NVIC_IRQChannel = EXTI9_5_IRQn;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
NVIC_InitStruct.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
}
void EXIT_cfg(void)
{
EXTI_InitTypeDef EXTI_InitStruct;
EXTI_ClearITPendingBit(EXTI_Line9);
EXTI_ClearITPendingBit(EXTI_Line10);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource9);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource10);
EXTI_InitStruct.EXTI_Line=EXTI_Line9|EXTI_Line10;
EXTI_InitStruct.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitStruct.EXTI_Trigger=EXTI_Trigger_Falling;
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStruct);
EXTI_GenerateSWInterrupt(EXTI_Line9);
EXTI_GenerateSWInterrupt(EXTI_Line10);
}
void EXTI9_5_IRQHandler(void)
{
EXTI_ClearITPendingBit(EXTI_Line9);
//if(!GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_9))
//{
exti_count++;
extidata<<=1;
extidata&=0xfffffffe;
//}
}
void EXTI15_10_IRQHandler(void)
{
EXTI_ClearITPendingBit(EXTI_Line10);
//if(!GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_10))
//{
exti_count++;
extidata<<=1;
extidata|=1;
//}
}
void Init(void)
{
exti_count=0;
exti_data=0;
extidata=0;
RCC_cfg();
IO_cfg();
NVIC_cfg();
EXIT_cfg();
}
void EXTI_Read(void)
{
switch(exti_count)
{
case 26:
case 34:
{
exti_data=(uint16)(extidata>>1);
DisplayBuffer[0]=((uint8)(exti_data>>12))&0x0f;
DisplayBuffer[1]=((uint8)(exti_data>>8))&0x0f;
DisplayBuffer[2]=((uint8)(exti_data>>4))&0x0f;
DisplayBuffer[3]=(uint8)(exti_data&0x0f);
}
default:
{
exti_count=0;
exti_data=0;
extidata=0; break;
}
}
} |