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

Is it possible to run code when the device wakes to advertise ?

Hi,

I'd like to check the battery level in my BLE device, and I can set a timer to handle the checking, however this means that Timer 1 would need to powered up, and hence it would take more power

I thought perhaps I could attach a callback to run when the nRF51822 wakes to advertise, but there doesn't seem to be a way to attach a callback.

And the only examples I have seen, e.g. BLE thermometers, seem to use the timer and then update the advertising data in the timer callback

Is a timer the only way to do this, and does it incur much more power usage ?

Parents
  • There are a few things to note here. Firstly, you can get a event whenever the radio is active, using Radio notification. Secondly, you do not need to use a TIMER in order to perform a task at a regular interval. The low power RTC is perfect for this purpose, and the additional current consumption is neglectable, as it uses the low frequency clock, which is anyway running when you have the SoftDevice enabled (needed for BLE). The Application timer library, which uses the RTC, is probably worth looking at.

  • Thanks Einar

    That's just what I was looking for.

    I don't need to actually read the ADC each time it advertises, but I thought I could simply use a counter and when the device has advertised a predefined number of times , equal to one hour of operation I will read the ADC to get the voltage and then change the advertising data (for next time it advertises)

    This would add very little overhead to normal operation eg

    if (++counter>MAX_COUNT) { counter=0;// counter is volatile int // Read ADC etc etc

    }

    Thanks again

    Roger

Reply
  • Thanks Einar

    That's just what I was looking for.

    I don't need to actually read the ADC each time it advertises, but I thought I could simply use a counter and when the device has advertised a predefined number of times , equal to one hour of operation I will read the ADC to get the voltage and then change the advertising data (for next time it advertises)

    This would add very little overhead to normal operation eg

    if (++counter>MAX_COUNT) { counter=0;// counter is volatile int // Read ADC etc etc

    }

    Thanks again

    Roger

Children
No Data
Related