Today at 12:11 pm
Hello,
after i managed to set the Arduino to sleeping mode, the Watchdog
restarts the whole system after 8 seconds. So far so good. But instead
of restarting the complete system I would like to continue after the
"sleeping line" to repeat the sleeping phase 5 more times. I already
checked out the ATMEGA4809 Datasheet, but didn't find anything to deal
with this issue. On the other hand I found some sample codes from other
ATMEGA microcontroler models where it seems to be possible. For example
here:
1 | http://shelvin.de/arduino-in-den-sleep_mode_pwr_down-schlaf-modus-setzen/
|
Here is the source of the datasheet I used as a reference:
1 | http://ww1.microchip.com/downloads/en/DeviceDoc/40002015A.pdf
|
Here is my code. Thanks in advance for your help!
Regards,
Manuel
1 | #include <avr/sleep.h>
|
2 |
|
3 | int count = 0;
|
4 | void setup()
|
5 | {
|
6 | //Waiting time
|
7 | Serial.begin(9600);
|
8 | }
|
9 |
|
10 | void loop()
|
11 | {
|
12 | for(int i = 0; i < 5; i++){
|
13 | delay(1000);
|
14 | Serial.println(count++);
|
15 | }
|
16 | watchdogOn();
|
17 | Serial.println("Continue here with operation to set the Arduino again in sleep mode");
|
18 | //watchdogOn();
|
19 | //watchdogOn();
|
20 | }
|
21 |
|
22 | //Set Watchdog active to 8s and go to sleep
|
23 | void watchdogOn() {
|
24 | WDT.STATUS = WDT.STATUS & 01111111;
|
25 | while (!(WDT.STATUS == 0)){
|
26 | Serial.println("...");
|
27 | }
|
28 | CPU_CCP = 0xD8; //unlock...
|
29 | WDT.CTRLA = 0xB; //set WDT to 8 seconds
|
30 | Serial.println("Watchdog active...and going to sleep");
|
31 | delay(100);
|
32 | set_sleep_mode(SLEEP_MODE_PWR_DOWN);
|
33 | sleep_enable();
|
34 | sleep_mode();
|
35 | sleep_disable();
|
36 | delay(100);
|
37 | }
|
38 |
|
39 | void watchdogOff() {
|
40 | WDT.STATUS = WDT.STATUS & 01111111;
|
41 | while (!(WDT.STATUS == 0)){
|
42 | Serial.println("...");
|
43 | }
|
44 | CPU_CCP = 0xD8;
|
45 | WDT.CTRLA = 0x0;
|
46 | Serial.println("Watchdog disabled...");
|
47 | }
|