你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

查看: 5238|回复: 1

帮忙看下,为啥TIM2中断进不去??

[复制链接]

9

主题

28

回帖

0

蝴蝶豆

初级会员

最后登录
1970-1-1
发表于 2010-12-7 21:30:47 | 显示全部楼层 |阅读模式
想要用tim2 产生1ms的中断。
用下面函数初始化后, 中断函数void TIM2_IRQHandler(void) 进不去,没有中断产生.
求教问题所在。
void Aux_Init(void)
{
 TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
 TIM_OCInitTypeDef  TIM_OCInitStructure;
 NVIC_InitTypeDef NVIC_InitStructure;
 
   /* TIM2 clock enable */
   RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
   /* Enable the TIM2 gloabal Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
   /* Time Base configuration */
  TIM_TimeBaseStructure.TIM_Prescaler = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseStructure.TIM_Period = 999;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Enable);

   /* Output Compare Timing Mode configuration: Channel1 */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = 999;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
     TIM_OC1Init(TIM2, &TIM_OCInitStructure);
   TIM_ITConfig(TIM2, TIM_IT_CC1 , ENABLE);
   TIM_Cmd(TIM2, ENABLE); 
}
回复

使用道具 举报

134

主题

4489

回帖

239

蝴蝶豆

版主

最后登录
2020-12-9
发表于 2010-12-8 14:29:30 | 显示全部楼层

RE:帮忙看下,为啥TIM2中断进不去??

/* Time base configuration */
  TIM_TimeBaseStructure.TIM_Period = 0xFFFF;         
  TIM_TimeBaseStructure.TIM_Prescaler = 0x02;      
  TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;   
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  
  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
  /* Output Compare Toggle Mode configuration: Channel1 */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;         
  TIM_OCInitStructure.TIM_Channel = TIM_Channel_1;         
  TIM_OCInitStructure.TIM_Pulse = CCR1_Val;  
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
  TIM_OCInit(TIM2, &TIM_OCInitStructure);
  TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Disable);
  /* Output Compare Toggle Mode configuration: Channel2 */
  TIM_OCInitStructure.TIM_Channel = TIM_Channel_2;         
  TIM_OCInitStructure.TIM_Pulse = CCR2_Val;  
  
  TIM_OCInit(TIM2, &TIM_OCInitStructure);
  TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Disable);
  /* Output Compare Toggle Mode configuration: Channel3 */
  TIM_OCInitStructure.TIM_Channel = TIM_Channel_3;         
  TIM_OCInitStructure.TIM_Pulse = CCR3_Val;  
  
  TIM_OCInit(TIM2, &TIM_OCInitStructure);
  TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Disable);
  /* Output Compare Toggle Mode configuration: Channel4 */
  TIM_OCInitStructure.TIM_Channel = TIM_Channel_4;         
  TIM_OCInitStructure.TIM_Pulse = CCR4_Val;  
  
  TIM_OCInit(TIM2, &TIM_OCInitStructure);
  TIM_OC4PreloadConfig(TIM2, TIM_OCPreload_Disable);
  
  /* TIM enable counter */
  TIM_Cmd(TIM2, ENABLE);
  /* TIM IT enable */
  TIM_ITConfig(TIM2, TIM_IT_CC1 | TIM_IT_CC2 | TIM_IT_CC3 | TIM_IT_CC4, ENABLE);
这样配置一下试试
回复 支持 反对

使用道具 举报

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
13245底部标题123相同标题
12底部标题123相同标题
33333底部标题123相同序号
3435底部标题-无链接
关注我们
st-img 微信公众号
st-img 手机版