I'm posting here as a last resort as I've read through the SAMD20 and SAMD21 datasheets, searched forums and used different deep sleep examples as references. My problem seems very similiar to what Matt Thomas was experiencing here: ATSAMR21 sleep high current draw However his link to the Atmel forum comment doesn't work any more, so I can't actually see what specifically he did to achieve low current consumption.
I've tried many different things but I can never get below around 500 µA. For now I'm testing on an Adafruit Qt Py, supplying 3V3 directly to circumvent the regulator. I'm measuring using a Power Profiler Kit II.
Even turning off the OSC8M and running on the ULP OSC I see no fall in current. Didn't expect it to do anything as the OSC8M is set to ONDEMAND and won't run once generator 0 sources the ULP oscillator.
Is there something I'm missing completely?
#include "sam.h"
int main(void)
{
GCLK->GENCTRL.reg =
GCLK_GENCTRL_ID(0) |
GCLK_GENCTRL_SRC_OSCULP32K |
GCLK_GENCTRL_IDC |
GCLK_GENCTRL_GENEN;
while(GCLK->STATUS.bit.SYNCBUSY);
SYSCTRL->OSC8M.bit.ENABLE = 0;
SYSCTRL->BOD33.bit.ENABLE = 0;
PM->APBCMASK.bit.ADC_ = 0;
PM->APBBMASK.bit.DMAC_ = 0;
PM->APBBMASK.bit.PAC1_ = 0;
PM->APBBMASK.bit.PORT_ = 0;
PM->APBBMASK.bit.USB_ = 0;
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
__DSB();
__WFI();
while (1)
{
}
}
```