外部中断调用延时函数的时候卡住了

2019-07-21 05:08发布

#ifndef __DELAY_H
#define __DELAY_H

void SysTick_Init(void);
void delay_ms(unsigned int time);
void delay_us(unsigned int time);

#endif

#include "stm32f4xx.h"
unsigned int TimingDelay = 0;
void SysTick_Init()
{
if(SysTick_Config(SystemCoreClock/1000000))
{
while(1);
}
}

void delay_ms(unsigned int time)
{
  TimingDelay=1000*time;
  while(TimingDelay);
}
void delay_us(unsigned int time)
{
  TimingDelay=time;
  while(TimingDelay);
}

void SysTick_Handler()
{
  if(TimingDelay)
        {
        TimingDelay--;
        }
}

#include "stm32f4xx.h"
#include "delay.h"
#include "beep.h"
#include "key.h"
#include "led.h"
#include "exti.h"
#include "usart.h"

void EXTI4_IRQHandler()
{

delay_ms(10);

if(KEY0==0)
{
LED0_REV;
EXTI_ClearITPendingBit(EXTI_Line4);
}

}

void EXTI3_IRQHandler()
{

delay_ms(10);

if(KEY1==0)
{
  LED1_REV;
        EXTI_ClearITPendingBit(EXTI_Line3);
}


}

void EXTI2_IRQHandler()
{

delay_ms(10);

if(KEY2==0)
{
  LED0_REV;
        LED1_REV;
        EXTI_ClearITPendingBit(EXTI_Line2);
}


}

void EXTI0_IRQHandler()
{

delay_ms(10);

if(KEY_UP==0)
{
  BEEP_REV;
        EXTI_ClearITPendingBit(EXTI_Line0);
}


}

void KEY_EXTI_Init()
{
        EXTI_InitTypeDef EXTI_InitStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
       
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG,ENABLE);
       
KEY_Init();
       
        SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE,EXTI_PinSource4);
        SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE,EXTI_PinSource3);
        SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE,EXTI_PinSource2);
        SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA,EXTI_PinSource0);
       
        EXTI_InitStructure.EXTI_Line=EXTI_Line4|EXTI_Line3|EXTI_Line2;
        EXTI_InitStructure.EXTI_LineCmd=ENABLE;
        EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;
        EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling;
        EXTI_Init(&EXTI_InitStructure);
       
        EXTI_InitStructure.EXTI_Line=EXTI_Line0;
        EXTI_InitStructure.EXTI_LineCmd=ENABLE;
        EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;
        EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Rising;
        EXTI_Init(&EXTI_InitStructure);
       
        NVIC_InitStructure.NVIC_IRQChannel=EXTI4_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
        NVIC_Init(&NVIC_InitStructure);
       
        NVIC_InitStructure.NVIC_IRQChannel=EXTI3_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
        NVIC_Init(&NVIC_InitStructure);
       
        NVIC_InitStructure.NVIC_IRQChannel=EXTI2_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
        NVIC_Init(&NVIC_InitStructure);
       
        NVIC_InitStructure.NVIC_IRQChannel=EXTI4_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
        NVIC_Init(&NVIC_InitStructure);
}
#include "stm32f4xx.h"
#include "delay.h"
#include "led.h"
#include "beep.h"
#include "key.h"
#include "exti.h"
#include "usart.h"

int main()
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
       
  SysTick_Init();
        LED_Init();
  BEEP_Init();
  KEY_EXTI_Init();
        My_USART1_Init();

while(1)
{        USART_SendData(USART1,65);

        delay_ms(100);
}
}

delay延时函数是用滴答定时器中断方式实现的

程序一旦执行到void EXTI4_IRQHandler()
{

delay_ms(10);

if(KEY0==0)
{
LED0_REV;
EXTI_ClearITPendingBit(EXTI_Line4);
}

}中的延时函数时就卡住了,求解!!!

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
3条回答
jiangzhiwei
1楼-- · 2019-07-21 10:46
找到原因了,因为systick定时器的中断优先级比较低,所以在中断里面调用,优先级比外部中断本身还要低,会卡在delay_ms()里面
login_FAE
2楼-- · 2019-07-21 15:21
中断函数里面别做费时的操作
jiangzhiwei
3楼-- · 2019-07-21 16:54
login_FAE 发表于 2018-3-26 18:10
中断函数里面别做费时的操作

我还是不明白中断里面为什么不能调用那个延时的函数,delay延时函数是用systick定时器中断实现的

一周热门 更多>