STM32F103 TIMER2定时器中断问题,代码如下:[mw_shl_code=c,true]void TIM2_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 , ENABLE);
TIM_DeInit(TIM2);
TIM_TimeBaseStructure.TIM_Period=10-1;
TIM_TimeBaseStructure.TIM_Prescaler= (72 - 1);
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_ClearFlag(TIM2, TIM_FLAG_Update);
TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);
TIM_Cmd(TIM2, ENABLE);
}[/mw_shl_code]
[mw_shl_code=c,true]void TIM2_NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}[/mw_shl_code]
[mw_shl_code=applescript,true]void TIM2_IRQHandler(void)
{
u16 i;u8 Temp;
TIM_ClearITPendingBit(TIM2, TIM_FLAG_Update); //Clear Timer Interrupt
GPIO_WriteBit(GPIOB, GPIO_Pin_5, (BitAction)!GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_5));//取反[/mw_shl_code]
TIMER2中断中取反GPIOB PIN5,然后示波器发现,的确是10us一次波形,但是1.5ms间隔的时候会产生一个20us的波形,说明1.5ms时刻的10us的中断没有产生?
这有可能是什么原因,没有其他的中断源。
一周热门 更多>