我在使用STM32F105外接8M,为了验证我的总线时钟配置,我分别用TIM1,和TIM3做了一个测试代码
void TimerTestInit(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
//NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_TimeBaseStructure.TIM_Period = 10000;
TIM_TimeBaseStructure.TIM_Prescaler =7200;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
TIM_Cmd(TIM1, ENABLE);
//tim3
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
//³õʼ»¯TIM2 (×¢£ºTIM2ʱÖÓΪ×ÜÏßʱÖÓµÄÁ½±¶£¬Ò²¾ÍÊÇ72MHz,ÏéÇé²Î¿¼STM32²Î¿¼ÊÖ²á7.2½Ú)
TIM_TimeBaseStructure.TIM_Period =10000; //ÉÏÏÞÖµ
TIM_TimeBaseStructure.TIM_Prescaler = 7200; //Ô¤·ÖƵ
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1 ; //Â˲¨Æ÷·ÖƵ
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);//ÖжÏÔÊÐí
TIM_Cmd(TIM3, ENABLE);
}
void TIM1_UP_IRQHandler(void)
{
TIM_ClearITPendingBit(TIM1, TIM_FLAG_Update);
BEEP_FLASH;
}
void TIM3_IRQHandler(void)
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
LED_FLASH;
} 观察发现TIM1的中断频率是2秒,TIM3的中断频率是1秒;我配置的APB1总线频率是36M,APB2总线频率为72M
所以TIM3的中断频率应该是正确的,就不知道TIM1的中断频率为什么只有2秒???
|