Problems with watchdog on ATTiny2313

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried to use the watchdog as system reset on my tiny2313.
It works fine the first time, but after the reset the tiny resets all over again. A hardware reset at this point also has no use.
I have te disconnect the power to user the tiny again.

What am i doing wrong?

Here is the code I use:

void main(void)
{


  DDRB = 0xFF;      //portb = output
  DDRD = 0x00;      //portd = input
  PORTB = 0;

  MCUSR = 0;
  __delay_cycles(10000);
  PORTB = 0xFF;
  __delay_cycles(10000);

  WDTCR   =   (1<<WDIF)|(0<<WDIE)|(1<<WDCE)|(1<<WDE )|(1<<WDP3 )|(0<<WDP2 )|(0<<WDP1)|(0<<WDP0);  

  _SEI();

  while(1)
  {
    __watchdog_reset();
    for(;;);  //wait for wd to reset

  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What compiler are you using?
Which delay time (ms) does this code produce?

__delay_cycles(10000);

ATTiny2313 has no register named WDCR but a WDTCSR register.

The Watchdog will be cleared only once since after the line

__watchdog_reset();

the program will hang in the endless loop

for(;;);

So the watchdog must reset the AVR.

Regards
Sebastian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

S-Sohn wrote:
What compiler are you using?
Which delay time (ms) does this code produce?

__delay_cycles(10000);

ATTiny2313 has no register named WDCR but a WDTCSR register.
[/code]


I'm using IAR Workbench __delay_cycles(10000) will delay 10 ms when i use an 1MZh crystal.

I looked in the iotiny2312 file and the register is WDTCR.
If i use WDTCSR, i get a compile error.

Quote:

The Watchdog will be cleared only once since after the line

__watchdog_reset();

the program will hang in the endless loop

for(;;);

So the watchdog must reset the AVR.

The program works for the first time. When it reaches for(;;), the Tiny reboots after 4sec watchdog time.
But after the reboot, the leds at PORTB are blinking very fast, so i think the uC reboots all the time. Even if i do a hardware reset (pulling RST low), PORTB keeps blinking.
Only after i disconnect the power and reconnect, it starts normal and resets after 4sec watchdog time. After this, it starts all over again.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

See my respective comments on top of the avr-libc watchdog header
file:

http://www.nongnu.org/avr-libc/user-manual/group__avr__watchdog.html

The actual syntax will be very different for IAR, but the problem is the
same. It's well described in the datasheet (though basically not really
expected at a first glance).

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Jörg I wasn't aware, that WDT is enabled after reset (and spend some time reading datasheet, but I didn't find this particular information). Google rulez :).