打印

STM32F407主频超到536M是的问题?

[复制链接]
264|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
石头张|  楼主 | 2018-7-29 16:28 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
用STM32F407的定时器3定时500ms,在定时器3中断服务程序中,让IO口状态反转,通过示波器来测试定时器的定时时间是否准确。发现在程序中设置定时500ms,结构示波器显示1.29us,于是调用 RCC_GetClocksFreq()函数查看系统主频,发现主频是536M多。不知道什么原因?大家帮忙看看,下面是我的代码:
void GPIO_Config(void)
{

        GPIO_InitTypeDef GPIO_InitStructure ;
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOI|RCC_AHB1Periph_GPIOF|RCC_AHB1Periph_GPIOC,ENABLE);
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10|GPIO_Pin_8;
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz;
        GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL;
        GPIO_Init(GPIOI,&GPIO_InitStructure);
}



RCC_ClocksTypeDef* RCC_Clocks;

int main(void)
{
        

        GPIO_Config();
        bsp_Time3_Init(5000-1,8400-1);//定时500ms

        while(1)
        {         

                RCC_GetClocksFreq(RCC_Clocks);   
        }

}


void bsp_Time3_Init(uint32_t arr,uint32_t psc)
{
        /*定义定时器结构体*/
        TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
        /*使能定时器的时钟*/
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);      
        /*参数设置*/
        TIM_TimeBaseInitStructure.TIM_Period = arr; //设置自动重载计数周期值        
        TIM_TimeBaseInitStructure.TIM_Prescaler = psc; //设置分频系数
        TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up; //向上计数模式
        TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1; //设置时钟分频因子
        TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0x0000;                /* TIM1 和 TIM8 必须设置 */        
        /*初始化定时器结构体*/
        TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStructure);  
        /*配置定时器3中断*/
        Time3_NVIC_Configuration();
        /*允许定时器更新中断*/
        TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);

        TIM_ARRPreloadConfig(TIM3, ENABLE);
        /*定时器使能*/
        TIM_Cmd(TIM3,ENABLE);

}


uint8_t ledflag2=0;
void TIM3_IRQHandler(void)
{
        

        if(TIM_GetITStatus(TIM3,TIM_IT_Update) != RESET)
        {

                 ledflag2 = ~ledflag2;
                 if(ledflag2 ==0x00)
                 {
                    GPIOI->BSRRL = GPIO_Pin_8;

                 }
                 else
                 {
                    GPIOI->BSRRH = GPIO_Pin_8;
                 }
        }
        /*清除中断表示位*/
        TIM_ClearITPendingBit(TIM3,TIM_FLAG_Break);

}


调试结果如下:
主频 :536887720
定时时间:1.27us

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

446

主题

446

帖子

0

粉丝