TIM_ICInitTypeDef TIM5_ICInitStructure;
void TIM5_CH1_Cap_Init(u32 arr,u16 psc)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5,ENABLE); //
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); //
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; //
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //
//GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; //
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA,&GPIO_InitStructure); //??????PA0
//GPIO_PinAFConfig(GPIOA,GPIO_PinSource0,GPIO_AF_TIM5);
TIM_TimeBaseStructure.TIM_Prescaler=psc;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period=arr;
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM5,&TIM_TimeBaseStructure);
NVIC_InitStructure.NVIC_IRQChannel = TIM5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;//
NVIC_InitStructure.NVIC_IRQChannelSubPriority =0; //
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure); //
TIM5_ICInitStructure.TIM_Channel = TIM_Channel_2; //
TIM5_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //
TIM5_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //
TIM5_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //
TIM5_ICInitStructure.TIM_ICFilter = 0x00;//
// TIM_ICInit(TIM5, &TIM5_ICInitStructure);
TIM_PWMIConfig(TIM5, &TIM5_ICInitStructure); //
TIM_SelectInputTrigger(TIM5, TIM_TS_TI2FP2); //
TIM_SelectSlaveMode(TIM5, TIM_SlaveMode_Reset); //
TIM_SelectMasterSlaveMode(TIM5, TIM_MasterSlaveMode_Enable);
TIM_ITConfig(TIM5,TIM_IT_Update|TIM_IT_CC2,ENABLE);//
TIM_ClearITPendingBit(TIM5, TIM_IT_CC2|TIM_IT_Update); //
TIM_Cmd(TIM5,ENABLE ); //
}
我是参考这个帖子写的。
http://www.openedv.com/posts/list/23218.htm
不知道stm32103与stm32407配置有什么不同啊?我修改成stm32407的程序不能用T^T串口打印出来的是0?
想问下各位大神知不知道有可能是什么问题啊???
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>