|
NUCLEO-L053R8:低功耗待机模式standby/PA0唤醒(例程分享) 待机模式唤醒后等同复位 基于ST官方NUCLEO-L053R8开发板 用PA0引脚唤醒(用杜邦线接高电平唤醒) 代码下载:见附件 standby mode without RTC:0.29uA VDD=3.0V /** * @brief Main program * @param None * @retval None */ int main(void)% A Y; f! C7 k. n: [/ G$ o { " }3 f0 V" r# Y* ~% X( y9 ^- q /* STM32L0xx HAL library initialization:# M) @5 ^- {+ o$ e) @* ` - Configure the Flash prefetch, Flash preread and Buffer caches - Systick timer is configured by default as source of time base, but user 8 z# b+ ^/ Y$ ~% Z+ J9 d( l- d* V4 k can eventually implement his proper time base source (a general purpose . ?! X' I+ Q$ y3 [+ @2 T8 a" { 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 ' D6 s' S& Z0 x+ d" i# B handled in milliseconds basis. - Low Level Initialization% u: p* y; q, \& o */ HAL_Init(); 5 j9 w7 a' |5 x4 V /* Configure LED2 */, E9 H/ P$ S( y BSP_LED_Init(LED2); ' N9 ~5 s( z. Y" b1 S8 z /* Configure the system clock to 2 MHz */ SystemClock_Config();; p: S% [( K, U /* Check and handle if the system was resumed from Standby mode */ - V' o9 O5 C0 I$ o9 T; R0 ~ if(__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET) {& \, M: v/ c! ^4 l( c /* Clear Standby flag */ __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB); ' o- S5 }4 {6 x //如果是唤醒状态,则LED亮3秒 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET); //点亮LED,延时3S,再灭LED+ @& O' x% W# v/ [ HAL_Delay(3000); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);2 x5 e( q4 ]$ w j$ ~ } else; - \% B5 @1 a+ m/ Q$ M1 h /* Configure the system Power */ SystemPower_Config();: V3 A# }) }& V& }9 ^/ A6 m$ x 7 r/ F1 K+ X* P0 l& j) U+ A /* Insert 1 seconds delay */ HAL_Delay(1000);. H* t) g, x3 [9 \ . j: ~. Q1 I: c/ V+ a9 ] /*The Following Wakeup sequence is highly recommended prior to each Standby mode entry# p/ a1 J* a2 Z! ~ mainly 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, # E0 r6 ?# [: c - Re-enable all used wakeup sources, - Enter the Standby mode.2 u# s) [# y' @5 M0 X5 u */ /*Disable all used wakeup sources: Pin1(PA.0)*/ o+ ~9 N$ _9 l+ X HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1); 7 q* d7 {3 n5 q4 h /*Clear all related wakeup flags*/ __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);* ?% U0 }5 F0 d, I7 B( p1 ^ /*Re-enable all used wakeup sources: Pin1(PA.0)*/ HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);2 w3 c$ v+ E5 w - E6 y) K: Q1 Y" N: d /*Enter the Standby mode*/( B; I' E, }9 \ b. y1 r HAL_PWR_EnterSTANDBYMode(); $ w7 I, c$ \7 I while (1)- t/ o8 r$ {/ N) p4 H, A% e8 m {, Z! _; t4 T! N% } } }
|
PWR_STANDBY.rar
下载4.04 MB, 下载次数: 28
微信公众号
手机版
谢楼上支持
谢楼上支持
学习学习