Skip to content

Latest commit

 

History

History
255 lines (144 loc) · 7.04 KB

README.md

File metadata and controls

255 lines (144 loc) · 7.04 KB

Arduino Low Power library for Silicon Labs boards

This library allows the use of the low power features of the EFR32 MCU. This means your battery powered projects will have a longer battery life.

Read more about the EFR32 energy modes here: https://www.silabs.com/mcu/32-bit-microcontrollers/efm32-energy-modes

⚠️ Flashing while in deep sleep

When in deep sleep the devices will turn off most of their peripherals - including their debug/flashing interfaces.

This means that when the device is deep sleeping it's not possible to flash or erase them.

On Silicon Labs boards the board controller will take care of this by issuing a reset after the first failed communication attempt.

On the Nano Matter an escape method is utilized when using this library to force and hold the device in an awake state before any user code can run.

To enter this escape mode on your Nano Matter do the following:

  • Press and hold the user button
  • Press and release the reset button
  • Wait for the onboard LED to be continuously lit
  • Release the user button
  • Your board will now stay awake and can be reflashed

Methods

LowPower.idle(milliseconds)

Description

Requests EM1/EM2 mode for the specified amount of time. The device is not guaranteed to be in the requested energy mode during for the entire specified period - as the radio stacks and other peripherals can and will periodically wake the device to perform their necessary tasks - then put the device back to sleep.

Syntax

LowPower.idle(milliseconds);

Parameters

milliseconds: the number of milliseconds to put the board in idle mode.

LowPower.sleep(milliseconds)

Description

Requests EM1/EM2 mode for the specified amount of time. The device is not guaranteed to be in the requested energy mode during for the entire specified period - as the radio stacks and other peripherals can and will periodically wake the device to perform their necessary tasks - then put the device back to sleep.

Syntax

LowPower.sleep(milliseconds);

Parameters

milliseconds: the number of milliseconds to put the board in sleep mode.

LowPower.deepSleep()

Description

Puts the MCU in deep sleep mode. The deep sleep mode allows the device to an enter extremely low power consumption state (EM4). Every peripheral is stopped except for a few - like the back-up RTC and back-up RAM. The CPU can only wake up using the RTC or a pulse on a wake-up interrupt capable pin. In this mode the CPU is completely halted and RAM contents are lost. Upon waking up the device starts from the beginning of the sketch.

Syntax

LowPower.deepSleep();
LowPower.deepSleep(milliseconds);

Parameters

milliseconds: the number of milliseconds to put the board in deep sleep mode. If void the deep sleep mode is used till a wake-up event.

LowPower.deepSleepHoldPins()

Description

Configures whether GPIO states should be held while the MCU is in deep sleep. When enabled, pins keep their state during deep sleep but return to their reset state after wake-up. Use LowPower.deepSleepRetainPin() to keep selected pins in a configured state after wake-up. If pin retention is configured with LowPower.deepSleepRetainPin(), it takes precedence over LowPower.deepSleepHoldPins() and this setting is ignored.

Syntax

LowPower.deepSleepHoldPins(hold);

Parameters

hold: true to hold GPIO states during deep sleep, false to disable GPIO hold.

LowPower.deepSleepRetainPin()

Description

Configures an output pin to keep the specified state during deep sleep and after wake-up. Only OUTPUT pins with a LOW or HIGH state can be retained. Up to 3 pins can be configured for retention. The function returns true if the pin retention configuration was stored successfully and false otherwise. Pin retention takes precedence over LowPower.deepSleepHoldPins(), so the GPIO hold setting is ignored once a retained pin is configured.

If the same pin is configured as a deep sleep wake-up pin with LowPower.attachInterruptWakeup(), the wake-up pin configuration takes precedence while entering deep sleep and the retained output state won't take effect while the MCU is sleeping.

The deep sleep escape pin always takes precedence over pin retention and is configured as INPUT_PULLUP after wake-up before the sketch starts.

Using this feature reserves the last 10 writeable addresses of the Back-up RAM (40 bytes). While pin retention is enabled, writes to those addresses with LowPower.deepSleepMemoryWrite() are ignored and reads with LowPower.deepSleepMemoryRead() return 0.

Syntax

LowPower.deepSleepRetainPin(pin, mode, status);

Parameters

pin: the pin to retain during and after deep sleep.

mode: the retained pin mode. Only OUTPUT is supported.

status: the retained pin state. Can be LOW or HIGH.

LowPower.deepSleepClearRetainedPins()

Description

Clears the stored deep sleep pin retention configuration. After calling this function, subsequent deep sleep calls won't retain pins after wake-up unless LowPower.deepSleepRetainPin() is called again.

Syntax

LowPower.deepSleepClearRetainedPins();

Parameters

None

LowPower.attachInterruptWakeup()

Description

Attaches a function to call on wake-up and sets the deep sleep wake-up pins.

Syntax

LowPower.attachInterruptWakeup(pin, callback, mode);

Parameters

pin: the pin used as external wakeup

callback: the function to call on wakeup

mode: the transitions to sense on the indicated pin. Can be one between:

  • FALLING
  • RISING

LowPower.wokeUpFromDeepSleep()

Description

Returns 'true' if the MCU has woken up after a deep sleep.

Returns 'false' if the MCU was reset by another cause.

Syntax

LowPower.wokeUpFromDeepSleep();

Parameters

None

LowPower.deepSleepMemoryWrite(address, data)

Description

Writes 4 bytes (uint32_t) to the deep sleep memory (Back-up RAM) to the specified address. Contents of the deep sleep memory are retained during deep sleep. Using LowPower.deepSleepRetainPin() reserves the last 10 writeable addresses of the Back-up RAM (40 bytes). While pin retention is enabled, writes to those addresses are ignored.

Syntax

LowPower.deepSleepMemoryWrite(address, data);

Parameters

address: address to write

data: data to write

LowPower.deepSleepMemoryRead(address)

Description

Reads 4 bytes (uint32_t) from the deep sleep memory (Back-up RAM) from the specified address. Using LowPower.deepSleepRetainPin() reserves the last 10 writeable addresses of the Back-up RAM (40 bytes). While pin retention is enabled, reads from those addresses return 0.

Syntax

uint32_t data_read = LowPower.deepSleepMemoryRead(address);

Parameters

None

LowPower.deepSleepMemorySize()

Description

Reads the size of the deep sleep memory (in writeable addresses). To get the size in bytes multiply the return value by 4.

Syntax

uint32_t deep_sleep_memory_size = LowPower.deepSleepMemorySize();

Parameters

None