Electrical – Is it possible to set up multiple wake up interrupts on STM32. ? How to manage multiple sensor reading intervals


I am new to developing applications on STM32 development boards.
Currently i have STM32 IoT discovery kit. I am able to configure all the sensors and read data. I am interested in low power design especially STOP2 mode, when i can retain all the variables on SRAM. I want to achieve low power consumption keeping sensor reading intervals low. Imagine having 3 different sensors, reading sensor data at 3 diffrent intervals for e.g.

  1. Sensor A – read every 15mins
  2. Sensor B – read every 30mins
  3. sensor C – read every hour.

So far i have implemented a storing mechanism to store data. I have also implemented the stop2 mode sample which wakeup every 33seconds (from examples). How can i achieve functionality where i can read/poll at diffrent intervals and keep the MCU in stop2 mode after the reading is finished.?

Best Answer

This is a trivial software problem. You keep "time to next wake-up" per each sensor. On every wake-up you subtract elapsed time from every value, measure sensors that reached zero (and re-initialize their counters with corresponding sampling periods) and at the same time find the smallest value of the rest. Setup your timer to wake-up after this smallest period and activate sleep again.

You only need one wake-up source for this to work. It can be RTC alarm, low-power timer or even WDT timer, depending on what is available on your MCU in chosen sleep mode. This method will work even if longest possible sleep period is shorter than smallest required delay. In this case you simply subtract elapsed time without polling any sensors and go into next sleep period immediately.