|
NUCLEO-L053R8:低功耗STOP模式,RTC唤醒(例程分享) 基于ST官方NUCLEO-L053R8开发板 代码下载:见附件 Stop mode with RTC:1uA VDD=3.0V /** * @brief Main program * @param None2 G8 v3 y) s6 [% E, j7 I * @retval None */; q8 f' Z! r0 F" e9 q int main(void) {: M- T7 ?$ `) Z7 e6 w) a& e' u /* 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 can eventually implement his proper time base source (a general purpose 0 h# T& b+ q% C/ o8 E( M v 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. - Low Level Initialization */ HAL_Init();9 D3 t; |! e7 Q+ K /* Configure LED2 to handle error handler */ BSP_LED_Init(LED2);6 Y- z! ^5 y; q7 {) M" n- d /* Configure the system clock @ 32 Mhz */ SystemClock_Config(); 7 L1 `$ l+ A9 | /* Configure the system Power */ SystemPower_Config();; D9 J! W5 f8 { o while (1)0 a2 Z) V, \6 | u: T B1 \ { /* Insert 3 seconds delay */ BSP_LED_Init(LED2); //LED初始化 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET); //点亮LED,延时3S,再灭LED2 T3 [8 _9 ^2 o HAL_Delay(3000); . c& |- q- P2 r R: x; ^* g/ w HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET); HAL_Delay(3000); SystemPowerNORTC_Config(); //关闭所有IO和时钟,不关闭RTC /* Disable Wakeup Counter */ HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle);' y: J: Q: v2 P; j1 V8 s 1 O, j, e h0 G; ?7 ~ /*## Setting the Wake up time ############################################*/ g# s) j. R+ D5 \ /* RTC Wakeup Interrupt Generation:( P" E$ ?" }$ {7 z0 k! [1 y h Wakeup Time Base = (RTC_WAKEUPCLOCK_RTCCLK_DIV /(LSE or LSI))3 w$ Q! m; _' K9 S- B; Y Wakeup Time = Wakeup Time Base * WakeUpCounter = (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:3 E" z: {" ?; e6 T7 P* Z RTC_WAKEUPCLOCK_RTCCLK_DIV = RTCCLK_Div16 = 16 Wakeup Time Base = 16 /(~39.000KHz) = ~0,410 ms! ~3 I9 J" @7 f. R# `8 a0 w Wakeup Time = ~4s = 0,410ms * WakeUpCounter& \9 Z# m% u6 B0 L+ P ==> WakeUpCounter = ~4s/0,410ms = 9750 = 0x2616 */1 U0 Y! O s% S HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, 0x2616, RTC_WAKEUPCLOCK_RTCCLK_DIV16); - P3 r) ?2 _- X7 ?& B: Y /* Enter Stop Mode */ HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);- K; C7 h& p' o+ b7 G( s! F' k 6 m& e6 t. _. I* B /* Configures system clock after wake-up from STOP: enable HSI, PLL and select' x5 U+ I% j' \! c( | PLL as system clock source (HSI and PLL are disabled automatically in STOP mode) */) s* V& y) P2 b! b7 i SystemClockConfig_STOP(); } }
/ E( w3 i: S8 S6 B% { |
PWR_STOP_RTC.rar
下载4.03 MB, 下载次数: 96
微信公众号
手机版
感谢支持
谢管理员支持
谢版主支持
谢楼上支持
谢楼上支持