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

Update timer speed once connected

I have a custom Characteristic in my GATT that is sending data in Notify mode every 30ms.

In my firmware I use timer to do this with something like this :


#define RTC1_TICK_DURATION		31
	
#define TIMER_ONE_DURATION   		33 // 30ms																/**<(deflt:1000)[ms] sending/measurement cycle duration for 1s cycled characteristics*/
#define TIMER_ONE_TICKS_NB 		(TIMER_ONE_DURATION * 1000 / RTC1_TICK_DURATION)


err_code = app_timer_start(m_TimerOne_id, (uint32_t)TIMER_ONE_TICKS_NB, NULL);


Everything is working great but sometimes, randomly, my app using BLE or my laptop using Web BLE (so two different device with two different source code with the same behavior) are unable to retrieve value for this Characteristic. They are able to connect to my device but no Characteristic value is send.

I tried to change the interval from 30ms to 90ms and so far I am not able to reproduce this issue so it lead me to think that the speed can be the source of the issue.

How would you deal with that ? Is it possible to notify at a low pace, then one second after a connection is made, increase the speed ? Or better, when someone subscribe to the Notifying Characteristic increase speed, when it disconnect decrease speed ?

Thanks !

  • This is exactly what I found by checking the log multiple time. It looks like every time the error occurs is when m_conn_handle DISCONNECTED is called just after a nrf_drv_saadc_sample is requested. This is why I included it in my log.

    I need to confirm.

    But if this is the case, how can we prevent it ? Because we should be able to disconnect any time.

    EDIT : I'm almost sure this is the reason, every time I am able to reproduce the error, this is what I see in the logs.

    EDIT 2 : It looks like, when I add a nrf_delay_ms(100); at the beginning of my DEVICE_GOtoLowpower case, I do not reproduce the error. Maybe this give him the time to finish the nrf_drv_saadc_sample ?! Do you see a better solution or is it OK if I keep this like that ?

  • One way is to check a flag in the uninit if it is sampling set another flag to uninit the in the saadc event handler after processing the sample.  If no sampling in progress then proceed with uninit.  

    An other way is to check in saadc event handler if connection is invalid then uninit the saadc instead of sending data.  

  • Thanks for the ideas.

    I ended up setting a flag to true every time I do a nrf_drv_saadc_sample() and I set it to false just after I've done the nrf_drv_saadc_buffer_convert()

    When I disconnect, in the DEVICE_GOtoLowpower case I check if my flag is true or false.

    If it's false then we do not have a saadc sample in progress so I can do all my uninit. If it's true, I wait 10ms.

    So far it's working great ! Hope we are done with this !

    Thanks for your help and (and your patience)

Related