最近两天在做外部计数,用的芯片stm32f107,希望采集100K~500K频率,之前没做过,网上好多例子只有部分代码没有说明,很郁闷。话不多说,这个程序总是不能出来数据。使用PA.0引脚来采集,用串口2,PA02 PA03输出信息,不知道哪里错了,希望大神能指正,最好能详细点,感激不尽
int main(void)
{
u16 i_Loop;
int n=0;
RCC_Configuration(); // System Clocks Configuration
NVIC_Configuration(); // NVIC configuration
GPIO_Configuration(); // Configure the GPIO ports
USART1_Config();
Tim2_config();
while (1)
{
for(i_Loop = 0; i_Loop < 100; i_Loop ++)
{
n = IC2Value;
GPIO_SetBits(GPIOB, GPIO_Pin_0);
Delay(10);
GPIO_ResetBits(GPIOB, GPIO_Pin_0);
Delay(10);
printf(" %d \n",n);
}
}
}
void Tim2_config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
//--------------设置------------------------
TIM_DeInit(TIM2);
// Time base configuration
TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
TIM_TimeBaseStructure.TIM_Prescaler = 0x00;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
//TIM_TimeBaseStructure.TIM_channel = TIM_Channel_1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_ETRClockMode2Config(TIM2, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_NonInverted, 0);
//--------------测试---------------------------------------
TIM_SetCounter(TIM2, 0);
TIM_Cmd(TIM2, ENABLE);
}
|