本文主要是介绍STM32F103系统时钟配置,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
STM32F103系统时钟完美配置
时钟树的理解确定分频倍频之后再做
- STM32F103时钟树
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-KXW3Vwk8-1591952361435)(https://cloud.githubusercontent.com/assets/13186592/21471246/f70cdcae-cae5-11e6-982f-d94bc187c670.jpg)]
- 假设外接晶振8MHz,现在需要配置出系统72MHz时,需要
配置代码(外部晶振8MHz配置系统时钟为72MHz)
/*RCC config*/
void RCC_Configuration(void)
{RCC_DeInit(); RCC_HSEConfig(RCC_HSE_ON);while(SUCCESS != RCC_WaitForHSEStartUp()){} /*设置FLASH存储器延时时钟周期数*/FLASH_SetLatency(FLASH_Latency_2); //FLASH_Latency_2 2延时周期 /*选择FLASH预取指缓存的模式*/ FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); // 预取指缓存使能/*设置PLL时钟源及倍频系数*/ /* Fcpu = (PLL_src * PLL_MUL) = (8 Mhz / 1) * (9) = 72Mhz */ RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); /* Enable PLL */RCC_PLLCmd(ENABLE); /*检查指定的RCC标志位(PLL准备好标志)设置与否*/ while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) {}/* Set system clock dividers */RCC_HCLKConfig(RCC_SYSCLK_Div1);RCC_PCLK2Config(RCC_HCLK_Div1);RCC_PCLK1Config(RCC_HCLK_Div2);RCC_ADCCLKConfig(RCC_PCLK2_Div6); /* Embedded Flash Configuration */FLASH_SetLatency(FLASH_Latency_2); FLASH_HalfCycleAccessCmd(FLASH_HalfCycleAccess_Disable);FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);/*SYSCLK configuration*/RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
}/*NVIC config*/
void NVIC_Configuration(void)
{/* Configure and enable ADC interrupt */NVIC_SetVectorTable(NVIC_VectTab_FLASH,0);/* Configure the NVIC Preemption Priority Bits */NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
}void bsp_init(void){RCC_Configuration();NVIC_Configuration();SysTick_Config(72000); //1ms
}
这篇关于STM32F103系统时钟配置的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!