STM32 RCC实验MCO脚输出时钟波形
2016-10-10 来源:eefocus
一:rcc设置使用内部HSI时钟,SYSclk 64M MCO输出32M
进入单片机查看更多内容>>
1:
void RCC_Configuration(void)
{
ErrorStatus HSEStartUpStatus;
/* RCC system reset(for debug purpose) */
RCC_DeInit(); //??RCC?????÷?è?????±????
/* Enable HSE */
//RCC_HSEConfig(RCC_HSE_ON); //?è???????????§??
RCC_HSEConfig(RCC_HSE_OFF);
RCC_HSICmd(ENABLE); //??????
//RCC_HSICmd(DISABLE); //??????
/* Wait till HSE is ready */ //HSE ?????????§??
//HSEStartUpStatus = RCC_WaitForHSEStartUp(); //????HSE????
while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET)
{
}
// if(HSEStartUpStatus == SUCCESS)
// {
/* HCLK = SYSCLK *///?è??AHB?±??=?????±?? ?¨RCC_SYSCLK_Div1??·?????????
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK *///?è??????APB2?±??(×??ó72MHZ)
RCC_PCLK2Config(RCC_HCLK_Div1); //RCC_HCLK_Div1 ??·?????RCC_HCLK_Div2 2·???
/* PCLK1 = HCLK/2 *///?è??????APB1?±???¨×??ó36MHZ??
RCC_PCLK1Config(RCC_HCLK_Div2);
/* Flash 2 wait state */
FLASH_SetLatency(FLASH_Latency_2);
/* Enable Prefetch Buffer */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* PLLCLK = 8MHz * 9 = 72 MHz */
//RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
//?????±????8/2=4M 4*16 = 64 hsi = 64m (MAX)
RCC_PLLConfig(RCC_PLLSource_HSI_Div2 , RCC_PLLMul_16);
/* 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)
{
}
// }
}
2:设置MCO引脚PA8
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // ×???????????50MHz
GPIO_Init(GPIOA, &GPIO_InitStructure);
注意: A8引脚使用复用推挽输出模式,我使用推挽输出的时候波形没出来,推挽输出只能输出TTL,复用推挽可以输出时钟波形
3:设置MCO模式
RCC_MCOConfig(RCC_MCO_PLLCLK_Div2); //因为端口最大50M所以要PLL 2分频
二:rcc设置使用外部HSE时钟,SYSclk 72M MCO输出36M
只要改变RCC设置即可,其他不变
相关文章