Advertising failed to start (err -120)

I am running into an issue (title), where I am attempting to switch the advertising interval to a slower interval after a set period of advertising in order to save power. Advertising is being successfully started the first time, I then start a timer. In the timer expiration handler, I call bt_le_adv_stop(), and then initialize advertising again, this time with a different set of min and max intervals. The second time around, bt_le_adv_start() returns -120 (EALREADY). I have tried adding a delay in between the stop and start functions in case it takes longer than expected for advertising to stop, but this did not change the outcome. Also, bt_le_adv_stop() is returning 0 which I believes implies the action was successful. Any help would be appreciated, thanks!

I am using:
NCS v2.6
nRF52832

  • It has to do with interrupt priorities. The error message is a bit misleading, and difficult to understand, but the issue is that stopping and starting the advertisements are dependent on interrupts from the SoftDevice controller. When it is trying to do this, while already being in a timeout interrupt, you will enter a deadlock. The SoftDevice controller can't tell the application that it has stopped, and the application is waiting for it to stop. 

    So what we are doing with the work handler is basically to queue up the advertising actions (stop -> start), so that it can execute outside the interrupt when you are done in the current interrupt (the timeout handler).

    Hope that made some sense.

    Best regards,

    Edvin

Related