STM32F107定時(shí)器4用作外部計(jì)數(shù)器的配置方法
掃描二維碼
隨時(shí)隨地手機(jī)看文章
不用配置引腳為輸入模式,TIM_TIxExternalCLK1Source_TI2為PB7引腳
void TIM4_Init(void)
{
TIM_TimeBaseInitTypeDefTIM_TimeBaseStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
TIM_TimeBaseStructure.TIM_Period = 0xffff;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
TIM_TIxExternalClockConfig(TIM4,TIM_TIxExternalCLK1Source_TI2,TIM_ICPolarity_Rising,0);
TIM_SetCounter(TIM4, 0);
TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
//打開溢出中斷
// TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM4, ENABLE);//計(jì)數(shù)器使能,開始工作
//NVIC_TIM4Configuration();
}