[mw_shl_code=c,true]//TIM8,PC6 PC7
RCC->APB2ENR |= 1<<1; //TIM8时钟使能
RCC->AHB1ENR |= 1<<2; //GPIOC端口时钟使能
GPIOC->MODER &= 0xFFFF0FFF; //PC6,PC7设置为复用模式
GPIOC->MODER |= 0x0000A000;
GPIOC->AFR[0] &= 0x00FFFFFF;
GPIOC->AFR[0] |= 0x33000000;
TIM8->ARR = 0xFFFF;
TIM8->PSC = 0;
TIM8->CCMR1 &= 0xFCFC; //CC1 通道配置为输入, IC1 映射到 TI1 上,CC2 通道配置为输入, IC2 映射到 TI2 上
TIM8->CCMR1 |= 0x0101;
TIM8->CCER &= 0xFFDD;
TIM8->CCMR1 &= 0x0F0F; //不滤波
TIM8->SMCR &= 0xFFF8;
TIM8->SMCR |= 0x0003;
TIM8->CR1 |= 1<<0; //使能计数器
//TIM1,PA8 PA9
RCC->APB2ENR |= 1<<0; //TIM1时钟使能
RCC->AHB1ENR |= 1<<0; //GPIOA端口时钟使能
GPIOA->MODER &= 0xFFF0FFFF; //PA8,PA9设置为复用模式
GPIOA->MODER |= 0x000A0000;
GPIOA->AFR[1] &= 0xFFFFFF00;
GPIOA->AFR[1] |= 0x00000011;
TIM1->ARR = 0xFFFF;
TIM1->PSC = 0;
TIM1->CCMR1 &= 0xFCFC; //CC1 通道配置为输入, IC1 映射到 TI1 上,CC2 通道配置为输入, IC2 映射到 TI2 上
TIM1->CCMR1 |= 0x0101;
TIM1->CCER &= 0xFFDD;
TIM1->CCMR1 &= 0x0F0F; //不滤波
TIM1->SMCR &= 0xFFF8;
TIM1->SMCR |= 0x0003;
TIM1->CR1 |= 1<<0; //使能计数器
[/mw_shl_code]
代码如上所示,TIM8是正常工作能计数的,但是TIM1无法正常计数,DIR位一直在变动。不知道是不是PA9是USART1_TX的原因,但是在初始化的时候没有初始化串口。大神求助!!!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>