TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
NVIC_InitTypeDef NVIC_InitStruct;
GPIO_InitTypeDef GPIO_InitStruct;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5|RCC_APB1Periph_TIM3,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_IN;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_0;
GPIO_InitStruct.GPIO_PuPd=GPIO_PuPd_DOWN;
GPIO_Init(GPIOA,&GPIO_InitStruct);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource0,GPIO_AF_TIM5);
TIM_TimeBaseInitStruct.TIM_ClockDivision=0;
TIM_TimeBaseInitStruct.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInitStruct.TIM_Period=arr;
TIM_TimeBaseInitStruct.TIM_Prescaler=psc;//1s
TIM_TimeBaseInit(TIM5,&TIM_TimeBaseInitStruct);
TIM5->CCMR1&=~3;
TIM5->CCMR1|=1<<0; //CC1S=01 Ñ¡Ôñêäèë¶Ë IC1ó3éäμ½TI1éÏ
TIM5->CCMR1&=~(0XF<<4); //IC1F=0000 ÅäÖÃêäèëÂË2¨Æ÷ 2»ÂË2¨
TIM5->CCER&=~(1<<1); //CC1P=0 éÏéyÑؼÆêy
TIM5->SMCR|=5<<4; //′¥·¢Ñ¡Ôñ:ÂË2¨oóμĶ¨ê±Æ÷êäèë1(TI1FP1)
TIM5->SMCR|=7<<0; //ía2¿ê±ÖóÄ£ê½1
TIM_TimeBaseInitStruct.TIM_ClockDivision=0;
TIM_TimeBaseInitStruct.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInitStruct.TIM_Period=59999;
TIM_TimeBaseInitStruct.TIM_Prescaler=1399;//1s
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStruct);
TIM_SelectOnePulseMode(TIM3,TIM_OPMode_Single);//μ¥Âö3åģ꽣¬μ¥ò»Âö3å
TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);//ÖD¶Ïê1Äü
NVIC_InitStruct.NVIC_IRQChannel=TIM3_IRQn;
NVIC_InitStruct.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStruct.NVIC_IRQChannelSubPriority=2;
NVIC_Init(&NVIC_InitStruct);
TIM_Cmd(TIM5,ENABLE); //Æô¶ˉ¼ÆêyÆ÷£¬CEN=1
TIM_Cmd(TIM3,ENABLE);
F4外部时钟模式还需要设置别的吗,求教
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
我之前参考了你的一篇帖子,设置在F103上是好使的,但是移植到407上就不能用了,我也是按照中文参考资料上的例子一步步设置的,但是就是没有效果,检测不到外部时钟。
要提供操作寄存器的时钟。
一周热门 更多>