我使用的是STM32F103VET6,现在用到了定时器中断3和外部中断。这两个中断单独都能使用。但是在外部中断中调用定时器中断,则定时器不进行中断。猜测是在进入外部中断后关闭了总中断,从而定时器中断不响应。我设置的定时器中断优先级是2,外部中断时4.
void TIME3_INIT(void){//10us中断
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel=TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;
//抢占优先级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority=2;//响应优先级0
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
//启动此通道的中断
NVIC_Init(&NVIC_InitStructure);
TIM_DeInit(TIM3);//定义10us
TIM_TimeBaseStructure.TIM_Period = 179;
TIM_TimeBaseStructure.TIM_Prescaler = 3;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
// 定时时间T计算公式:
//T=(TIM_Period+1)*(TIM_Prescaler+1)/TIMxCLK=(35999+1)*(1999+1)/72MHz=1s
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);
TIM_Cmd(TIM3,ENABLE);
}
//IR INPUT
//外部中断初始化
RCC_APB2PeriphClockCmd(IR_INPUT_CLOCK, ENABLE);
gpio.GPIO_Mode = GPIO_Mode_IN_FLOATING;
gpio.GPIO_Pin = IR_INPUT_PIN;
gpio.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(IR_BASE, &gpio);
//IR 中断
GPIO_EXTILineConfig(IR_INT_PORT, IR_INT_PIN);
exti.EXTI_Line = IR_INT_LINE;
exti.EXTI_Mode = EXTI_Mode_Interrupt;
exti.EXTI_Trigger = EXTI_Trigger_Falling; //下降沿触发
exti.EXTI_LineCmd = ENABLE;
EXTI_Init(&exti);
nvic.NVIC_IRQChannel = IR_INT_CHANNEL;
nvic.NVIC_IRQChannelPreemptionPriority = 4;
nvic.NVIC_IRQChannelSubPriority = 4;
nvic.NVIC_IRQChannelCmd = ENABLE;
NVIC_ClearPendingIRQ(IR_INT_CHANNEL);
NVIC_Init(&nvic); |