/* Set PLL clock output to 72MHz using HSE (8MHz) as entry clock */
//上面这句例程中缺失了,但却很关键
/* 利用锁相环讲外部8Mhz晶振9倍频到72Mhz */
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
/* Enable PLL 使能锁相环*/
RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready 等待锁相环输出稳定*/
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{}
/* Select PLL as system clock source 将锁相环输出设置为系统时钟 */
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source 等待校验成功*/
while (RCC_GetSYSCLKSource() != 0x08)
{}
}
{
ErrorStatus HSEStartUpStatus;
RCC_DeInit(); /* 重置了RCC的设置,类似寄存器复位 */
RCC_HSEConfig(RCC_HSE_ON); /* 使能外部高速晶振 */
HSEStartUpStatus = RCC_WaitForHSEStartUp();/* 等待高速晶振稳定 */
if (HSEStartUpStatus == SUCCESS)
{
/* 使能flash预读取缓冲区 */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* 令Flash处于等待状态,2是针对高频时钟的,这两句跟RCC没直接关系,可以暂且略过 */
FLASH_SetLatency(FLASH_Latency_2);
/* HCLK = SYSCLK 设置高速总线时钟=系统时钟*/
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK 设置低速总线2时钟=高速总线时钟*/
RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK/2 设置低速总线1的时钟=高速时钟的二分频*/
RCC_PCLK1Config(RCC_HCLK_Div2);
/* ADCCLK = PCLK2/6 设置ADC外设时钟=低速总线2时钟的六分频*/
RCC_ADCCLKConfig(RCC_PCLK2_Div6);
/* Set PLL clock output to 72MHz using HSE (8MHz) as entry clock */
//上面这句例程中缺失了,但却很关键
/* 利用锁相环讲外部8Mhz晶振9倍频到72Mhz */
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
/* Enable PLL 使能锁相环*/
RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready 等待锁相环输出稳定*/
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{}
/* Select PLL as system clock source 将锁相环输出设置为系统时钟 */
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source 等待校验成功*/
while (RCC_GetSYSCLKSource() != 0x08)
{}
}
/* ADCCLK = PCLK2/4 */
RCC_ADCCLKConfig(RCC_PCLK2_Div4);
/* Enable peripheral clocks ------------------------------------------------*/
/* Enable DMA1 clocks */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
/* Enable ADC1, ADC2, ADC3 and GPIOC clocks */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOC |
RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1 |
RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
}[/mw_shl_code]
一周热门 更多>