We control the Autonomo sleep cycle by using de BEEDTR pin as external interrupt. But this breaks the sleep process. If we leave the attach interrupt command out, the sleep current is 15uA. With attach interrupt it uses 10mA.
Any idea how to solve this?
#include <Arduino.h>
#define XbeeSerial Serial
#define XBPWR (7)
#define LED1 PIN_LED3
#define LED2 PIN_LED2
const byte XB_ON = 0;
volatile byte awake = LOW;
void setup() {
//XbeeSerial.begin(9600);
pinMode(LED1, OUTPUT);
digitalWrite(LED1, LOW);
pinMode(LED2, OUTPUT);
digitalWrite(LED2, LOW);
// Xbee on
pinMode(XBPWR, OUTPUT);
digitalWrite(XBPWR, LOW);
// pinMode(6, OUTPUT);
// digitalWrite(6, HIGH);
//
// Setup up wakepin
pinMode(XB_ON, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(XB_ON), wake, LOW);
// Set sleep mode
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
//Disable USB
USB->DEVICE.CTRLA.reg &= ~USB_CTRLA_ENABLE;
}
void loop() {
if ( awake )
{
digitalWrite(LED2, HIGH);
delay(1000);
digitalWrite(LED2, LOW);
awake = LOW;
}
digitalWrite(LED1, HIGH);
delay(100);
digitalWrite(LED1, LOW);
__WFI();
delay(900);
}
void wake() {
awake = HIGH;
}
I know the code is without the flash sleep, I have this in another sketch. .
The SAMD platform doesn’t use the digitPinToInterrupt() macro in the same way. You simply pass the pin index/ID and the attach interrupt method looks up the specific EIC line (if available) to use.
So change:
pinMode(XB_ON, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(XB_ON), wake, LOW);
To:
pinMode(XB_ON, INPUT_PULLUP);
attachInterrupt(XB_ON, wake, LOW);
and you should be good to go.
I tested it with these constants, and using a wire to ground the BEEDTR pin to trigger the interrupt.
#define XbeeSerial Serial1
#define XBPWR BEE_VCC
#define LED1 PIN_LED
#define LED2 2 //External LED on D2
const byte XB_ON = BEEDTR;
Ah, thanks! I already knew this. It was a bit of a quick post.
The good news is, the interrupt loop works after some reinstalling the Arduino software en deleting all of its libraries.
It is now using 20uA during sleep after soldering the BEE_VCC jumper over.
The bad news is, as soon as I put in the sleep commands it does not wake on interrupt. It is probably the same issue as described here https://github.com/arduino/ArduinoCore-samd/pull/90
This is the exact code I am using now:
// Test sleep current
#include <SPI.h>
const byte ledPin = LED_BUILTIN;
const byte interruptPin = BEECTS;
volatile byte state = HIGH;
void setup()
{
// LED On
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, 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(ledPin, LOW);
// Set sleep mode
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
//Disable USB
USB->DEVICE.CTRLA.reg &= ~USB_CTRLA_ENABLE;
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(interruptPin, blink, FALLING);
}
void loop() {
digitalWrite(ledPin, state);
delay(1000);
state = !state;
digitalWrite(ledPin, state);
DFlashUltraDeepSleep();
//Enter sleep mode
__WFI();
//...Sleep forever
//Enable USB
USB->DEVICE.CTRLA.reg |= USB_CTRLA_ENABLE;
}
void DFlashUltraDeepSleep()
{
// SPI initialisation
SPI.begin();
// Initialise 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 blink() {
state = !state;
}
That change to WInterrupts.c was pulled into Sodaq SAMD fork a while ago. As long as you are using v1.6.7 or later, of the Sodaq SAMD board files, it will be included.
I believe the issue is to do with the interrupt mode. When the board is in standby/sleep, you can only use HIGH, or LOW. RISING, FALLING, or CHANGE are not supported (by default when asleep). This is because these modes require an active clock. The source clock for the EIC is not setup to run in standby.
If you need to use a change type interrupt, I have provided a solution in this thread:
http://forum.arduino.cc/index.php?topic=410699.msg2828987#msg2828987
Yeah, I just checked, it’s in. 
you can only use HIGH, or LOW.
Ah have seen this before, I’ll try first thing tomorrow.
If you need to use a change type interrupt, I have provided a solution in this thread:
http://forum.arduino.cc/index.php?topic=410699.msg2828987#msg2828987
Thanks for the workaround. LOW is probably good enough. 
Hope this is it 
Ah yeah, this works like a charm! It’s sleeping perfectly now.

The only trouble now is catching the right pin change. I have trouble getting an interrupt consequently… Next stop 
Thanks very much!
