9 years, 10 months ago.

Detaching and Re-attaching ticker does not work on nrf51822 Nordic nRF51-DK

When using the ticker with the Nordic nRF51-DK, when I try detaching and the re-attaching to the ticker in order to change the timing, the ticker stops working. Calling detach() prior to attach does not seem to make any difference.

Are there any workarounds for this?

Thanks!

Code showing problem with re-attaching to the ticker

#include "mbed.h"
#include "app_timer.h"
Ticker flipper;
DigitalOut led1(LED1);
DigitalOut led2(LED2);
Timer timer;
volatile int counter = 0;
void flip()
{
    led2 = !led2;
    counter ++;
}

int main()
{
    led2 = 1;
    bool state = true;
    
    flipper.attach(&flip, 0.2); // the address of the function to be attached (flip) and the interval (2 seconds)

    // spin in a main loop. flipper will interrupt it to call flip
    while(1) {
        led1 = !led1;
        wait(0.2);

        if (counter > 20) {
            counter = 0;
            flipper.detach();
            state = !state;
            flipper.attach(&flip,state? 0.2: 0.1); //this line will not properly attach to the ticker, and led2 will no longer flip!
        }
    }
}

Question relating to:

2 Answers

9 years, 10 months ago.

At least make sure your mbed lib is the latest version (right click on mbed lib, click update). Or even try importing the mbed-src lib (in the import window it is probably somewhere on top, otherwise search for it), which is more recent than the normal mbed lib.

That said I don't know if they already fixed all ticker bugs of the NRF.

Hi,

I have verified that I am using the latest version, and also tried using the latest source code. The ticker and timeout code on the nrf51822 is very buggy!

posted by Mordechai Brodt 20 Jan 2015

I don't have the NRF myself, but I do know there have been indeed quite some bugs related to the NRF ticker code. Many are fixed, but apparantly this one not. Sadly I can't help you further with it, maybe someone else can :).

posted by Erik - 20 Jan 2015

I have another nRF51 related ticker bug: https://developer.mbed.org/questions/53738/wait_ms-and-Ticker-slow-to-a-crawl-but-o/ :-(

posted by Tim H 28 May 2015
9 years, 10 months ago.

Hi, I'm also running into this bug. Am considering using the Nordic SDK timer (and maybe scheduler too), see: http://developer.mbed.org/teams/Nordic-Semiconductor/code/nRF51822/file/0e7a9efee6d7/nordic/nrf-sdk/app_common/app_timer.h