高中生
最后登录1970-1-1
在线时间 小时
注册时间2016-11-28
|
大家好,我最近用STM32F103R6,写段程序,发现只要打开定时器3,程序就运行不下去了,初始化程序如下,请各位帮忙看一下
嘀嗒初始化,频率是1000000
void ltk_systick_init(uint32_t systick_hz)
{
if (SysTick_Config(SystemCoreClock / systick_hz))
{
/* ²¶»ñ´íÎó */
while (1);
}
}
定时器3初始化
void NVIC_TIM3_Configuration(void)//¶¨Ê±Æ÷3ÖжÏÅäÖÃ
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void TIM3_Init(void)
{
//使能定时器TIM_X时钟
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
//计算要定时的时间
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
//自动装载的计数值
TIM_TimeBaseStructure.TIM_Period = (100 - 1);//(100-1)±íʾ10ms//TIM_TimeBaseStructure.TIM_Period = (10000 - 1);/////(10000 - 1)±íʾ1s
//自动分频系数
TIM_TimeBaseStructure.TIM_Prescaler =7200 ;
//数字滤波器,定时时不涉及此项
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
//计数模式设置,设为向上
TIM_TimeBaseStructure.TIM_CounterMode=0;
//定时基本设置
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);//TIM_TimeBaseInit(TIM_TypeDef* TIMx, TIM_TimeBaseInitTypeDef* TIM_TimeBaseInitStruct);
//清除定时器X的中断溢出标志
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
//开定时器溢出中断
TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);//TIM_ITConfig(TIM_TypeDef* TIMx, uint16_t TIM_IT, FunctionalState NewState);
//使能定时器
TIM_Cmd(TIM3, ENABLE);
//配置定时器中断
NVIC_TIM3_Configuration();
}//
|
|