//¶¨ê±Æ÷5í¨μà1êäèë2¶»ñÅäÖÃ
//arr£o×Ô¶ˉÖØ×°Öμ(TIM2,TIM5êÇ32λμÄ!!)
//psc£oê±ÖóÔ¤·ÖÆμêy
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); //TIM5ê±Öóê1Äü
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); //ê1ÄüPORTAê±Öó
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //GPIOA0
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//¸′óÃ1|Äü
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //Ëù¶è100MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //íÆíì¸′óÃêä3ö
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; //ÏÂà-
GPIO_Init(GPIOA,&GPIO_InitStructure); //3õê¼»ˉPA0
GPIO_PinAFConfig(GPIOA,GPIO_PinSource0,GPIO_AF_TIM5); //PA0¸′óÃ붨ê±Æ÷5
TIM_TimeBaseStructure.TIM_Prescaler=psc; //¶¨ê±Æ÷·ÖÆμ
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //ÏòéϼÆêyÄ£ê½
TIM_TimeBaseStructure.TIM_Period=arr; //×Ô¶ˉÖØ×°ÔØÖμ
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM5,&TIM_TimeBaseStructure);
//3õê¼»ˉTIM5êäèë2¶»ñ2Îêy
TIM5_ICInitStructure.TIM_Channel = TIM_Channel_1; //CC1S=01 Ñ¡Ôñêäèë¶Ë IC1ó3éäμ½TI1éÏ
TIM5_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //éÏéyÑØ2¶»ñ
TIM5_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //ó3éäμ½TI1éÏ
TIM5_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //ÅäÖÃêäèë·ÖÆμ,2»·ÖÆμ
TIM5_ICInitStructure.TIM_ICFilter = 0x00;//IC1F=0000 ÅäÖÃêäèëÂË2¨Æ÷ 2»ÂË2¨
TIM_ICInit(TIM5, &TIM5_ICInitStructure);
TIM_ITConfig(TIM5,TIM_IT_Update|TIM_IT_CC1,ENABLE);//ÔêDí¸üDÂÖD¶Ï ,ÔêDíCC1IE2¶»ñÖD¶Ï
TIM_Cmd(TIM5,ENABLE ); //ê1Äü¶¨ê±Æ÷5
NVIC_InitStructure.NVIC_IRQChannel = TIM5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;//ÇàÕ¼óÅÏ輶3
NVIC_InitStructure.NVIC_IRQChannelSubPriority =0; //×óóÅÏ輶3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQí¨μàê1Äü
NVIC_Init(&NVIC_InitStructure); //¸ù¾YÖ¸¶¨μÄ2Îêy3õê¼»ˉVIC¼Ä′æÆ÷¡¢
}
这是原子哥的定时器捕获的库函数代码中定时器的初始化,我理解A0被映射为定时器的输入捕获通道,但是A0的初始化中
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //íÆíì¸′óÃêä3ö
这行代码设置为推挽输出了,不懂是为什么,请教各位大神
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
我在手册上看到IO配置的是复用功能推挽,是在stm32F407内部会自己选择时输入还是输出吗?
一周热门 更多>