关了TIM2了为什么还能进去中断的

[复制链接]
2946|2
 楼主| 拿起书本 发表于 2013-8-7 21:02 | 显示全部楼层 |阅读模式
TI, AC, BLE
1.jpg
请教一下,我明明用TIM_Cmd(TIM2, DISABLE);关了TIM2了
为什么还能进去中断的?
2.jpg
 楼主| 拿起书本 发表于 2013-8-7 22:47 | 显示全部楼层
测试后,发现进去一次之后就没再进中断了。
but为啥会进去一次了?不是一次都不应该进中断的吗
logokfu 发表于 2013-8-8 10:21 | 显示全部楼层
拿起书本 发表于 2013-8-7 22:47
测试后,发现进去一次之后就没再进中断了。
but为啥会进去一次了?不是一次都不应该进中断的吗 ...


同学,注意这个函数的最后一句的功能。


  1. /**
  2. Initializes the TIMx Time Base Unit peripheral according to
  3. * the specified parameters in the TIM_TimeBaseInitStruct.
  4. * @param TIMx: where x can be 1 to 17 to select the TIM peripheral.
  5. * @param TIM_TimeBaseInitStruct: pointer to a TIM_TimeBaseInitTypeDef
  6. * structure that contains the configuration information for the
  7. * specified TIM peripheral.
  8. * @retval None
  9. */
  10. void TIM_TimeBaseInit(TIM_TypeDef* TIMx, TIM_TimeBaseInitTypeDef* TIM_TimeBaseInitStruct)
  11. {
  12. uint16_t tmpcr1 = 0;

  13. /* Check the parameters */
  14. assert_param(IS_TIM_ALL_PERIPH(TIMx));
  15. assert_param(IS_TIM_COUNTER_MODE(TIM_TimeBaseInitStruct->TIM_CounterMode));
  16. assert_param(IS_TIM_CKD_DIV(TIM_TimeBaseInitStruct->TIM_ClockDivision));

  17. tmpcr1 = TIMx->CR1;

  18. if((TIMx == TIM1) || (TIMx == TIM8)|| (TIMx == TIM2) || (TIMx == TIM3)||
  19. (TIMx == TIM4) || (TIMx == TIM5))
  20. {
  21. /* Select the Counter Mode */
  22. tmpcr1 &= (uint16_t)(~((uint16_t)(TIM_CR1_DIR | TIM_CR1_CMS)));
  23. tmpcr1 |= (uint32_t)TIM_TimeBaseInitStruct->TIM_CounterMode;
  24. }

  25. if((TIMx != TIM6) && (TIMx != TIM7))
  26. {
  27. /* Set the clock division */
  28. tmpcr1 &= (uint16_t)(~((uint16_t)TIM_CR1_CKD));
  29. tmpcr1 |= (uint32_t)TIM_TimeBaseInitStruct->TIM_ClockDivision;
  30. }

  31. TIMx->CR1 = tmpcr1;

  32. /* Set the Autoreload value */
  33. TIMx->ARR = TIM_TimeBaseInitStruct->TIM_Period ;

  34. /* Set the Prescaler value */
  35. TIMx->PSC = TIM_TimeBaseInitStruct->TIM_Prescaler;

  36. if ((TIMx == TIM1) || (TIMx == TIM8)|| (TIMx == TIM15)|| (TIMx == TIM16) || (TIMx == TIM17))
  37. {
  38. /* Set the Repetition Counter value */
  39. TIMx->RCR = TIM_TimeBaseInitStruct->TIM_RepetitionCounter;
  40. }

  41. /* Generate an update event to reload the Prescaler and the Repetition counter
  42. values immediately */
  43. TIMx->EGR = TIM_PSCReloadMode_Immediate;
  44. }



您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:好好学习,天天向上!

519

主题

4194

帖子

31

粉丝
快速回复 在线客服 返回列表 返回顶部