void Timerx_Init(u16 arr,u16 psc)
{
RCC->APB1ENR|=1<<1;//TIM3时钟使能
TIM3->ARR=arr; //设定计数器自动重装值//刚好1ms
TIM3->PSC=psc; //预分频器7200,得到10Khz的计数时钟
RCC->APB2ENR|=1<<2;
GPIOA->CRL&=0XF0FFFFFF;
GPIOA->CRL|=0X08000000; //配置IT1输入
GPIOA->ODR|=1<<6;
RCC->APB2ENR|=1<<5;
GPIOD->CRL&=0XFFFFF0FF;
GPIOD->CRL|=0X00000800;//配置ER输入
GPIOD->ODR|=1<<2;
TIM3->SMCR&=0<<8;
TIM3->SMCR&=0<<12; //外部触发输入计数
TIM3->SMCR&=0<<15;
TIM3->SMCR|=1<<14;
TIM3->CCMR1&=0<<4;
TIM3->CCMR1|=1<<0;//TI上升沿触发定时器
TIM3->CCER&=0<<1;
TIM3->SMCR|=6<<0;//配置定时器触发模式
TIM3->SMCR|=5<<4;
TIM3->CR1|=0x01; //使能定时器3
Ex_NVIC_Config(GPIO_A,6,FTIR); //检测到TI下降沿进入中断
MY_NVIC_Init(2,2,EXTI9_5_IRQChannel,2);
}
void EXTI9_5_IRQHandler(void)
{
n=TIM3->CNT;
TIM3->CNT&=0;
printf("zhi:%d\r\n",n);
EXTI->PR=1<<2;
}
按照手册上定时器从模式:外部时钟模式2 + 触发模式,,用mini板写的,,调了那么久始终没成功,,求高人指点一下
|