找了一下,我这边只有以前测试用的《待机模式》 和《停止模式》的代码。
将就的参考下吧,年代比较久远了。呵呵
/**
******************************************************************************
* [url=home.php?mod=space&uid=288409]@file[/url] /PWR_STANDBY.h
* [url=home.php?mod=space&uid=187600]@author[/url] xd.wu
* [url=home.php?mod=space&uid=895143]@version[/url] V1.0
* [url=home.php?mod=space&uid=212281]@date[/url] 2012-4-19
* [url=home.php?mod=space&uid=247401]@brief[/url] PWR:待机模式
WFE事件 新来的中断、之前悬起的中断等(比较容易唤醒)
WFI中断
******************************************************************************
*用途:
3.待机模式:可实现系统的最低功耗
进入:
设置CM3系中的SLEEPDEEP位 , PWR_CR中设置PDDS位 , CWUF位
然后执行WFI(等待中断)或WFE(等待事件)指令
唤醒:WKUP引脚的上升沿、RTC闹钟事件、NRST引脚上的外部复位、IWDG复位
唤醒延时:复位阶段时电压调节器的启动
SCB->SCR[4:0] == SEVONPEND,0,SLEEPDEEP,SLEEPONEXIT,0
*/
/*实例应用步骤:
//1."main.cpp"调用fmain()
//2."stm32f10x_it.cpp"拷贝
void SysTick_Handler(void)
{
#if defined __PWR_STANDBY
GPIO_WriteBit(GPIOF, GPIO_Pin_6, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOF, GPIO_Pin_6)));
#endif
}
void EXTI15_10_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line11) != RESET)
{
#if defined __PWR_STANDBY
GPIO_SetBits(GPIOF, GPIO_Pin_6);
RTC_ClearFlag(RTC_FLAG_SEC);
while(RTC_GetFlagStatus(RTC_FLAG_SEC) == RESET);// Wait till RTC Second event occurs
RTC_SetAlarm(RTC_GetCounter()+ 3);// Set the RTC Alarm after 3s
RTC_WaitForLastTask();
//PWR_EnterSTANDBYMode();
SCB->SCR |= 0x00000004;//SLEEPDEEP = 1
PWR->CR |= 0x006;//PWR_CR中设置PDDS位 , CWUF位
__WFE();
#endif
EXTI_ClearITPendingBit(EXTI_Line11);
}
}
//3."stm32f10x_it.h"声明
#define __PWR_STANDBY
void EXTI15_10_IRQHandler(void);
void SysTick_Handler(void);
//4.Watch中观察
LED绿灯闪烁
按下Sel后进入待机模式,3s后RTC闹钟唤醒,黄灯点亮
*/
#ifndef __PWR_STANDBY_H
#define __PWR_STANDBY_H
/* Includes ------------------------------------------------------------------*/
#include "std32periph.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define GPIO_LED GPIOF
#define RCC_LED RCC_APB2Periph_GPIOF
#define RCC_EXTI RCC_APB2Periph_GPIOB
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
void RTC_Configuration(void)
{
if(PWR_GetFlagStatus(PWR_FLAG_SB) != RESET)/* System resumed from STANDBY mode */
{
GPIO_SetBits(GPIO_LED, GPIO_Pin_7);
/* Clear StandBy flag */
PWR_ClearFlag(PWR_FLAG_SB);
RTC_WaitForSynchro();
}
else
{
/* StandBy flag is not set */
/* RTC clock source configuration ----------------------------------------*/
BKP_DeInit();
RCC_LSEConfig(RCC_LSE_ON);
while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
{
}
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
RCC_RTCCLKCmd(ENABLE);
/* RTC configuration -----------------------------------------------------*/
RTC_WaitForSynchro();
/* Set the RTC time base to 1s */
RTC_SetPrescaler(32767);
RTC_WaitForLastTask();
}
}
void fmain(void)
{
RCC_HSEConf(9);//72M
RCC_APB2PeriphClockCmd(RCC_EXTI | RCC_LED | RCC_APB2Periph_AFIO, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIO_LED, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_SetBits(GPIO_LED, GPIO_Pin_6);
/* Enable PWR and BKP clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
/* Enable WKUP pin */
PWR_WakeUpPinCmd(ENABLE);
/* Allow access to BKP Domain */
PWR_BackupAccessCmd(ENABLE);
/* Configure RTC clock source and prescaler */
RTC_Configuration();
/* Configure EXTI Line to generate an interrupt on falling edge */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource11);
EXTI_InitTypeDef EXTI_InitStructure;
EXTI_InitStructure.EXTI_Line = EXTI_Line11;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_GroupSet(NVIC_PriorityGroup_0, EXTI15_10_IRQn, 1);
/* Configure SysTick to generate an interrupt each 250ms */
SysTick->LOAD = 250000*9;
SysTick->VAL = 0x00;//清空计数器
/* ---------------------------------------------------------------------
SysTick 控制与状态寄存器的位
SysTick->CTRL: CountFlag【16】,CLKSource【2】,TickINT【1】,ENABLE【0】
--------------------------------------------------------------------- */
//CLKSource【2】=0 使用外部时钟源HCLK(1:内核时钟HCLK/8)
// TickINT【1】=0 向下计数至0,不会挂起Systick(1:至0会挂起Systick)
// ENABLE【0】=0 禁止计数器(1:使能,至0将CountFlag置1)
SysTick->CTRL = 0x00003;
}
#endif
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
|