I looked at low power modes but didn't get very far. I put a waitfor interrupt instruction (WFI) in the loop() function. I had assumed that it would put the processor to sleep forever because I hadn't arranged for anything to interrupt. The code below should go to sleep forever with the LED off, but the LED keeps toggling indicating that the processor is being interrupted.
Code:
// Put the processor to sleep forever
// Pin for LED
#define LEDPIN 13
// state of led pin
volatile int ledVal;
void setup()
{
pinMode(LEDPIN, OUTPUT);
ledVal = 0;
digitalWrite(LEDPIN, ledVal); // Start with the LED off
}
void loop()
{
// There should be no interrupts so this should sleep forever
// but the LED pin tells a different story
asm volatile("wfi\n"::);
digitalWrite(LEDPIN, ledVal ^= 1);
}
If I run the equivalent code on a Nano or Teensy++2 the LED stays off.
Anyone know what is interrupting and how to shut it down? It isn't the USB because a Serial.end() in setup() makes no difference.
Pete