I have been trying to get the arduino nano 33 IoT (SAMD21) in sleep mode, when I wake Up with an externall interruption, it wakes up, but only while the interruption is activated
Here is my code
// Put the CPU core into deep sleep and awake with a logic HIGH interrupt on D12
void setup()
{
pinMode(12, INPUT_PULLDOWN); // Set digital pin D12 to an input with an internal pull-down resistor
attachInterrupt(13, interrupt, HIGH); // Set up an interrupt on digital pin D12 on a logic HIGH level
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; // Set up the CPU to enter low power STANDBY mode on running the WFI() function (Wait For Interrupt)
}
void loop()
{
delay(10000); // Wait for 1 second
digitalWrite(LED_BUILTIN, LOW); // Set D13 output to logic LOW
}
void interrupt() // Interrupt Service Routine (ISR)
{
digitalWrite(LED_BUILTIN, HIGH); // Set D13 output to logic HIGH
}
What is your example trying to show?
You configure one pin (12) as input but attach an interrupt to another (13).
You configure deep sleep but do not activate sleep.
Sorry I posted a wrong code
I try to setup my arduino for sleep mode and then wake up and turn on the led for 10 seconds
When I activate the external interruption , the led turns on but only while I keep the interruption activated, It does not keep 10 seconds turn on.
// Put the CPU core into deep sleep and awake with a logic HIGH interrupt on D13
void setup()
{
pinMode(13, INPUT_PULLDOWN); // Set digital pin D13 to an input with an internal pull-down resistor
attachInterrupt(13, interrupt, HIGH); // Set up an interrupt on digital pin D13 on a logic HIGH level
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; // Set up the CPU to enter low power STANDBY mode on running the WFI() function (Wait For Interrupt)
__WFI;
}
void loop()
{
delay(10000); // Wait for 1 second
digitalWrite(LED_BUILTIN, LOW);
}
void interrupt() // Interrupt Service Routine (ISR)
{
digitalWrite(LED_BUILTIN, HIGH);
}
So, when you apply a 3.3V to the pin, the LED lights up. When you remove it, the LED is switched off because you configured the pin as input. Your digitalWrite do not do anything. Luckily for you. This could damage your I/O.
Okey thanks for advising of this problem.
I have changed the code with the interruption in pin digital 2 and sleeping the nano from the beginin,then when the interruption is activated the led blinks for 1 second and thens returns to sleep mode, However it never stops blinking, so it never goes to sleep mode.
// Put the CPU core into deep sleep and awake with a logic HIGH interrupt on D13
void setup()
{
pinMode(LED_BUILTIN, OUTPUT); // Set digital pin D13 to an input with an internal pull-down resistor
pinMode(2, INPUT_PULLDOWN); // Set digital pin D2 to an input with an internal pull-down resistor
attachInterrupt(digitalPinToInterrupt(2), interrupt, HIGH); // Set up an interrupt on digital pin D13 on a logic HIGH level
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; // Set up the CPU to enter low power STANDBY mode on running the WFI() function (Wait For Interrupt)
__WFI;
}
void loop()
{
digitalWrite(LED_BUILTIN, HIGH);
delay(1000); // Wait for 1 second
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
__WFI;
}
void interrupt() // Interrupt Service Routine (ISR)
{
}