NUCLEO-L053R8:低功耗STOP模式,RTC唤醒(例程分享) 基于ST官方NUCLEO-L053R8开发板 代码下载:见附件 Stop mode with RTC:1uA VDD=3.0V /*** z* L' R5 K0 O, t& H+ D5 t * @brief Main program * @param None * @retval None */ int main(void) { /* STM32L0xx HAL library initialization: - Configure the Flash prefetch, Flash preread and Buffer caches- F% d6 m& e& r8 @, w$ e - Systick timer is configured by default as source of time base, but user 8 p, { K9 i) d( j5 R can eventually implement his proper time base source (a general purpose 1 w6 L8 ~; A; P1 q" b; Y: i, J R 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 % u* x, t7 I- v0 j handled in milliseconds basis. - Low Level Initialization */ HAL_Init(); /* Configure LED2 to handle error handler */1 a3 G- }2 _2 o0 C' b BSP_LED_Init(LED2);* X" X8 N6 B7 `! Z. L. \0 W! ?+ J /* Configure the system clock @ 32 Mhz */ SystemClock_Config(); : a, q* P/ M+ f2 D /* Configure the system Power */ SystemPower_Config(); while (1) { /* Insert 3 seconds delay */1 y9 H2 P) k ] BSP_LED_Init(LED2); //LED初始化 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET); //点亮LED,延时3S,再灭LED; m7 M, Z/ _0 ]3 k1 f( }, n2 h HAL_Delay(3000);% t/ Q: X8 ?# l3 x1 S b/ \ * f0 }4 W( x: F" | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);! }" W! j& [% \: W" |& U, v HAL_Delay(3000);! {. o. N9 ]* g! }, R& { SystemPowerNORTC_Config(); //关闭所有IO和时钟,不关闭RTC5 i9 Z" P! E2 I% n1 ^1 K /* Disable Wakeup Counter *// i; ?* ~) @0 {, D HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle);9 ]3 f0 j4 b1 I. c% k; g /*## Setting the Wake up time ############################################*/ /* RTC Wakeup Interrupt Generation: x. [2 W. F; e' `0 y K6 H% Y6 e Wakeup Time Base = (RTC_WAKEUPCLOCK_RTCCLK_DIV /(LSE or LSI)) Wakeup Time = Wakeup Time Base * WakeUpCounter ; Q; x. f" J3 `) _! u: Z = (RTC_WAKEUPCLOCK_RTCCLK_DIV /(LSE or LSI)) * WakeUpCounter ==> WakeUpCounter = Wakeup Time / Wakeup Time Base To configure the wake up timer to 4s the WakeUpCounter is set to 0x1FFF:8 o; j2 y6 l* W- T RTC_WAKEUPCLOCK_RTCCLK_DIV = RTCCLK_Div16 = 16 Wakeup Time Base = 16 /(~39.000KHz) = ~0,410 ms Wakeup Time = ~4s = 0,410ms * WakeUpCounter ==> WakeUpCounter = ~4s/0,410ms = 9750 = 0x2616 */# E/ x- q- U5 {' a+ ^& C8 m$ t HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, 0x2616, RTC_WAKEUPCLOCK_RTCCLK_DIV16); . z. J9 q: W8 u9 u$ r /* Enter Stop Mode */6 j% o4 P5 Z" |) [4 d HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);% c! i3 s: \ w( g% P1 W 0 a F2 T; Y' f0 \$ e \ /* Configures system clock after wake-up from STOP: enable HSI, PLL and select& N6 n" e9 r5 K, P; F7 [4 p* B PLL as system clock source (HSI and PLL are disabled automatically in STOP mode) */% g* z* D$ R5 F4 U, V$ l% M SystemClockConfig_STOP(); }: S/ R6 H- ^* T% a0 x1 c }: u5 r" Y7 f, n" Y( A! \ |
PWR_STOP_RTC.rar
下载4.03 MB, 下载次数: 94
感谢支持
谢管理员支持
谢版主支持
谢楼上支持
谢楼上支持