strange problem with WTR reset

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

Hi,

I just got a strange problem for WTR in my bootloader. After the new program been loaded into the flash, I have a WTR reset in order to start application:

wdt_enable(WDTO_15MS);

I found out that this will not bring the CPU back to application section, and after I power off and power on the CPU, the application started. And I found out the program downloading is ok, so then I start to be suspicious of this WDR, but I can't find anything from both datasheet of AVR and on line avr-libc.

Anyone can give me a idea?

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

You've got a recent AVR, did you?

The behaviour of the watchdog has changed with the new
watchdog implementation. If your device has a watchdog
that can trigger an interrupt as well as a reset, that's
a `new' one: the watchdog will remain active even after
the reset, with the shortest watchdog period (15 ms),
until you first clear the WDRF flag in MCUSR, and then
disable the watchdog.

See the introduction in , or in printed form
here.

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

yes, my AVR is mega1281, the 'new' one.

And in my application code, I did first disable the WDR by using wdt_disable() from , so I think that should be ok, or is it?

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

Did you look at the link I provided? Did you read my text
above? Did you read the datasheet (carefully -- but it's
written there)?

No, it's not OK. Either do what I wrote in the docs, or go
ahead and really understand each detail of *why* it is that
way. You dropped clearing WDRF, and unless you are really
sure all your initializations are done within less than 15 ms,
you should also consider moving all this into the .init3
sections as the avr-libc docs suggest.

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

ok, I changed the code to:

void turn_off_watchdog(void) __attribute__((naked)) __attribute__((section(".init3")));

void turn_off_watchdog(void)
// disable the watchdog timer first, in case of this application code is been loaded by the bootloader
{
	MCUSR &= ~(_BV(WDRF));
	
	wdt_disable(); 
}

and then it start to work.

Thanks jörg