STM32F4 TIM4 第二通道 配置成输入捕获,但已经进不了中断,求助。
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM4_ICInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
uint16_t PrescalerValue = 0;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //????100MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //???ì????????
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //????
GPIO_Init(GPIOD, &GPIO_InitStructure);
//GPIO_ResetBits(GPIOD,GPIO_Pin_13);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource13, GPIO_AF_TIM4);
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 65535; //?????÷
TIM_TimeBaseStructure.TIM_Prescaler = 0; //???±??·????ó?????????÷
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Down;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
TIM_ARRPreloadConfig(TIM4,ENABLE); //????×???×°??
TIM4_ICInitStructure.TIM_Channel = TIM_Channel_2; //CC1S=01 ????
TIM4_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling; //??????????
TIM4_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //??????TI1????????
TIM4_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //??????????·???
TIM4_ICInitStructure.TIM_ICFilter = 0x00;//IC1F=0000???????????¨?÷?????¨
TIM_ICInit(TIM4, &TIM4_ICInitStructure);
/* Enable the TIM3 gloabal Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* TIM Interrupts enable */
// TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
TIM_ITConfig(TIM4, TIM_IT_CC2, ENABLE);
/* TIM3 enable counter */
TIM_Cmd(TIM4, ENABLE);
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>