STM32的tim1n捕获问题

项目中要使用stm32的 tim1通道3捕获红外波形,stm32f107的芯片。PE12管脚,但实际中发现竟然进不了捕获中断。

代码

/************************************************************************
函数名称:Remote_Init
功能:PE12初始化输入  定时器1 通道3 输入捕获
输入参数:void
输出参数:void
作者: v
************************************************************************/

void Remote_Init(void)        

 GPIO_InitTypeDef GPIO_InitStructure;
 NVIC_InitTypeDef NVIC_InitStructure;
 TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
 TIM_ICInitTypeDef  TIM_ICInitStructure; 
 
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE); //PE口
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE); //TIM1 时钟 

 GPIO_InitStructure.GPIO_Pin = IR_LED_PIN;     //PE
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;   //
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(IR_LED_PORT, &GPIO_InitStructure);
  GPIO_SetBits(IR_LED_PORT,IR_LED_PIN); //
 
       
  TIM_TimeBaseStructure.TIM_Period = 10000; //设定计数器自动重装值  
 TIM_TimeBaseStructure.TIM_Prescaler =(72-1);  //预分频器 1M的计数频率  1us加1  
 TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //设置时钟分割 :TDTS = Tck_tim
 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  //TIM向上计数

 TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); //初始化 参数

   TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;  // 映射通道3  TIM1_CH3N
   TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //上升沿补
   TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;//直接定时器补获
   TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;  //输入不分频
   TIM_ICInitStructure.TIM_ICFilter = 0x03;//IC4F=0011 配置输入滤波器 8个定时器时钟周期滤波
   TIM_ICInit(TIM1, &TIM_ICInitStructure);//3初始化参数
    TIM_ITConfig( TIM1,TIM_IT_Update|TIM_IT_CC3,ENABLE);//允许通道3捕获中断 
        TIM_Cmd(TIM1,ENABLE );  //使能
 
 NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;  //TIM1
 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;  //先占优先级0级
 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;  //′从优先级3
 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ使能
 NVIC_Init(&NVIC_InitStructure);  //初始化NVIC寄存器
       
       NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn;  //TIM1
 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;  //先占优先级0级
 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;  //′从优先级3
 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ使能
 NVIC_Init(&NVIC_InitStructure);  //初始化NVIC寄存器
        
}
 

 

sitemap