This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF52 Watchdog not resetting

Hi,

Currently I am trying to implement Watchdog functionality into my Project.

I have the followowing problem:

I use the Nordic WatchdogTimer.h and instance the class with 1s in the constructor.

now, if I just do a 'while(1);' the code succesfuly resets after about 1 Second.

But If I dont use a while loop, it does not reset, even if I dont use the WDT::Kick() function..?!

I think I altered some of the nrf52_bitfields.h parameters, but I dont remember which ones, so maybe thats the cause, but what could it be?

Its really strange that it resets on a while loop, but not without it and without WDT::Kick()

Thanks,

jonas

  • Hi,

    There are a few issues with your code, but none that should prevent it from working. I have fixed the writes to the WDT registers and modified the code to match the normal nRF5 SDK like this:

    int main(void)
    {
        APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
        NRF_LOG_DEFAULT_BACKENDS_INIT();
        NRF_LOG_INFO("Temperature example started.");
    
        static const uint16_t NRF_CLK_RATE = 32768; //32KHz
        NRF_WDT->CONFIG = 0x00000009;
        NRF_WDT->CRV = 2 * NRF_CLK_RATE;
        NRF_WDT->RREN = 0x11111111;
        NRF_WDT->TASKS_START = 1;
    
        while (1)
        {
            NRF_LOG_INFO("looping");
            nrf_delay_ms(1000);
        }
    }

    This gives the expected log output:

    <info> app: Temperature example started.
    <info> app: looping
    <info> app: Temperature example started.
    <info> app: looping
    <info> app: looping
    <info> app: Temperature example started.
    <info> app: looping
    <info> app: looping
    <info> app: Temperature example started.
    <info> app: looping
    <info> app: looping
    <info> app: Temperature example started.
    <info> app: looping
    <info> app: looping
    <info> app: Temperature example started.
    <info> app: looping
    <info> app: looping
    <info> app: Temperature example started.
    <info> app: looping
    <info> app: looping
    <info> app: Temperature example started.
    <info> app: looping
    <info> app: looping
    

    Please also note that the SDK includes a WDT example which uses the WDT driver, providing a high-level API that is tested and verified by us (Nordic).

  • yehaa, its working!

    I still dont know why the WatchdogTimer.h does not work, but I will just do it this way now.

    my first try to do it without the included file would have worked, if I wouldnt have been so stupid and accidentally use 0x00001001 instead of 0b00001001.

    So thanks for helping me out! Slight smile

    Jonas

  • well.. I discovered something strange... when I set CONFIG to 0x00000009 it will work. If I try to set it to 0x00 it wont work?! also, I noticed that for the CONFIG=... it will take a power cycle for the change to get applied, is that intentionally?

  • Hi,

    What do you mean by saying that it won't work when CONFIG is set to 0? In that case the WDT will pause when in sleep or haltet by a debugger, so if your current test code does that, then you should not expect to see a reset.

    Regarding changes to the CONFIG register, that must always be done before the WDT is started by writing to TASKS_START. Once it is started it cannot be reconfigured, and the only way to stop it (so that it can be reconfigured again) is with a reset. This is intentional behavior, as it prevents a malfunction system to accidentally reconfigure the SoftDevice, potentially preventing a WDT reset.

    The WDT chapter in the PS specifies it like this:

    The watchdog must be configured before it is started. After it is started, the watchdog’s configuration registers, which comprise registers CRV, RREN, and CONFIG, will be blocked for further configuration.

  • the chip does not sleep, nor am i debugging it(or does connecting over Segger RTT count as debugging?), but it simply wont reset if I set the config register to 0x00. I do start the chip after configuring it.

    regarding the power cycle, does that mean I can reconfigure the WDT every program start or every power cycle?

Related