ATTiny167 : Watchdog reset when writing command to CLKCSR

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a working watchdog on the ATTiny, period set to 8sec, no issues.

However, I need to switch to the external oscillator.

My sequence after power on is :

Disable the watchdog

Attempt to do the clock switch : currently limited to the following lines of code

  /* Save the current system clock source */
  CLKCSR = 1 << CLKCCE;
  CLKCSR = CLOCK_RECOVER;

Reset the watchdof (WDR instruction), then enable the watchdog as per datasheet

This results in the watchdog resetting immediately.

 

If I just remove the line CLKCSR = CLOCK_RECOVER, the watchdog works fine.

Hence somehow writing a command to CLKCSR is having an effect on the watchdog.

Please could someone advise 

 

As soon as I write a command to CLKCSR