stm32 唤醒后配置什么
1个回答
2014-02-27
展开全部
Hi 大家,
这几天在调试stm32的低功耗,采用rtc的alarm唤醒,在唤醒之前所用的外设有uart,TIM2.当唤醒之后,首先我从新配置了时钟:代码
ErrorStatus HSEStartUpStatus;
//turn on HSE
RCC_HSEConfig(RCC_HSE_ON);
//Wait till HSE is ready and if Time out is reached exit
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
{
/* Enable Prefetch Buffer */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* Flash 2 wait state */
FLASH_SetLatency(FLASH_Latency_2);
/* HCLK = SYSCLK */
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK */
RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK/2 */
RCC_PCLK1Config(RCC_HCLK_Div2);
/* PLLCLK = 8MHz * 9 = 72 MHz */
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)
{}
}
这段代码应该没问题,以防万一,先贴出来。
这几天在调试stm32的低功耗,采用rtc的alarm唤醒,在唤醒之前所用的外设有uart,TIM2.当唤醒之后,首先我从新配置了时钟:代码
ErrorStatus HSEStartUpStatus;
//turn on HSE
RCC_HSEConfig(RCC_HSE_ON);
//Wait till HSE is ready and if Time out is reached exit
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
{
/* Enable Prefetch Buffer */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* Flash 2 wait state */
FLASH_SetLatency(FLASH_Latency_2);
/* HCLK = SYSCLK */
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK */
RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK/2 */
RCC_PCLK1Config(RCC_HCLK_Div2);
/* PLLCLK = 8MHz * 9 = 72 MHz */
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)
{}
}
这段代码应该没问题,以防万一,先贴出来。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询