當前位置:編程學習大全網 - 源碼下載 - 求STM32高手幫助:待機模式20s後用RTC 喚醒,這樣壹直循環。我qq:1031992594.真誠求助啊!

求STM32高手幫助:待機模式20s後用RTC 喚醒,這樣壹直循環。我qq:1031992594.真誠求助啊!

前提.standby模式只能有rtc 看門狗和外部中斷來喚醒

妳需要20s後用rtc喚醒,所以務必把看門狗關閉(standby看門狗還是工作的,否則狗到時間會喚醒MCU)

給妳寫代碼參考

/**

* @brief Main program.

* @param None

* @retval : None

*/

int main(void)

{

/* System Clocks Configuration */

/* Keep the default configuration HSI 8MHz */

/* GPIO configuration */

GPIO_Configuration();

/* Turn on led connected to PC.01 */

GPIO_SetBits(GPIOC, GPIO_Pin_1);

/* Enable PWR and BKP clock */

RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

/* Allow access to BKP Domain */

PWR_BackupAccessCmd(ENABLE);

/* Configure RTC clock source and prescaler */

RTC_Configuration();

/* Wait till RTC Second event occurs */

RTC_ClearFlag(RTC_FLAG_SEC);

while(RTC_GetFlagStatus(RTC_FLAG_SEC) == RESET);

#ifdef WKUP_20s

/* Set the RTC Alarm after 20 s ( = 327000 * 61?s) */

RTC_SetAlarm(RTC_GetCounter()+ 327000);

#else

#ifdef WKUP_200ms

/* Set the RTC Alarm after 200 ms ( = 3276 * 61?s) */

RTC_SetAlarm(RTC_GetCounter()+ 3276);

#endif

#endif

/* Configure ADC conversion mode */

ADC_Configuration();

/* ADC1 regular Software Start Conv */

ADC_SoftwareStartConvCmd(ADC1, ENABLE);

/* Test EOC flag */

while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC));

/* Read regular converted data and clear EOC Flag */

RegularConvData = ADC_GetConversionValue(ADC1);

ADC_Cmd(ADC1, DISABLE);

/* Turn on led connected to PC.01 */

GPIO_ResetBits(GPIOC, GPIO_Pin_1);

/* Wait until last write operation on RTC registers has finished */

RTC_WaitForLastTask();

/* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */

PWR_EnterSTANDBYMode();

while(1)

{

}

}

/**

* @brief Enters STANDBY mode.

* @param None

* @retval : None

*/

void PWR_EnterSTANDBYMode(void)

{

/* Clear Wake-up flag */

PWR->CR |= CR_CWUF_Set;

/* Select STANDBY mode */

PWR->CR |= CR_PDDS_Set;

/* Set SLEEPDEEP bit of Cortex System Control Register */

*(__IO uint32_t *) SCB_SysCtrl |= SysCtrl_SLEEPDEEP_Set;

/* This option is used to ensure that store operations are completed */

#if defined ( __CC_ARM )

__force_stores();

#endif

/* Request Wait For Interrupt */

__WFI();

}

看不到源碼的函數在STM32的庫可以看到,希望對妳有幫助 有問題在email我

  • 上一篇:2010年之後,有哪些不得不看的經典科幻片?
  • 下一篇:Libthread源代碼
  • copyright 2024編程學習大全網