diff --git a/arduino_nano/main.c b/arduino_nano/main.c index f2fc8ba..c8b14fa 100644 --- a/arduino_nano/main.c +++ b/arduino_nano/main.c @@ -46,10 +46,24 @@ void wdt_init(void) { MCUSR = 0; wdt_disable(); - - return; } +/* enable watchdog with interrupt and system reset (modified wdt_enable) */ +#define wdt_set(value) \ +__asm__ __volatile__ ( \ + "in __tmp_reg__,__SREG__" "\n\t" \ + "cli" "\n\t" \ + "wdr" "\n\t" \ + "sts %0,%1" "\n\t" \ + "out __SREG__,__tmp_reg__" "\n\t" \ + "sts %0,%2" "\n\t" \ + : /* no outputs */ \ + : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \ + "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE) | _BV(WDIE)), \ + "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | _BV(WDE) | _BV(WDIE) | (value & 0x07)) ) \ + : "r0" \ +) + /* initialize GPIO */ void io_init(void) { @@ -73,7 +87,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")); /* configure nRF24 transceiver */ nrf24_set_rx_addr(conf.rx_addr); // set device receiving address @@ -98,24 +112,12 @@ int main(void) 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<