打印

求助TIM1 溢出中断

[复制链接]
2174|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
nobleyinhuan|  楼主 | 2011-12-16 09:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
TI, IO, pi, GPIO, gp
香水城版主-----这是我第一个STM32的单片机的例子,以前使用过STM8S系列的单片机.
我用TIM1 测试中断,它就是死活进不了中断,郁闷呀,哪位大虾帮忙看看,问题出在哪里.下面是我的例程.
void RCC_Configura(void)
{ RCC_DeInit();
  RCC_HSEConfig(RCC_HSE_ON);
//SystemInit();   
}
//---------------------------------------------------------------------
void GPIOD_Configure(void)
{ GPIO_InitTypeDef GPIO_InitStructure;
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD| RCC_APB2Periph_AFIO, ENABLE);
    GPIO_InitStructure.GPIO_Pin = LED1|LED2|LED3|LED4;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_SetBits(GPIOD,LED1|LED2|LED3|LED4);
}
//-----------------------------------------------------------------------
void TIM1_Configure(void)
{ TIM_TimeBaseInitTypeDef TIM1_InitStructure;
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
TIM1_InitStructure.TIM_Prescaler =  0x0;
TIM1_InitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM1_InitStructure.TIM_Period = (10000-1);
TIM1_InitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM1_InitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM1,&TIM1_InitStructure);  /*SET TIM1 VAUALE*/
TIM_ClearITPendingBit(TIM1,TIM_IT_Update);
TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
TIM_SetCounter(TIM1,0);
TIM_Cmd(TIM1,ENABLE);  
}
//-------------------------------------------------------------------
void  Interrupt_Configure(void)
{ NVIC_InitTypeDef NVIC_InitStructure;
   NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0000);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn;
   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
} //-----------------------------------------------------------------------------

int main(void)
{ RCC_Configura();
    GPIOD_Configure();
TIM1_Configure();
Interrupt_Configure();  
GPIO_ResetBits(GPIOD, LED1|LED3);  
    while (1)
   { GPIO_SetBits(GPIOD,LED4);
delay(1000000);
GPIO_ResetBits(GPIOD,LED4);
delay(1000000);
   }
}
//--------------------------------------------------------
以下是中断服务子程序
/////////////////////////////////////////////////////////////
void TIM1_UP_IRQHandler (void)
{ TIM_ClearFlag(TIM1,TIM_FLAG_Update);
GPIO_ResetBits(GPIOD,LED2);
GPIO_SetBits(GPIOD,LED1);

}
沙发
nobleyinhuan|  楼主 | 2011-12-16 09:41 | 只看该作者
如果定时器中断后, LED2会亮,LED1 灭.郁闷呀!就是实现不了.

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

11

主题

34

帖子

1

粉丝