aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKing Kévin <kingkevin@cuvoodoo.info>2015-11-08 18:51:55 +0100
committerKing Kévin <kingkevin@cuvoodoo.info>2015-11-08 18:51:55 +0100
commit65807c648c8e9accd7f205a843e8439d6258d086 (patch)
tree722b95f5d89a1501d1bb37bfdd7f9fbb74b66c83
parent85b27248b09e2f6e6f23cce053b121dfc7ea9c07 (diff)
watchdog test (not working for now)
-rw-r--r--arduino_nano/main.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/arduino_nano/main.c b/arduino_nano/main.c
index 491a8d9..d47c3b9 100644
--- a/arduino_nano/main.c
+++ b/arduino_nano/main.c
@@ -40,6 +40,7 @@
/* variables */
bool query_pzem004 = false; // flag to query the PZEM-004 power meter
volatile uint8_t timer_seconds = 0; // how many seconds have passed
+volatile bool watchdog = true; // set when watchdog interrupt occurred
/* disable watchdog when booting */
void wdt_init(void) __attribute__((naked)) __attribute__((section(".init3")));
@@ -74,7 +75,7 @@ int main(void)
{
io_init(); // initialize IOs
- //printf(PSTR("welcome to the spar counter power meter monitor\n"));
+ printf(PSTR("welcome to the spar counter power meter monitor\n"));
struct configuration conf; // node configuration
// read configuration data from EEPROM + CRC-8-iButton value
@@ -109,8 +110,24 @@ int main(void)
bool send_values = false; // set to true to send out the values
bool action = false; // to know if we performed any king of action during which some other activity could have happened
+
+ /* start watchdog */
+ wdt_enable(WDTO_4S);
+ while (true);
+ WDTCSR = (1<<WDCE); // change settings
+ //WDTCSR = (0<<WDP3)|(1<<WDP2)|(1<<WDP1)|(1<<WDP0); // set time-out to 2s
+ WDTCSR = (1<<WDP3)|(0<<WDP2)|(0<<WDP1)|(1<<WDP0);
+ WDTCSR = (1<<WDCE); // change settings
+ WDTCSR = (1<<WDE)|(1<<WDIE); // enable interrupt than system reset mode
+ while (true);
+
while (true) { // endless loop for micro-controller
action = false; // new cycle of actions
+ if (watchdog) { // watchdog interrupt trigger. clear before system reset
+ WDTCSR = (1<<WDCE); // change settings
+ WDTCSR = (1<<WDE)|(1<<WDIE); // enable interrupt than system reset mode
+ watchdog = false;
+ }
if (timer_seconds!=0 && timer_seconds==conf.request_period) {
action = true; // an action is performed
timer_seconds = 0; // restart timer
@@ -247,3 +264,9 @@ ISR(TIMER1_COMPA_vect)
{
timer_seconds++; // count seconds
}
+
+/* watchdog interrupt */
+ISR(WDT_vect)
+{
+ watchdog = true;
+}