2个回答
展开全部
前提.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我
你需要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我
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
看看你程序,是不是唤醒后又继续待机了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询