1

Question

In the interest of reducing power consumption, I am putting the Arduino into sleep mode between taking sensor readings. However, the data from readings are stored in arrays, and must not be erased when the device enters sleep mode.

For clarity, I am using sleep_mode_pwr_down, and triggering an interrupt using the Watchdog Timer on the ATMega328 chip. See this post for a description of the different sleep modes: What are (or how do I use) the power saving options of the Arduino to extend battery life?

It would be possible to address this issue by writing data to the EEPROM, however, I am unsure whether this is necessary. The question is whether putting the device into sleep_mode_pwr_down erases the dynamic memory?


Specs / Context:

Arduino Uno (ATMega328 chip)

2
  • If not, you could use an external SRAM chip - which will provide more RAM than ATmega328 gives anyway. You can find them with a quick google search: e.g. SRAM 1Mbit. Standby current is well below 10 uA.
    – MichaelT
    Aug 14, 2018 at 12:16
  • Thanks @MichaelT, it appears from some prototyping I have just done that it is indeed the case that SRAM is not erased (based on dynamic memory within the system). I plan to test this further as this seems somewhat unexpected, but will update this post with any major developments.
    – Triz
    Aug 14, 2018 at 12:39

1 Answer 1

4

Generally, Atmega sleep modes do not erase RAM. Their memory is static and as long as voltage (above 2.7V I believe) is applied, data is held.

However, this also depends on how you plan to wake up the device. If it receives a RESET, RAM is cleared and program execution starts from the beginning.

If an enabled interrupt occurs while the MCU is in a sleep mode, the MCU wakes up. The MCU is then halted for four cycles in addition to the start-up time, executes the interrupt routine, and resumes execution from the instruction following SLEEP. The contents of the Register File and SRAM are unaltered when the device wakes up from sleep.

Check out the AVR's sleep modes to see which fits your application best and how to safely wake it up again

1
  • 3
    Note that, on reset, the RAM is erased by software (the libc startup code), not by hardware. You can put data in the “.noinit” section if you want to preserve it through a reset. Aug 15, 2018 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.