[mw_shl_code=c,true]void TIM3_Init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
TIM_TimeBaseStructure.TIM_Period=5000;
TIM_TimeBaseStructure.TIM_Prescaler=8399;
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure);
TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);
TIM_Cmd(TIM3,ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //?ü??????
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //??????????0
NVIC_InitStructure.NVIC_IRQChannelSubPriority =1; //?ì????????1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //???í????
NVIC_Init(&NVIC_InitStructure);
}[/mw_shl_code]
[mw_shl_code=c,true]void TIM3_IRQHandler(void)
{
if(TIM_GetITStatus(TIM3,TIM_IT_Update)!=RESET) //????????
{
//USART_handler();
}
TIM_ClearITPendingBit(TIM3,TIM_IT_Update); //????????±ê????
}[/mw_shl_code]
[mw_shl_code=c,true]int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
// gpio_init();
TIM3_Init();
while(1)
{
;
}
}[/mw_shl_code]
定时器的配置、中断服务函数和主函数如上,程序能进入定时器中断服务函数,但是过一会儿必定进入hardfalut_handler里面,想请教一下大概会是什么原因?(用过外部中断、串口接收中断都没出错)谢谢!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>