我在使用ETR外部时钟信号时,想实现类似于外部中断的,信号来一次进入一次中断的操作。但是发现当TIM_Period参数给1-1,也就是0时,无法正常进入中断。但是将参数调整为2-1时,来两次信号又可以进入中断,请问这是为什么?uint16_t Count;
void TIM_QuicklyInit(void);
int main(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);
}
}
void TIM_QuicklyInit(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
GPIO_InitTypeDef GPIOInitstructure;
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_TimeBaseInitTypeDef TimeInitstructure;
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_InitTypeDef NVICInitstructure;
NVICInitstructure.NVIC_IRQChannel = TIM2_IRQn ;
NVICInitstructure.NVIC_IRQChannelCmd = ENABLE;
NVICInitstructure.NVIC_IRQChannelPreemptionPriority = 2;
NVICInitstructure.NVIC_IRQChannelSubPriority = 2;
NVIC_Init(&NVICInitstructure);
}
void TIM2_IRQHandler(void)
{
if(TIM_GetFlagStatus(TIM2,TIM_IT_Update)==SET)
Count++;
TIM_ClearFlag(TIM2,TIM_IT_Update);
}
|