I'm trying to use WDT reset on a ATTINY85.
For the moment it works with interrupts using the code below (setup WDT).
Because I don't understand the complete code, I'm not able to change it from interrupt to reset.
(want the ATTINY to reset when the cpu stops (8s))
==> from WDE & WDIE 1 to WDE 1 & WDIE0
Writing WDTCSR binairy (B00111001 or B00101001) don't work.
Can some help me out?
Thanks
uint8_t bb;
if (ii > 9 ) ii=9; //say ii = 9
bb=ii & 7; // bit wise 9 AND 7 ==> B00000001
if (ii > 7) bb|= (1<<5); // Bit wise OR==> B000100001
bb|= (1<<WDCE); //[u]I don't understand what happens here??[/u] B00110001 ??
MCUSR &= ~(1<<WDRF); //bit wise AND NOT???
// start timed sequence
WDTCSR |= (1<<WDCE) | (1<<WDE); //setting WDCE and WDE to one
// set new watchdog timeout value
WDTCSR = bb; // played around with binairy values but didn't work
WDTCSR |= _BV(WDIE); //also lost here :o
That should make your code more portable to any model AVR since sometimes the register names are different from one chip to another. The exception is that some of the timeout durations are not available on all chips (details at the link above).
It works with using the code from that site. Thanks.
Still in the dark about the syntax used in my example code..
pert:
It's great to understand how to work with the registers but the AVR toolchain does come with a useful library that makes it easy to configure the WDT:
#include <avr/wdt.h> // Include the avr-libc Watchdog timer handling library
void setup() {
wdt_enable(WDTO_8S); // Set watchdog timeout to 8 seconds
}
void loop() {
wdt_reset(); // Reset the watchdog timer
}
Reference:
http://www.nongnu.org/avr-libc/user-manual/group__avr__watchdog.html
That should make your code more portable to any model AVR since sometimes the register names are different from one chip to another. The exception is that some of the timeout durations are not available on all chips (details at the link above).