Home > other >  To solve the stm32 of external interrupt latency, added a problem
To solve the stm32 of external interrupt latency, added a problem

Time:10-02

I, in the external interrupt set led lit 1 s and then off, but it has been a bright experiment led, solving according to?

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 the

Just 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:

refer to the second floor JohnnyTim response:
is the first one is must not add delay function in interrupt service 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 for a level changes, the function of your affirmation is unable to realize,
I set up delay, and external interrupt is separate by a high level of external

CodePudding user response:

Online to find an explanation:
Assume that interrupt latency, that when in the interrupt delay subroutine, next interruption, then transferred to an interrupt, the next interruption delay subroutine will come again in the next interruption... ... So, this is a dead nested, assembly inside will be better understood

CodePudding user response:

How can add a delay in the interrupt, will affect other task to run first, second, the interruption of delay hasn't arrived, the interrupt what happened again,

CodePudding user response:

Sail share GouFuGui regulations

CodePudding user response:

Well,, hair wrong
External interrupt added because external could interrupt at any time, so can't add delay function, why not add inside the timer interrupt?
  • Related