I am using TWR-S08DC-PT60 board which has a MC9S08PT60 microcontroller.
I am trying to disable the watchdog timer in my application, just for ease of development. After configuring it in the software, it is disabled in the first run after programming, as wanted. However, after a reset occurs, either by reset button or power down, it is automatically enabled by itself. This happens when I debug, run or flash using CodeWarrior 10.4.
Here is how I disable it:
_WDOG_CS1.Bits.UPDATE = 1; // Enable changes to WDOG.
WDOG_CNT = 0xC520; // write the 1st unlock word
WDOG_CNT = 0xD928; // write the 2nd unlock word
_WDOG_CS1.Bits.EN = 0; // Kill the dog.
_WDOG_CS1.Bits.INT = 1; // Enable WDOG interrupt.
From the reference manual:
23.3.2.1 Reconfiguring the Watchdog
In some cases (such as when supporting a bootloader function), users may want to reconfigure or disable the watchdog without forcing a reset first. By setting the WDOG_CS1[UPDATE] bit to a 1 on the initial configuration of the watchdog after a reset, users can reconfigure the watchdog at any time by executing an unlock sequence. (Conversely, if the WDOG_CS1[UPDATE] remains 0, the only way to reconfigure the watchdog is by initiating a reset.) The unlock sequence is similar to the refresh sequence but uses different values.
When I debug the application, I can see that UPDATE bit is set and the watchdog timer is disabled, also, it behaves as desired when I reset using the debugger. However, in case of a reset by the reset button or power down, watchdog timer is enabled again and reset the MCU, since I do not feed it in the main loop.
Also, it doesn't create an interrupt before resetting the MCU, although its interrupt is enabled. I can see, by the help of SYS_SRS (system reset source) register that the MCU is last reset by watchdog timer.
Commenting out 2nd and 3rd line (WDOG_CNT=...) does not help.
Here is my full code:
main.c
. Afterinitialize_CPU()
function, which includes above code, executed, an LED is lit, then it is turned OFF. Then,SYS_SRS
register is shown by the LEDs on the board. \$\endgroup\$initialize_CPU
is not being called or it's not changing the CSR bits. What happens if you put a breakpoint afterinitialize_CPU
, press reset, and check WDOG_CS1? \$\endgroup\$EN
bit ofWDOG_CS1
seems to be cleared. \$\endgroup\$