Low Power Sketch¶
This sketch will put the board and components off or into sleep.
Libraries¶
There are no additional libraries required.
Code¶
// Test sleep current
#include <SPI.h>
void DFlashUltraDeepSleep()
{
// SPI initialization
SPI.begin();
// Initialize the CS pin for the data flash
pinMode(SS_DFLASH, OUTPUT);
digitalWrite(SS_DFLASH, HIGH);
transmit(0x00); // In case already in sleep, wake
transmit(0x79); // Now enter sleep
//transmit(0x00); // Wake again, for testing
// SPI end
SPI.end();
// Resets the pins used
resetSPIPins();
}
void transmit(uint8_t val)
{
SPISettings settings;
SPI.beginTransaction(settings);
digitalWrite(SS_DFLASH, LOW);
SPI.transfer(val);
digitalWrite(SS_DFLASH, HIGH);
SPI.endTransaction();
delayMicroseconds(1000);
}
void resetSPIPins()
{
resetPin(MISO);
resetPin(MOSI);
resetPin(SCK);
resetPin(SS_DFLASH);
}
void resetPin(uint8_t pin)
{
PORT->Group[g_APinDescription[pin].ulPort].PINCFG[g_APinDescription[pin].ulPin].reg=(uint8_t)(0);
PORT->Group[g_APinDescription[pin].ulPort].DIRCLR.reg = (uint32_t)(1<<g_APinDescription[pin].ulPin);
PORT->Group[g_APinDescription[pin].ulPort].OUTCLR.reg = (uint32_t) (1<<g_APinDescription[pin].ulPin);
}
void setup()
{
// LED On
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
// Start delay of 5s to allow for new upload after reset
// Do not remove as there is no wake up trigger
delay(5000);
// LED Off
digitalWrite(LED_BUILTIN, LOW);
// Set sleep mode
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
DFlashUltraDeepSleep();
//Disable USB
SerialUSB.flush();
SerialUSB.end();
USBDevice.detach();
USB->DEVICE.CTRLA.reg &= ~USB_CTRLA_ENABLE; // Disable USB
//Enter sleep mode
__WFI();
//...Sleep forever
//Enable USB
USB->DEVICE.CTRLA.reg |= USB_CTRLA_ENABLE;
}
void loop()
{
}
Note
The board will immediately go into sleep mode after 5 seconds, to reprogram you must double press the reset button
, the LED will fade.
Sleep current¶
The power consumption in sleep will be ~15uA.
Measured with :
- Arduino IDE 1.8.13
- SODAQ Board files version 1.8.9
- Autonomo rev5