当前位置: 首页> 房产> 建材 > STM32待机休眠指令设置

STM32待机休眠指令设置

时间:2025/7/15 2:29:35来源:https://blog.csdn.net/jacklood/article/details/139063086 浏览次数:0次

1、如果使用STM32单片机需要在不工作的时候进入待机休眠模式,通过查询STM32的数据手册,可以通过几个指令语句设置先关的寄存器即可。当按键按下的时候,取消待机休眠模式,进入正常工作的状态。

2、具体测试程序代码如下:

int main(void)
{/* STM32F103xB HAL library initialization:- Configure the Flash prefetch- Systick timer is configured by default as source of time base, but user can eventually implement his proper time base source (a general purpose timer for example or other time source), keeping in mind that Time base duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and handled in milliseconds basis.- Set NVIC Group Priority to 4- Low Level Initialization*/HAL_Init();/* Configure the system clock to 64 MHz */SystemClock_Config();/* Configure the system Power 配置系统电源 */SystemPower_Config();/* Check and handle if the system was resumed from Standby mode 确认系统是否从待机模式恢复*/ if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET){/* Clear Standby flag 如果恢复则清楚待机标志位*/__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);}/* Insert 5 seconds delay 延时5S*/HAL_Delay(5000);/* The Following Wakeup sequence is highly recommended prior to each Standby mode entrymainly when using more than one wakeup source this is to not miss any wakeup event.- Disable all used wakeup sources,- Clear all related wakeup flags, - Re-enable all used wakeup sources,- Enter the Standby mode.*//* Disable all used wakeup sources: PWR_WAKEUP_PIN1 */HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);/* Clear all related wakeup flags*/__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);/* Enable WakeUp Pin PWR_WAKEUP_PIN1 connected to PA.00 使能PA00的唤醒功能*/HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);/* Enter the Standby mode进入待机模式 */HAL_PWR_EnterSTANDBYMode();/* This code will never be reached!如果没有进入待机模式则进入此循环 */while (1){/* Insert delay 500 ms */HAL_Delay(500);HAL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN);  //用于检测是否进入待机模式,若没进入将500ms一次闪烁LED2灯 }
}

关键字:STM32待机休眠指令设置

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: