I have just started playing with a low power arduino project, and have managed to get the power drain down to about 220uA using powerDown
from LowPower
.
What I would love to be able to do is start the USB controller and send some data every 8 seconds, but I cant seem to send anything...
Any idea would be greatly appreciated :)
Her is my code:
// **** INCLUDES *****
#include <LowPower.h>
#include <avr/interrupt.h>
#include <avr/power.h>
#include <avr/sleep.h>
#include <avr/io.h>
void setup()
{
DDRD = B00100000; // PORTD5 = TXLED
DDRB = B00000001; // PORTB0 = RXLed
Serial.begin(9600);
while (!Serial) ; // Needed for Leonardo only
Serial.println("Starter...");
delay(100);
Serial.end();
/*
* IKKE FJERN DENNE!!! Da greier vi ikke å omprogramere kortet...
*/
delay(10000);
Serial.begin(9600);
while (!Serial) ; // Needed for Leonardo only
Serial.println("low-power...");
delay(100);
Serial.end();
flash();
}
void loop()
{
//LowPower.idle(SLEEP_8S, ADC_OFF, TIMER4_OFF, TIMER3_OFF, TIMER1_OFF, TIMER0_OFF, SPI_OFF, USART1_OFF, TWI_OFF, USB_OFF);//, USB_OFF);
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
//USBCON &= B11011111; //Disable USB Freeze clock USBCON.FRZCLK
//USBCON |= B10010001; //SET USB_MACRO_ENABLE_BIT USBCON.USBE
PLLCSR |= B00000010; //-Enable PLL PLLCSR.PLLE = 1;
while (!(PLLCSR & 1)); //-Wait PLL LOCK while (PLLCSR.PLOCK != 1);
USBCON &= B11011111; //-Unfreeze USB clock USBCON.FRZCLK = 0; (Clear to unfreeze)
//-Clear Resume information ???
flash();
/*
* Test USB kommunikasjon :)
*/
Serial.begin(9600);
while (!Serial);
delay(5);
Serial.println("Hello world!!!");
delay(5);
Serial.end();
PORTD |= B00100000;
PORTB |= B00000001;
}
void flash() {
PORTD &= B11011111;
PORTB &= B11111110;
delay(100);
PORTD |= B00100000;
PORTB |= B00000001;
delay(100);
PORTD &= B11011111;
PORTB &= B11111110;
delay(100);
PORTD |= B00100000;
PORTB |= B00000001;
delay(100);
PORTD &= B11011111;
PORTB &= B11111110;
delay(100);
PORTD |= B00100000;
PORTB |= B00000001;
delay(100);
}
Best regards, Richard
EDIT
The manual specifies this resume protocol: Resuming the USB interface (21.13 USB Software Operating Modes)
- Enable PLL
- Wait PLL lock
- Unfreeze USB clock
- Clear Resume Informtion
which I have translated into this:
PLLCSR |= B00000010; //-Enable PLL PLLCSR.PLLE = 1;
while (!(PLLCSR & 1)); //-Wait PLL LOCK while (PLLCSR.PLOCK != 1);
USBCON &= B11011111; //-Unfreeze USB clock USBCON.FRZCLK = 0; (Clear to unfreeze)
//-Clear Resume information ???
It have no effect whatsoever, have no idea how to clear resume information though...
Also, for the record, the LEDs are flashing happily every 8 seconds.