STM32的停机模式与唤醒

发布时间:2020-07-23 23:56:20 作者:dawn0919
来源:网络 阅读:1005

主函数内容:
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_DMA_Init();
MX_ADC_Init();
MX_LPUART1_UART_Init();
MX_USART1_UART_Init();
MX_RTC_Init();
WorkFinished=0;//工作没有完成
while(1)
{
LED1_ON; LED2_ON; LED3_ON;HAL_Delay (500);
printf ("Before Stop \r\n");
if(WorkFinished){
HAL_PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);//进入停止模式
}
LED1_OFF; LED2_OFF; LED3_OFF;
printf ("After Stop \r\n");
}

//用于停机模式的声明
#define PWR_Regulator_LowPower ((uint32_t)0x00000001)
#define PWR_STOPEntry_WFI ((uint8_t)0x01)

//系统的停机函数
void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
{
uint32_t tmpreg = 0U;
/ Check the parameters /
assert_param(IS_PWR_REGULATOR(Regulator));
assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
/ Select the regulator state in Stop mode ---------------------------------/
tmpreg = PWR->CR;
/ Clear PDDS and LPDS bits /
CLEAR_BIT(tmpreg, (PWR_CR_PDDS | PWR_CR_LPSDSR));
/ Set LPSDSR bit according to PWR_Regulator value /
SET_BIT(tmpreg, Regulator);
/ Store the new value /
PWR->CR = tmpreg;
/ Set SLEEPDEEP bit of Cortex System Control Register /
SET_BIT(SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);
/ Select Stop mode entry --------------------------------------------------/
if(STOPEntry == PWR_STOPENTRY_WFI)
{
/ Request Wait For Interrupt /
WFI();
}
else
{
/ Request Wait For Event /
SEV();
WFE();
WFE();
}
/ Reset SLEEPDEEP bit of Cortex System Control Register /
CLEAR_BIT(SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);
}

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
WorkFinished=~WorkFinished;
SystemClock_Config();
printf ("Callback \r\n"); //外设中断 打印
}

程序正常启动后三个灯闪烁(PB12|PB13|PB14),按键后进入停机模式,再按键程序继续执行,再按键停机。
停机模式下耗电:148uA。

推荐阅读:
  1. 批量设置nagios的计划停机
  2. STM32的待机与按键(闹钟)唤醒试验

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

stm32 c st 唤醒

上一篇:AccessibilityServiceInfo

下一篇:Overview of the Architecture of ADO.NET

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》