Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf_delay_ms not working correctly after porting to SDK 16


Hi, I am porting an app from SDK 14.2 to SDK 16 (nrf52832) and noticed some strange behaviour with nrf_delay_ms - it is not delaying anywhere nearly long enough. I have built a sample program and tested with 14.2 with a delay of 1000 ms and it works as expected. To get the same behaviour with 16 I have to pass a value of about 5000000 to get a 1000 ms delay. I'm sure I must be missing something obvious but can't really see what? I noticed the delay code has changed significantly between 14.2 and 16.

Apologies if this has been asked before but I have looked but I could not find any reference to this problem.

The test program does NOT use a soft device.

Thanks for your help!

#include <stdlib.h>
#include "nrf_delay.h"
#include "boards.h"

int main()
{
    //
    // Initialise the board.
    //
    nrf_gpio_cfg_output(LED_A);

    //
    // Loop forever toggling the led ON/OFF
    //
    bool setOn = true;
    while (true)
    {
        if(setOn)
        {
            nrf_gpio_pin_set(LED_A);
        }
        else
        {
            nrf_gpio_pin_clear(LED_A);
        }
        setOn = setOn ? false : true;
        // nrf_delay_ms(5000000);
        nrf_delay_ms(1000);
    }
}

Parents Reply Children
  • Hi,

    Just tried it and exactly the same behaviour - a value of 5000000 is required to get a delay of about 1 second.

    However, I have now managed to fix the problem. The issue is that there is more than one version of nrfx_glue.h in the SDK and my build procedure was including the wrong one. The one my build procedure was picking up has an empty definition for NRFX_DELAY_US(us_time).

    I changed my build procedures include search paths from having:

    nRF5SDK160098a08e2/modules/nrfx/templates

    to:

    nRF5SDK160098a08e2/integration/nrfx

    and this now appears to include the correct version of nrfx_glue.h and nrf_delay_ms now behaves as expected.

    Anyway, thanks for your help! Slight smile

Related