Created Mon, 16 Dec 2013 02:47:08 +0000 by SickBeard
Mon, 16 Dec 2013 02:47:08 +0000
So I've been trying to set up my fubarino SD to sleep then wake up after the WDT timeouts (it blinks the LED otherwise). I can get it to sleep, or I get it to blink, however not at the interval it should be blinking it (1sec off, 1sec on). I've tried changing the postscaler, and it seems not to make a difference.
Mon, 16 Dec 2013 08:55:34 +0000
Any chance of sharing your code with us?
Mon, 16 Dec 2013 14:23:46 +0000
Excuse the messiness; I've been trying out a lot, and don't know if it's necessary so I've kept it, but commented out. Please tell me if I'm doing something stupidly wrong, I really can't wrap my head around this.
void setup() {
WDTCONSET = 0x30; // post scaler
WDTCONCLR = 0x0002;
WDTCONSET = 0x8000;
WDTCONSET = 0x01;
// FWDTPS = 0b01100;
// initialize the digital pin as an output.
// Pin PIN_LED1 has an LED connected on most Arduino and compatible boards:
pinMode(PIN_LED1, OUTPUT);
//DEVCFG1 = (1 << 23); //wdt enabled
if (RCON & 0x18){
asm volatile("eret");
}
/*
if (RCON & 0x14) {
asm volatile ("eret");
}
if (RCON & 0x10){
}*/
}
void loop() {
/*SYSKEY = 0x12345678;
SYSKEY = 0xAA996655;
SYSKEY = 0x556699AA; //unlocked
*/OSCCONSET = 0x10;
/*
SYSKEY = 0x33333333;
*/
while (1) {
digitalWrite(PIN_LED1, HIGH); // set the LED on
delay(5000); // wait for a second
digitalWrite(PIN_LED1, LOW); // set the LED off
delay(1000); // wait for a second
digitalWrite(PIN_LED1, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(PIN_LED1, LOW); // set the LED off
delay(1000); // wait for a second
asm("wait");
}
}
//__ADC1Interrupt:
//asm("eret");
Wed, 18 Dec 2013 21:07:57 +0000
Any ideas, anyone?
Thu, 19 Dec 2013 18:37:41 +0000
Any ideas, anyone?
In my Forth system using the following code:
//*
//* sleep ( f --- )
//* Put MCU to sleep mode.
//* Switch off the USB module
//* If f is true then turn on the WDT before going to sleep.
//* Tested only with WDT reset. Need to test other wakeup sources !
void sleep(void) {
UINT wdt = POP;
SYSKEY = 0x0;
SYSKEY = 0xAA996655;
SYSKEY = 0x556699AA;
OSCCONSET = 0x10; // set Power-Saving mode to Sleep
SYSKEY = 0x0;
if (wdt) {
ClearWDT();
EnableWDT();
ClearWDT();
}
U1PWRC = 0; // Switch off the USB module to save more power.
// put device in selected power-saving mode
asm volatile( "wait" );
}
An example using sleep in Forth on a DP32 board:
hex
: .reset
cr cr cr
rcon@ ." RCON: " u. cr cr
." Cause of reset:" cr
rcon@ 1 and if
." POR reset" cr
then
rcon@ 2 and if
." BOR reset" cr
then
rcon@ 4 and if
." IDLE reset" cr
then
rcon@ 8 and if
." SLEEP reset" cr
then
rcon@ 10 and if
." WDTO reset" cr
then
rcon@ 40 and if
." SWR reset" cr
then
rcon@ 80 and if
." EXT reset" cr
then
;
decimal
11 constant LED
: main
\ Set LED to output
1 LED pm
\ blink LED 50 times
\ this is the time to reconnect with terminal
50 0 do
LED d@ 0= LED d!
100 delayms
loop
\ print cause of reset
.reset
\ wait for keypress in next 5 seconds
cr ." Press any key to sleep or BootLoader button to abort !" cr
25 0 do
200 delayms
LED d@ 0= LED d!
?key if
leave
then
loop
\ Switch off LED
0 11 d!
\ Switch on WDT and put MCU to sleep
1 sleep
;
\ Start "main" automatically after reset.
\ Work all reset cause except External Reset (eg. Reset Button)
: autorun main ;
\ Save the current system to flash.
syssave
\ Execute a soft reset
0 reset
And the result in the terminal:
RCON: 10
Cause of reset:
WDTO reset
Press any key to sleep or BootLoader button to abort !