谢谢大家的热情关心,代码如下:
/* 进入低功耗模式 */
void mcu_pwr_enter_stop_mode_set( U8 cSleepTime )
{
/* Alarm after 400 ms, interrupt every 200ms */
RTC_SetAlarm( RTC_GetCounter()+ cSleepTime );
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
/* Enable the alarm interrupt */
RTC_ITConfig( RTC_IT_ALR, ENABLE );
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
ADC_Cmd(ADC1, DISABLE);
DAC_Cmd(DAC_CH_1, DISABLE);
DAC_Cmd(DAC_CH_2, DISABLE);
/* DEBUG_MCU_STOP */
//DBGMCU->CR &= ~0x00000002;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_ALL, DISABLE );
RCC_APB1PeriphClockCmd( RCC_APB1Periph_ALL, DISABLE);
RCC_APB1PeriphClockCmd( RCC_APB1Periph_BKP | RCC_APB1Periph_PWR, ENABLE );
FLASH_PrefetchBufferCmd( FLASH_PrefetchBuffer_Disable);
PWR_EnterSTOPMode( PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
}
退出时的操作:
void mcu_from_stop_mode( void )
{
/* Enable HSE */
RCC_HSEConfig( RCC_HSE_ON);
/* Wait till HSE is ready */
if( RCC_WaitForHSEStartUp() == SUCCESS )
{
/* Re-Enable Prefetch Buffer*/
FLASH_PrefetchBufferCmd( FLASH_PrefetchBuffer_Enable);
/* 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 )
{
;
}
/* disable HSI and clock-safe-system */
*(VU32 *) CR_HSION_BB = (U32)0;
*(VU32 *) CR_CSSON_BB = (U32)0;
ADC_Cmd( ADC1, ENABLE );
DAC_Cmd(DAC_CH_1, ENABLE );
DAC_Cmd(DAC_CH_2, ENABLE );
/* disable RTC and its clock source--LSI */
RCC_LSICmd( DISABLE );
RCC_RTCCLKCmd( DISABLE );
RCC_APB1PeriphClockCmd( RCC_APB1Periph_BKP| RCC_APB1Periph_PWR, DISABLE );
/* disable DEBUG_MCU_STOP */
//DBGMCU->CR |= ~0x00000002;
}
} |