问答

汇集网友智慧,解决技术难题

BullTalented

TA的家园币:20  

  • 为什么STM32在使用定时器中断的时候ARR的参数不能给0?

    我在使用ETR外部时钟信号时,想实现类似于外部中断的,信号来一次进入一次中断的操作。但是发现当TIM_Period参数给1-1,也就是0时,无法正常进入中断。但是将参数调整为2-1时,来两次信号又可以进入中断,请问这是为什么?uint16_tCount;voidTIM_QuicklyInit(void);intmain(void){TIM_QuicklyInit();OLED_Init();OLED_ShowString(1,1,"Counts:");while(1){OLED_ShowNum(2,1,Count,4);OLED_ShowNum(3,1,TIM_GetCounter(TIM2),1);}}voidTIM_QuicklyInit(void){RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);GPIO_InitTypeDefGPIOInitstructure;GPIOInitstructure.GPIO_Mode=GPIO_Mode_IPD;GPIOInitstructure.GPIO_Pin=GPIO_Pin_0;GPIOInitstructure.GPIO_Speed=GPIO_Speed_50MHz;GPIO_Init(GPIOA,&GPIOInitstructure);TIM_ETRClockMode2Config(TIM2,TIM_ExtTRGPSC_OFF,TIM_ExtTRGPolarity_Inverted,0x0F);TIM_TimeBaseInitTypeDefTimeInitstructure;TimeInitstructure.TIM_CounterMode=TIM_CounterMode_Up;TimeInitstructure.TIM_ClockDivision=TIM_CKD_DIV4;TimeInitstructure.TIM_Period=1-1;TimeInitstructure.TIM_Prescaler=1-1;TimeInitstructure.TIM_RepetitionCounter=0;TIM_TimeBaseInit(TIM2,&TimeInitstructure);TIM_ClearFlag(TIM2,TIM_FLAG_Update);TIM_Cmd(TIM2,ENABLE);TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);NVIC_InitTypeDefNVICInitstructure;NVICInitstructure.NVIC_IRQChannel=TIM2_IRQn;NVICInitstructure.NVIC_IRQChannelCmd=ENABLE;NVICInitstructure.NVIC_IRQChannelPreemptionPriority=2;NVICInitstructure.NVIC_IRQChannelSubPriority=2;NVIC_Init(&NVICInitstructure);}voidTIM2_IRQHandler(void){if(TIM_GetFlagStatus(TIM2,TIM_IT_Update)==SET)Count++;TIM_ClearFlag(TIM2,TI

    单片机 嵌入式 ST

    2023-09-04 8