主程序循环中一直打印不出东西;调试时一直死在if(it1 == 1),确认定时器工作了,it1 =1 了;但是就是进不了if处理程序!
void TIM2_NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
//TIM_Period--1000 TIM_Prescaler--71 -->中断周期为1ms//
void TIM2_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 , ENABLE);
// TIM_DeInit(TIM2);
TIM_TimeBaseStructure.TIM_Period=1000; // 自动重装载寄存器周期的值(计数值)//
// 累计 TIM_Period个频率后产生一个更新或者中断//
TIM_TimeBaseStructure.TIM_Prescaler= (72 - 1); // 时钟预分频数 72M/72 //
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1; // 采样分频 //
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; // 向上计数模式 //
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_ClearFlag(TIM2, TIM_FLAG_Update); // 清除溢出中断标志 //
TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);
// RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 , DISABLE); //先关闭等待使用//
}
__attribute__((interrupt("WCH-Interrupt-fast")))
void TIM2_IRQHandler(void)
{
if ( TIM_GetITStatus(TIM2 , TIM_IT_Update) != RESET ){
TIM_ClearITPendingBit(TIM2 , TIM_FLAG_Update);
time++;//check_delaytime();
if ( time == 10 ) { time = 0; // 100ms 时间到
it1 = 1;
}
}
}
/*******************************************************************************
* Function Name : main
* Description : Main program.
* Input : None
* Return : None
*******************************************************************************/
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
Delay_Init();
USART_Printf_Init(115200);
printf("SystemClk:%d\r\n",SystemCoreClock);
TIM2_NVIC_Configuration();
TIM2_Configuration();
TIM_Cmd(TIM2, ENABLE);
//printf("This is printf example\r\n");
it1 = 0;
while(1)
{
if(it1 == 1){
printf("This is printf example\r\n");
it1=0;
}
}
}