Code:
#include
# include "stm32f10x_exti. H"
# include "delay. H"
//external interrupt 0 service program
Void EXTIX_Init (void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
//discipline configuration
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOA, ENABLE);//can make PB, PC port clock
//SoftWare Serial TXD
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_10;
GPIO_InitStructure. GPIO_Mode=GPIO_InitStructure. GPIO_Mode=GPIO_Mode_IPD;//set to pull the input
GPIO_InitStructure. GPIO_Speed=GPIO_Speed_50MHz;//IO port speed of 50 MHZ
GPIO_Init (GPIOB, & amp; GPIO_InitStructure);
//GPIO_ResetBits (GPIOB, GPIO_Pin_10);
//SoftWare Serial TXD
//GPIO_InitStructure. GPIO_Pin=GPIO_Pin_9;
//GPIO_InitStructure. GPIO_Mode=GPIO_Mode_Out_PP;//input mode selection for floating empty input//push-pull output
//GPIO_InitStructure. GPIO_Speed=GPIO_Speed_50MHz;//IO port speed of 50 MHZ
//
//GPIO_Init (GPIOB, & amp; GPIO_InitStructure);
//GPIO_SetBits (GPIOB, GPIO_Pin_9);
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_10;
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_Out_PP;//input mode selection for floating empty input//push-pull output
GPIO_InitStructure. GPIO_Speed=GPIO_Speed_50MHz;//IO port speed of 50 MHZ
GPIO_Init (GPIOA, & amp; GPIO_InitStructure);
GPIO_SetBits (GPIOA, GPIO_Pin_10);
//SoftWare Serial TXD
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_8;
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_Out_PP;//push-pull output
GPIO_InitStructure. GPIO_Speed=GPIO_Speed_50MHz;//IO port speed of 50 MHZ
GPIO_Init (GPIOB, & amp; GPIO_InitStructure);
GPIO_ResetBits (GPIOB, GPIO_Pin_8);
RCC_APB2PeriphClockCmd (RCC_APB2Periph_AFIO, ENABLE);//(2) open AFIO clock
//GPIOE. 2 bolt and interrupt initialization configuration, falling edge trigger
GPIO_EXTILineConfig (GPIO_PortSourceGPIOB, GPIO_PinSource10);//(3)
EXTI_InitStructure. EXTI_Line=EXTI_Line10;
EXTI_InitStructure. EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitStructure. EXTI_Trigger=EXTI_Trigger_Rising;//drop along the trigger
EXTI_InitStructure. EXTI_LineCmd=ENABLE;
EXTI_Init (& amp; EXTI_InitStructure);//(4) initialization bolt parameters in
NVIC_InitStructure. NVIC_IRQChannel=EXTI15_10_IRQn;//can make key external interrupt channel
NVIC_InitStructure. NVIC_IRQChannelPreemptionPriority=0 x02;//take priority 2,
NVIC_InitStructure. NVIC_IRQChannelSubPriority=0 x02;//child priority 2
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;//can make external interrupt channel
NVIC_Init (& amp; NVIC_InitStructure);//(5) initializes the NVIC
}
//6 external interrupt service routine 2
U8 text=1;
Void EXTI15_10_IRQHandler (void)
{
If (EXTI_GetITStatus (EXTI_Line10)!={
RESET)GPIO_SetBits (GPIOB, GPIO_Pin_8);
delay_ms(100);
GPIO_ResetBits (GPIOB, GPIO_Pin_8);
delay_ms(100);
Text=1;
delay_ms(1000);
Text=0;
EXTI_ClearITPendingBit (EXTI_Line10);//clear the interrupt flag bit on the LINE
}
}
Int main (void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
EXTIX_Init ();
while(1);
}
CodePudding user response:
No added time delay to the interrupt function, this is common sense,CodePudding user response:
First one is a must not be inside the interrupt service function plus time delay function, and then your external function is set down along the trigger, your main function does not have the change of the level, the external interrupt you certainly won't trigger, but finally you inside the interrupt function to a level of change, your function is certainly not be achieved,CodePudding user response:
Consider a state machine, the architecture of theJust set in interrupt service status, the status of task processing, in the main program to do,
As far as possible avoid perform time-consuming longer operating in the interrupt service,
CodePudding user response: