Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
stm32:peripherals:pwr_sleep [2016/10/13 11:10] – created feur | stm32:peripherals:pwr_sleep [2019/09/16 07:19] (current) – [Programming Example] kjaz | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== SLEEP Mode ====== | ====== SLEEP Mode ====== | ||
+ | |||
+ | In SLEEP mode only the cpu clock is disabled, everything else stays as previously configured. \\ \\ | ||
+ | |||
+ | === Enter SLEEP mode === | ||
+ | |||
+ | * WFI (wait for interrupt) instuction enters SLEEP mode. | ||
+ | \\ | ||
+ | |||
+ | === Exit SLEEP mode === | ||
+ | |||
+ | * Clear the EXTI (and, if not EXTI, the corresponding NVIC) pending bit. | ||
+ | \\ | ||
+ | |||
+ | |||
+ | ===== Programming Example ===== | ||
+ | |||
+ | The code snippet bellow shows how to enter (and exit) SLEEP mode. | ||
+ | |||
+ | <code c> | ||
+ | #include " | ||
+ | |||
+ | RCC-> | ||
+ | RCC-> | ||
+ | |||
+ | /* Configure wake up pin (PA.0). */ | ||
+ | GPIOA-> | ||
+ | |||
+ | GPIOA-> | ||
+ | GPIOA-> | ||
+ | |||
+ | /* Configure interrupt. */ | ||
+ | SYSCFG-> | ||
+ | EXTI-> | ||
+ | EXTI-> | ||
+ | NVIC-> | ||
+ | |||
+ | /* Disable SLEEPDEEP (STOP or STANDBY mode). */ | ||
+ | SCB->SCR &= ~(0x1 << 2u); | ||
+ | |||
+ | |||
+ | /* -------------------- Enter SLEEP mode -------------------- */ | ||
+ | |||
+ | __asm volatile (" | ||
+ | |||
+ | |||
+ | /* -------------------- Exit SLEEP mode --------------------- */ | ||
+ | |||
+ | /* Since all registers and the SRAM are untouched by the SLEEP mode, | ||
+ | * the program continues after the WFI instruction. | ||
+ | * No further steps required. | ||
+ | */ | ||
+ | |||
+ | </ | ||
+ | \\ |