STM32F207 输入捕获进不了中断搞了一上午了,求解释!!

2019-10-16 04:11发布

        GPIO_InitTypeDef GPIO_InitStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
        TIM_ICInitTypeDef  TIM_ICInitStructure;  

        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE); //PORTA
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5,ENABLE);        //TIM5

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;                                 
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;;        
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
        GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;;
        GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
//         GPIO_SetBits(GPIOA,GPIO_Pin_2);        //

        TIM_TimeBaseStructure.TIM_Period = 10000; ;
        TIM_TimeBaseStructure.TIM_Prescaler =(SystemCoreClock/2/1000000-1);                   
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  
        TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure);
       
        NVIC_InitStructure.NVIC_IRQChannel = TIM5_IRQn;;  
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);
        TIM_ITConfig( TIM5,TIM_IT_CC3,ENABLE);
       
  TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;
  TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_BothEdge;       
  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;       
  TIM_ICInitStructure.TIM_ICFilter = 0;
  TIM_ICInit(TIM5, &TIM_ICInitStructure);
        TIM_Cmd(TIM5,ENABLE );        

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。