在程序中加入定时器,在特定的地方调用TIM_Cmd(TIM3, ENABLE); 开启定时器,但是SR寄存器会置位产生中断标志,从而进入中断服务函数。单步调试发现,程序到TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);这一句的时候,SR的值会变成1,相当于产生中断!
void TIM3_Int_Init(u16 arr,u16 psc)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
TIM_TimeBaseStructure.TIM_Period = arr;
TIM_TimeBaseStructure.TIM_Prescaler =psc;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_ITConfig( TIM3, TIM_IT_Update ,DISABLE);
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_Cmd(TIM3, DISABLE);
}
void TIM3_IRQHandler(void) //TIM3?D??
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update );
system_info = SYS_EVENT_ERR_SUCCESS;
}
}
[img]file:///C:UsersAdministrator.9WFVB53RQT5LQSLDocumentsTencent Files530807798ImageGroup{2%~OYREEJO`{GZJ%A)[T6F.png[/img]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
谢谢你哈!问题解决了!
一周热门 更多>