stm32高级定时器使用的问题

2019-03-23 18:19发布

我直接更改的一个例程,通用定时器2的比较输出,然后把2改成了1,还有APB
1改为APB2,主函数运行,但是进入不了中断,也不知道为什么?
void GPIO_Configuration(void)
{
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitTypeDef GPIO_InitStruct;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_Speed =GPIO_Speed_Level_3;
GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_2);

//  GPIO_SetBits(GPIOA, GPIO_Pin_11 | GPIO_Pin_12 );
}

void TIM_INT_Config(void)
{
   NVIC_InitTypeDef NVIC_InitStructure;
  /* TIM1 clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
  /*  TIM1 ÖжÏǶÌ×Éè¼Æ*/
  NVIC_InitStructure.NVIC_IRQChannel = TIM1_BRK_UP_TRG_COM_IRQn;//TIM1_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPriority = 2;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}

void TIM_OUT_Config(void)
{
/* -----------------------------------------------------------------------
      TIM_TimeBaseStructure.TIM_Period = 65535;
  TIM_TimeBaseStructure.TIM_Prescaler = 0;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
  /* Ô¤·ÖƵÆ÷ÅäÖà */
  TIM_PrescalerConfig(TIM1, PrescalerValue, TIM_PSCReloadMode_Immediate);
  /* Êä³ö±È½ÏʱÐòģʽÅäÖÃÉèÖà */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
  /* Êä³ö±È½ÏʱÐòģʽÅäÖÃ: ƵµÀ1*/
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = 20;
  TIM_OC1Init(TIM1, &TIM_OCInitStructure);
  TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Disable);
  
  TIM_ITConfig(TIM1, TIM_IT_CC1, ENABLE);
  TIM_Cmd(TIM1, ENABLE);
}
此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。