RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Period = 0; TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; TIM2->CNT = 10; printf("TIM2->CNT:%u\n", TIM2->CNT); // 此处打印为10 TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);// 此函数的最后会触发 Update事件 printf("TIM2->CNT:%u\n", TIM2->CNT); // 此时的CNT应该清0,但是还是10
测试发现当TIM没有使能时,UE事件无法复位CNT。测试它厂同类型号没有此问题,该行为会导致TIM初始化后,CNT不被复位,而出现莫名其妙问题,麻烦确实下。
热门产品 :
CH32V317: 互联型青稞RISC-V MCU