中断太多,但又不能删,用的是轮询判断哪个中断触发,但容易卡死在中断中,怎么处理[mw_shl_code=c,true]
void WiegandInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHB1PeriphClockCmd(WIEGAND1_RCC_PORT | WIEGAND2_RCC_PORT | WIEGAND4_RCC_PORT,ENABLE);
#if DEBUG
RCC_AHB1PeriphClockCmd( WIEGAND3_RCC_PORT );
#endif
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);//RCC_APB2Periph_AFIO
GPIO_InitStructure.GPIO_Pin = WIEGAND1_DATA0_GPIO | WIEGAND1_DATA1_GPIO;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //????
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; //éÏà-
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(WIEGAND1_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = WIEGAND2_DATA0_GPIO | WIEGAND2_DATA1_GPIO;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //????
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; //éÏà-
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(WIEGAND2_PORT, &GPIO_InitStructure);
#if DEBUG
GPIO_InitStructure.GPIO_Pin = WIEGAND3_DATA0_GPIO | WIEGAND3_DATA1_GPIO;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; //éÏà-
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(WIEGAND3_PORT, &GPIO_InitStructure);
#endif
GPIO_InitStructure.GPIO_Pin = WIEGAND4_DATA0_GPIO | WIEGAND4_DATA1_GPIO;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //????
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; //éÏà-
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(WIEGAND4_PORT, &GPIO_InitStructure);
//Relay_PIN_Init
GPIO_InitStructure.GPIO_Pin = Relay1_GPIO;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(Relay1_PORT, &GPIO_InitStructure);
//WIEGAND1
SYSCFG_EXTILineConfig(WIEGAND1_PortSource,EXTI_PinSource6);
EXTI_InitStructure.EXTI_Line = EXTI_Line6;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //ϽμÑØ′¥·¢
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
SYSCFG_EXTILineConfig(WIEGAND1_PortSource,EXTI_PinSource7);
//GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource1);
EXTI_InitStructure.EXTI_Line = EXTI_Line7;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //ϽμÑØ′¥·¢
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
//ÖD¶ÏóÅÏ輶
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; //ê1Äü°′¼üËùÔúμÄía2¿ÖD¶Ïí¨μà
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x03; //ÇàÕ¼óÅÏ輶
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02; //×ÖóÅÏ輶
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ê1Äüía2¿ÖD¶Ï
NVIC_Init(&NVIC_InitStructure);
//WIEGAND2
SYSCFG_EXTILineConfig(WIEGAND2_PortSource,EXTI_PinSource11);
EXTI_InitStructure.EXTI_Line = EXTI_Line11;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //ϽμÑØ′¥·¢
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
SYSCFG_EXTILineConfig(WIEGAND2_PortSource,EXTI_PinSource12);
EXTI_InitStructure.EXTI_Line = EXTI_Line12;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //ϽμÑØ′¥·¢
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
//ÖD¶ÏóÅÏ輶
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //ê1Äü°′¼üËùÔúμÄía2¿ÖD¶Ïí¨μà
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x03; //ÇàÕ¼óÅÏ輶
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02; //×ÖóÅÏ輶
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ê1Äüía2¿ÖD¶Ï
NVIC_Init(&NVIC_InitStructure);
#if DEBUG //WIEGAND3
SYSCFG_EXTILineConfig(WIEGAND3_PortSource,EXTI_PinSource8);
EXTI_InitStructure.EXTI_Line = EXTI_Line8;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //ϽμÑØ′¥·¢
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
SYSCFG_EXTILineConfig(WIEGAND3_PortSource,EXTI_PinSource14);
//GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource1);
EXTI_InitStructure.EXTI_Line = EXTI_Line14;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //ϽμÑØ′¥·¢
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
//ÖD¶ÏóÅÏ輶
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn ; //ê1Äü°′¼üËùÔúμÄía2¿ÖD¶Ïí¨μà
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x03; //ÇàÕ¼óÅÏ輶
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02; //×ÖóÅÏ輶
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ê1Äüía2¿ÖD¶Ï
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //ê1Äü°′¼üËùÔúμÄía2¿ÖD¶Ïí¨μà
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x03; //ÇàÕ¼óÅÏ輶
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02; //×ÖóÅÏ輶
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ê1Äüía2¿ÖD¶Ï
NVIC_Init(&NVIC_InitStructure);
#endif
//WIEGAND4
SYSCFG_EXTILineConfig(WIEGAND4_PortSource,EXTI_PinSource4);
EXTI_InitStructure.EXTI_Line = EXTI_Line4;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //ϽμÑØ′¥·¢
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
SYSCFG_EXTILineConfig(WIEGAND4_PortSource,EXTI_PinSource5);
//GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource1);
EXTI_InitStructure.EXTI_Line = EXTI_Line5;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //ϽμÑØ′¥·¢
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
//ÖD¶ÏóÅÏ輶
NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQn;//ía2¿ÖD¶Ï0
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x03;//ÇàÕ¼óÅÏ輶0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02;//×óóÅÏ輶2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//ê1Äüía2¿ÖD¶Ïí¨μà
NVIC_Init(&NVIC_InitStructure);//ÅäÖÃ
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;//ía2¿ÖD¶Ï0
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x03;//ÇàÕ¼óÅÏ輶0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02;//×óóÅÏ輶2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//ê1Äüía2¿ÖD¶Ïí¨μà
NVIC_Init(&NVIC_InitStructure);//ÅäÖÃ
}
//Read_WG
/***********************************************************
* oˉêyÃû:EXTI15_10_IRQHandler
* 1| Äü
ATAêy¾YÏßÖD¶Ï·tÎñoˉêy
* êä èë:ÎT
* êä 3ö:ÎT
**********************************************************/
void EXTI4_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line4) != RESET && flag_wiegand[3]==0) //WIEGAND4_A
{ //Data0 -> »ñμÃò»Î»0
if(u_DataBits[3] == 0)
{
u_EvenCheck[3]=0; //żD£Ñéλ
}
else if(u_DataBits[3] == (WG_DATA_BITS-1))
{
u_OddCheck[3]=0; //ÆæD£Ñéλ
}
else
{
//printf("0");
WG_Data[3]<<=1;
}
u_DataBits[3]++;
EXTI_ClearITPendingBit(EXTI_Line4);
}
if(u_DataBits[3] >= WG_DATA_BITS)
{
flag_wiegand[3]=1;
return;
}
}
void EXTI9_5_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line5) != RESET && flag_wiegand[3]==0) //WIEGAND4_B
{ //Data1 -> »ñμÃò»Î»1
if(u_DataBits[3] == 0)
{
u_EvenCheck[3]=1; //żD£Ñéλ
}
else if(u_DataBits[3] == (WG_DATA_BITS-1))
{
u_OddCheck[3]=1; //ÆæD£Ñéλ
}
else
{
//printf("1");
WG_Data[3]<<=1;
WG_Data[3]|=1;
}
u_DataBits[3]++;
EXTI_ClearITPendingBit(EXTI_Line5);
}
else if(EXTI_GetITStatus(EXTI_Line6) != RESET && flag_wiegand[0]==0) //WIEGAND1_A
{ //Data0 -> »ñμÃò»Î»0
if(u_DataBits[0] == 0)
{
u_EvenCheck[0]=0; //żD£Ñéλ
}
else if(u_DataBits[0] == (WG_DATA_BITS-1))
{
u_OddCheck[0]=0; //ÆæD£Ñéλ
}
else
{
//printf("0");
WG_Data[0]<<=1;
}
u_DataBits[0]++;
EXTI_ClearITPendingBit(EXTI_Line6);
}
else if(EXTI_GetITStatus(EXTI_Line7) != RESET && flag_wiegand[0]==0) //WIEGAND1_B
{ //Data1 -> »ñμÃò»Î»1
if(u_DataBits[0] == 0)
{
u_EvenCheck[0]=1; //żD£Ñéλ
}
else if(u_DataBits[0] == (WG_DATA_BITS-1))
{
u_OddCheck[0]=1; //ÆæD£Ñéλ
}
else
{
//printf("1");
WG_Data[0]<<=1;
WG_Data[0]|=1;
}
u_DataBits[0]++;
EXTI_ClearITPendingBit(EXTI_Line7);
}
else if(EXTI_GetITStatus(EXTI_Line8) != RESET && flag_wiegand[2]==0) //WIEGAND3_A
{ //Data0 -> »ñμÃò»Î»0
if(u_DataBits[2] == 0)
{
WG_Data[2]=0x0;
u_EvenCheck[2]=0; //żD£Ñéλ
}
else if(u_DataBits[2] == (WG_DATA_BITS-1))
{
u_OddCheck[2]=0; //ÆæD£Ñéλ
}
else
{
//printf("0");
WG_Data[2]<<=1;
}
//[u_DataBits] = 1;
u_DataBits[2]++;
EXTI_ClearITPendingBit(EXTI_Line8);
}
//éèÖñê־λ
if(u_DataBits[0] >= WG_DATA_BITS)
{
flag_wiegand[0]=1;
return ;
}
else if(u_DataBits[2] >= WG_DATA_BITS)
{
flag_wiegand[2]=1;
return ;
}
else if(u_DataBits[3] >= WG_DATA_BITS)
{
flag_wiegand[3]=1;
return ;
}
}
void EXTI15_10_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line11) != RESET && flag_wiegand[1]==0) //WIEGAND2_A
{ //Data0 -> »ñμÃò»Î»0
if(u_DataBits[1] == 0)
{
WG_Data[1]=0x0;
u_EvenCheck[1]=0; //żD£Ñéλ
}
else if(u_DataBits[1] == (WG_DATA_BITS-1))
{
u_OddCheck[1]=0; //ÆæD£Ñéλ
}
else
{
//printf("0");
WG_Data[1]<<=1;
}
u_DataBits[1]++;
EXTI_ClearITPendingBit(EXTI_Line11);
}
else if(EXTI_GetITStatus(EXTI_Line12) != RESET && flag_wiegand[1]==0) //WIEGAND2_B
{ //Data1 -> »ñμÃò»Î»1
if(u_DataBits[1] == 0)
{
WG_Data[1]=0x0;
u_EvenCheck[1]=1; //żD£Ñéλ
}
else if(u_DataBits[1] == (WG_DATA_BITS-1))
{
u_OddCheck[1]=1; //ÆæD£Ñéλ
}
else
{
//printf("1");
WG_Data[1]<<=1;
WG_Data[1]|=1;
}
//[u_DataBits] = 1;
u_DataBits[1]++;
EXTI_ClearITPendingBit(EXTI_Line12);
}
else if(EXTI_GetITStatus(EXTI_Line14) != RESET && flag_wiegand[2]==0 )//WIEGAND3_B
{ //Data1 -> »ñμÃò»Î»1
if(u_DataBits[2] == 0)
{
WG_Data[2]=0x0;
u_EvenCheck[2]=1; //żD£Ñéλ
}
else if(u_DataBits[2] == (WG_DATA_BITS-1))
{
u_OddCheck[2]=1; //ÆæD£Ñéλ
}
else
{
//printf("1");
WG_Data[2]<<=1;
WG_Data[2]|=1;
}
//[u_DataBits] = 1;
u_DataBits[2]++;
EXTI_ClearITPendingBit(EXTI_Line14);
}
if(u_DataBits[1] >= WG_DATA_BITS)
{
flag_wiegand[1]=1;
return ;
}
else if(u_DataBits[2] >= WG_DATA_BITS)
{
flag_wiegand[2]=1;
return ;
}
}
[/mw_shl_code]
一周热门 更多>