NUCLEO-L053R8:低功耗待机模式standby/PA0唤醒(例程分享)# j/ I8 M" z$ S* Q- Y" G! `3 M 待机模式唤醒后等同复位 基于ST官方NUCLEO-L053R8开发板 用PA0引脚唤醒(用杜邦线接高电平唤醒) 代码下载:见附件 standby mode without RTC:0.29uA VDD=3.0V /**! o/ |; f( n( ~" U4 L% k6 j; I * @brief Main program q; A, A: G: E$ {1 r * @param None * @retval None */ X7 ?0 m! z& n' s$ b- l3 W int main(void)1 ?0 x! M: X8 l! P x/ ]5 W, | { /* STM32L0xx HAL library initialization: - Configure the Flash prefetch, Flash preread and Buffer caches - Systick timer is configured by default as source of time base, but user ( E; b+ h/ g2 A. z can eventually implement his proper time base source (a general purpose / Y- ^8 e: F; k: d8 T# m" R$ D timer for example or other time source), keeping in mind that Time base / e# m. o" m3 h! b duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and & f" o, L7 f7 o, e handled in milliseconds basis.( H6 e4 Z4 X9 F/ T8 c; U& K - Low Level Initialization# h/ Y6 H& o" l9 I }2 K/ Y/ D. U8 S Q */* u2 {4 b0 K/ m% d1 i HAL_Init(); /* Configure LED2 */ I8 u, Q. I( s/ P& v9 h6 E. x( f BSP_LED_Init(LED2); c1 [8 y+ A$ ?$ @- T2 W9 F/ W2 a0 r /* Configure the system clock to 2 MHz */7 S( S, F3 w. w5 y7 F SystemClock_Config(); / P* p% s! i. T. ~' g3 |7 e9 k /* Check and handle if the system was resumed from Standby mode */ $ c! Y! C+ S; l8 L* ~6 `, J% w if(__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)$ \2 T. U7 A# W. q- t { /* Clear Standby flag */ __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);8 A$ O$ s3 N4 T. K* I! T/ N% b9 o9 b: p //如果是唤醒状态,则LED亮3秒 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET); //点亮LED,延时3S,再灭LED HAL_Delay(3000); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET); }7 p* G& q, X) w5 @% C$ p- t else; ' s' P& a, T' B9 r9 | /* Configure the system Power */ SystemPower_Config(); /* Insert 1 seconds delay */7 }( e f! A0 o/ ^* @5 l) t5 t HAL_Delay(1000);$ j( T4 J! R% @. [1 ]3 f3 p# ^ % R( {- K- e3 l" Q- V" y+ d( ~, s /*The Following Wakeup sequence is highly recommended prior to each Standby mode entry3 S# k3 _( n9 h4 O; i8 D mainly when using more than one wakeup source this is to not miss any wakeup event.. c5 p; d- Q% Q, v - Disable all used wakeup sources,0 t4 g3 \; x6 l& I+ u - Clear all related wakeup flags, 0 v" g( b0 }+ w; }4 \( {; T7 A - Re-enable all used wakeup sources, - Enter the Standby mode. */% d" n# X0 S5 E3 \! o* t \ /*Disable all used wakeup sources: Pin1(PA.0)*/: I/ e7 H$ M; L3 R) @% m HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);* I7 C1 Y) V6 o& T) t /*Clear all related wakeup flags*/ __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);3 m9 l: g* @# ~ 2 U9 j% Y5 J+ j2 O /*Re-enable all used wakeup sources: Pin1(PA.0)*/ HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1); 7 V5 S5 e1 t% C* [! r% z$ Z /*Enter the Standby mode*/ HAL_PWR_EnterSTANDBYMode(); 1 ]8 j6 B \5 d3 @$ R( m- d( ? while (1)8 C& k& j( m6 W( Q& X! R" \% B {6 F( o( [1 c' Z4 u4 ^! q }' { H3 D8 j1 H( F } |
PWR_STANDBY.rar
下载4.04 MB, 下载次数: 28
谢楼上支持
谢楼上支持
学习学习