今天莫名其妙的在STM32F401 NUCLEO板子上折腾了一天通用定时器的配置,一直没有成功运行。
刚刚试着将代码改换到STM32F407 DISCO板子上运行,却意外地运行成功了。(LED闪烁)
两块板子的区别只在于 前者使用内部晶振,后者使用外部晶振。
程序是用来测试的所以没有注释,应该也容易看懂
有空的帮我看看什么情况吧。
int main(void)
{
RCC_ClocksTypeDef MyClock;
SystemCoreClockSetHSI();
RCC_GetClocksFreq (&MyClock);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2 );
Btn_EXTI_Init();
// USART1_Init();
LED_GPIO_Init ();
LED_OFF ();
TIM3_Config();
while(1)
{
// /* Toggle LED */
// LED_Toggle();
}
return 0;
}
void TIM3_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure .NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure .NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure .NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure .NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
RCC_APB1PeriphClockCmd (RCC_APB1Periph_TIM3 ,ENABLE);
TIM_DeInit(TIM3);
TIM_TimeBaseStructure .TIM_Period = 1000-1; //1000*1ms = 1s
TIM_TimeBaseStructure .TIM_Prescaler = 24000; //1KHz -- 1ms
TIM_TimeBaseStructure .TIM_CounterMode = TIM_CounterMode_Up ;
TIM_TimeBaseStructure .TIM_ClockDivision = TIM_CKD_DIV1 ;
TIM_TimeBaseInit (TIM3,&TIM_TimeBaseStructure);
TIM_ClearFlag (TIM3,TIM_FLAG_Update);
TIM_ITConfig (TIM3,TIM_IT_Update ,ENABLE);
TIM_Cmd (TIM3,ENABLE);
}
void TIM3_IRQHanlder(void)
{
if(TIM_GetITStatus(TIM3,TIM_IT_Update ) != RESET )
{
TIM_ClearITPendingBit(TIM3,TIM_IT_Update);
LED_Toggle ();
}
}
帮我看看是哪里疏忽了
|