Giter Club home page Giter Club logo

stm32sleep's Introduction

STM32sleep

Helper library for using Stop & Standby modes with STM32duino on STM32F103Cx microcontrollers.

Usage

  1. Install STM32duino
  2. Create STM32sleep directory under Arduino IDE's library dir (~Documents/Arduino/libraries on OS X)
  3. Clone all files in this repository to the created directory
  4. Restart Arduino IDE if it was running
  5. Include STM32Sleep.h and RTClock.h to your sketch
  6. Code away!

Examples

Standby mode

The following code runs the microcontroller normally for 1 second and then sleeps 5 seconds in standby mode. When RTC alarm triggers, the device is reset and the sketch runs again from the beginning.

#include <STM32Sleep.h>
#include <RTClock.h>

RTClock rt(RTCSEL_LSE);
long int alarmDelay = 5;

void setup() {
  // We have just started or woken up from sleep! System clock is set to 72MHz HSE.
  delay(1000);
  sleepAndWakeUp(STANDBY, &rt, alarmDelay);  
}

void loop() { }  // This is never run

Stop mode

The following sketch disables ADC & GPIO's to save power before entering stop mode. Device is then continuously woken up after 5 seconds by RTC.

#include <STM32Sleep.h>
#include <RTClock.h>

RTClock rt(RTCSEL_LSE);
long int alarmDelay = 5;

void setup() {
  // Disable ADC to save power
  adc_disable_all();

  // Set all GPIO pins to Analog input to save power (this disables pretty 
  // much all I/O incl. Serial)
  setGPIOModeToAllPins(GPIO_INPUT_ANALOG);  

  sleepAndWakeUp(STOP, &rt, alarmDelay);
}

void loop() {
  // We have woken up from sleep! System clock is set to 8MHz HSI.
  
  // Optionally disable peripheral clocks to save power while in Run mode
  //disableAllPeripheralClocks();

  delay(100);  // As the main clock is only 8MHz instead of normal 72MHz this actually takes 900ms

  sleepAndWakeUp(STOP, &rt, alarmDelay);
}

#Misc

Thanks for the hard work & inspiration for all the people working on STM32duino!

For more about low power on STM32 devices, see e.g. Low power mode and wake from sleep.

stm32sleep's People

Contributors

chacal avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.