<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Update timer speed once connected</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/45384/update-timer-speed-once-connected</link><description>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 : 
 
 
 
 Everything is working great but sometimes, randomly, my app using BLE or my laptop using</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 17 Apr 2019 16:47:51 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/45384/update-timer-speed-once-connected" /><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/182660?ContentTypeID=1</link><pubDate>Wed, 17 Apr 2019 16:47:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:945c309b-4a0e-4707-84dd-bbd7d799bfab</guid><dc:creator>StephaneJ</dc:creator><description>&lt;p&gt;Thanks for the ideas.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I ended up setting a flag to &lt;em&gt;true&lt;/em&gt; every time I do a &lt;em&gt;nrf_drv_saadc_sample()&lt;/em&gt; and I set it to false just after I&amp;#39;ve done the&amp;nbsp;&lt;em&gt;nrf_drv_saadc_buffer_convert()&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;When I disconnect, in the&amp;nbsp;&lt;em&gt;DEVICE_GOtoLowpower&lt;/em&gt; case I check if my flag is true or false.&lt;/p&gt;
&lt;p&gt;If it&amp;#39;s false then we do not have a saadc sample in progress so I can do all my uninit. If it&amp;#39;s true, I wait 10ms.&lt;/p&gt;
&lt;p&gt;So far it&amp;#39;s working great&amp;nbsp;! Hope we are done with this !&lt;/p&gt;
&lt;p&gt;Thanks for your help &lt;a href="https://devzone.nordicsemi.com/members/hnhoan"&gt;Nguyen Hoan Hoang&lt;/a&gt; and &lt;a href="https://devzone.nordicsemi.com/members/simonr"&gt;Simonr&lt;/a&gt; (and your patience)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/182456?ContentTypeID=1</link><pubDate>Tue, 16 Apr 2019 16:49:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c55c1746-cdbf-42f7-b1ee-c3f0ecf27454</guid><dc:creator>Nguyen Hoan Hoang</dc:creator><description>&lt;p&gt;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. &amp;nbsp;If no sampling in progress then proceed with uninit. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;An other way is to check in saadc event handler if connection is invalid then uninit the saadc instead of sending data. &amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/182449?ContentTypeID=1</link><pubDate>Tue, 16 Apr 2019 16:02:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:24f530c7-5b60-4d24-a78e-fabe7c201f99</guid><dc:creator>StephaneJ</dc:creator><description>&lt;p&gt;This is exactly what I found by checking the log multiple time. It looks like every time the error occurs is when&amp;nbsp;m_conn_handle DISCONNECTED is called just after a&amp;nbsp;nrf_drv_saadc_sample is requested. This is why I included it in my log.&lt;/p&gt;
&lt;p&gt;I need to confirm.&lt;/p&gt;
&lt;p&gt;But if this is the case, how can we prevent it ? Because we should be able to disconnect any time.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;EDIT : I&amp;#39;m&amp;nbsp;almost sure this is the reason, every time I am able to reproduce the error, this is what&amp;nbsp;I see in the logs.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;EDIT 2 : It looks like, when I add a nrf_delay_ms(100); at the beginning of my&amp;nbsp;DEVICE_GOtoLowpower case, I do not reproduce the error. Maybe this give him the time to finish the&amp;nbsp;nrf_drv_saadc_sample ?! Do you see a better solution or is it OK if I keep this like that ?&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/182447?ContentTypeID=1</link><pubDate>Tue, 16 Apr 2019 16:00:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ff4ec3cf-52be-4695-88ce-904ece232157</guid><dc:creator>Nguyen Hoan Hoang</dc:creator><description>&lt;p&gt;I see that there was a saadc sample started then saadc uninit before getting the result then the saadc interrupt occurs in between. &amp;nbsp;Could this be the cause of the issue ?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/182446?ContentTypeID=1</link><pubDate>Tue, 16 Apr 2019 15:53:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2cb7a7e6-d104-48a0-b5fb-e9c49d3b9b56</guid><dc:creator>StephaneJ</dc:creator><description>&lt;p&gt;Hi &lt;a href="https://devzone.nordicsemi.com/members/hnhoan"&gt;Nguyen Hoan Hoang&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;Thanks for your feedback, so I updated my saadc_callback to send it only if m_conn_handle is equal to zero (connected). Here is the new saadc_callback.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{
   
  NRF_LOG_INFO(&amp;quot;u8_device_state: %d&amp;quot;, u8_device_state);
  NRF_LOG_INFO(&amp;quot;p_event-&amp;gt;type: %d&amp;quot;, p_event-&amp;gt;type);
  NRF_LOG_PROCESS();
    if (p_event-&amp;gt;type == NRF_DRV_SAADC_EVT_DONE)
    {
 
        ret_code_t err_code;

        err_code = nrf_drv_saadc_buffer_convert(p_event-&amp;gt;data.done.p_buffer, SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);
        send_log(&amp;quot;nrf_drv_saadc_buffer_convert DONE&amp;quot;);
      
        val = p_event-&amp;gt;data.done.p_buffer[0];
        if(val &amp;gt; 65000 || val &amp;lt; 0) val=0;

        
        value_data[0]= (uint8_t) val;
        value_data[1]= (uint8_t) (val&amp;gt;&amp;gt;8);

        if(m_conn_handle == NRF_SUCCESS){
          NRF_LOG_INFO(&amp;quot;Send it !&amp;quot;);
          err_code = ble_service_on_value_change(m_conn_handle, &amp;amp;m_service, value_data);
          NRF_LOG_INFO(&amp;quot;m_conn_handle: %d&amp;quot;, m_conn_handle);
          NRF_LOG_INFO(&amp;quot;err_code: %d&amp;quot;, err_code);
          NRF_LOG_PROCESS();
          if (err_code != NRF_SUCCESS &amp;amp;&amp;amp;
              err_code != BLE_ERROR_INVALID_CONN_HANDLE &amp;amp;&amp;amp;
              err_code != NRF_ERROR_INVALID_STATE &amp;amp;&amp;amp;
              err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING &amp;amp;&amp;amp;
              err_code != NRF_ERROR_RESOURCES
             )
            {
              NRF_LOG_INFO(&amp;quot;ERROR CHECK&amp;quot;);
              NRF_LOG_PROCESS();
              APP_ERROR_CHECK(err_code);
            }
        }
        else{
          send_log(&amp;quot;Did not sent it because we are not connected anymore&amp;quot;);
        }

    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;But it&amp;#39;s not working. Here are the log :&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;WORKING LOGS :
[...]
&amp;lt;info&amp;gt; app: Send it !
&amp;lt;info&amp;gt; app: m_conn_handle: 0
&amp;lt;info&amp;gt; app: err_code: 0
&amp;lt;info&amp;gt; app: m_conn_handle DISCONNECTED
&amp;lt;info&amp;gt; app:
&amp;lt;info&amp;gt; app:
&amp;lt;info&amp;gt; app: Start DEVICE_GOtoLowpower
&amp;lt;info&amp;gt; app: enter stop_TimerOne
&amp;lt;info&amp;gt; app: exit stop_TimerOne
&amp;lt;info&amp;gt; app: enter stop_TimerTwo
&amp;lt;info&amp;gt; app: exit stop_TimerTwo
&amp;lt;info&amp;gt; app: Timers stopped
&amp;lt;info&amp;gt; app: enter saadc_uninit
&amp;lt;info&amp;gt; app: before nrf_drv_saadc_uninit
&amp;lt;info&amp;gt; app: after nrf_drv_saadc_uninit
&amp;lt;info&amp;gt; app: exit saadc_uninit
&amp;lt;info&amp;gt; app: enter GPIO_lowpower
&amp;lt;info&amp;gt; app: exit GPIO_lowpower
&amp;lt;info&amp;gt; app: End DEVICE_GOtoLowpower
&amp;lt;info&amp;gt; app: m_conn_handle CONNECTED : 0
&amp;lt;info&amp;gt; app: ------------------------------------------------------
&amp;lt;info&amp;gt; app: enter saadc_init
&amp;lt;info&amp;gt; app: exit saadc_init
&amp;lt;info&amp;gt; app: enter GPIO_init
&amp;lt;info&amp;gt; app: exit GPIO_init
&amp;lt;info&amp;gt; app: enter start_TimerTwo
&amp;lt;info&amp;gt; app: exit start_TimerTwo
&amp;lt;info&amp;gt; app: Device SET
&amp;lt;info&amp;gt; app: m_conn_handle : 0
&amp;lt;info&amp;gt; app: nrf_drv_saadc_sample
&amp;lt;info&amp;gt; app: u8_device_state: 0
&amp;lt;info&amp;gt; app: p_event-&amp;gt;type: 0
&amp;lt;info&amp;gt; app: nrf_drv_saadc_buffer_convert DONE
&amp;lt;info&amp;gt; app: Send it !
&amp;lt;info&amp;gt; app: m_conn_handle: 0
[...]




NOT WORKING LOGS :
[...]
&amp;lt;info&amp;gt; app: nrf_drv_saadc_sample
&amp;lt;info&amp;gt; app: m_conn_handle DISCONNECTED
&amp;lt;info&amp;gt; app:
&amp;lt;info&amp;gt; app:
&amp;lt;info&amp;gt; app: Start DEVICE_GOtoLowpower
&amp;lt;info&amp;gt; app: enter stop_TimerOne
&amp;lt;info&amp;gt; app: exit stop_TimerOne
&amp;lt;info&amp;gt; app: enter stop_TimerTwo
&amp;lt;info&amp;gt; app: exit stop_TimerTwo
&amp;lt;info&amp;gt; app: Timers stopped
&amp;lt;info&amp;gt; app: enter saadc_uninit
&amp;lt;info&amp;gt; app: u8_device_state: 3
&amp;lt;info&amp;gt; app: p_event-&amp;gt;type: 0
&amp;lt;info&amp;gt; app: nrf_drv_saadc_buffer_convert DONE
&amp;lt;info&amp;gt; app: Did not sent it because we are not connected anymore
&amp;lt;info&amp;gt; app: before nrf_drv_saadc_uninit
&amp;lt;info&amp;gt; app: after nrf_drv_saadc_uninit
&amp;lt;info&amp;gt; app: m_conn_handle CONNECTED : 0
&amp;lt;info&amp;gt; app: ------------------------------------------------------
&amp;lt;info&amp;gt; app: enter saadc_init
&amp;lt;info&amp;gt; app: exit saadc_init
&amp;lt;info&amp;gt; app: enter GPIO_init
&amp;lt;info&amp;gt; app: exit GPIO_init
&amp;lt;info&amp;gt; app: enter start_TimerTwo
&amp;lt;info&amp;gt; app: exit start_TimerTwo
&amp;lt;info&amp;gt; app: Device SET
&amp;lt;info&amp;gt; app: m_conn_handle : 0
&amp;lt;info&amp;gt; app: nrf_drv_saadc_sample
&amp;lt;info&amp;gt; app: nrf_drv_saadc_sample
&amp;lt;info&amp;gt; app: nrf_drv_saadc_sample
[...]&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/182442?ContentTypeID=1</link><pubDate>Tue, 16 Apr 2019 15:23:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6464ee1a-239b-40ee-9f4a-6dbc562f0d02</guid><dc:creator>StephaneJ</dc:creator><description>&lt;p&gt;No problem, you asked for it :D&lt;/p&gt;
&lt;p&gt;I really want this to be fixed so I try to give you as much informations as possible.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;For the&amp;nbsp;&lt;span&gt;CONN_SUP_TIMEOUT, I tried 8000 and even 10000&amp;nbsp;but I have the same result and behaviour.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;So I tried lower number, with 2000 same result.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;But during my manipulation I was able to reproduce the exact same issue apparently (no saadc_callback trigger) if I comment the&amp;nbsp;&lt;em&gt;saadc_init();&lt;/em&gt;&amp;nbsp;line in the DEVICE_SET case.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;So I&amp;nbsp;tried to put a&amp;nbsp;nrf_delay_us(100000) just after&amp;nbsp;&lt;em&gt;saadc_init()&amp;nbsp;&lt;/em&gt;just in case this was because the init is not yet finish before it start advertising but without success.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If I comment the&amp;nbsp;&lt;em&gt;saadc_init and&amp;nbsp;saadc_uninit&amp;nbsp;&lt;/em&gt;from the switch case (so it stay always initialized because it&amp;#39;s init during first boot) the problem is still there.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;So I put log in every function that I call when disconnecting. Log when entering and log when exiting.&amp;nbsp;Every time&amp;nbsp;when it&amp;#39;s not working, I do not see all logs. Sometimes I miss &amp;quot;exit saadc_uninit&amp;quot; or sometimes I miss &amp;quot;enter and exit GPIO_lowpower&amp;quot; and even &amp;quot;End DEVICE_GOtoLowpower&amp;quot;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;So I added nrf_delay_ms(25) between each line of DEVICE_SET case and DEVICE_GotoLowpower case. &lt;strong&gt;So far, I did not reproduce the issue after ~40 trials&lt;/strong&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Now the game is to find which one is really useful...&lt;/p&gt;
&lt;p&gt;&lt;em&gt;EDIT : It looks like the&amp;nbsp;only important one is the first one of DEVICE_GotoLowpower case to make sure the saadc_sample is finished before uninit everything. Please take a look at &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/45384/update-timer-speed-once-connected/182449#182449"&gt;my other answer here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/182434?ContentTypeID=1</link><pubDate>Tue, 16 Apr 2019 15:05:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5633f634-1aa1-4720-a01f-de161ff3d249</guid><dc:creator>Nguyen Hoan Hoang</dc:creator><description>&lt;p&gt;It is normal that the saadc never trigger again after that. &amp;nbsp;This is because you didn&amp;#39;t read the data out when the connection handle is invalid. &amp;nbsp;The state of the saadc was not reset. &amp;nbsp;You should read the saadc date even not connected, just don&amp;#39;t send it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/182389?ContentTypeID=1</link><pubDate>Tue, 16 Apr 2019 12:35:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d207f59-73c0-4a5d-a514-577fa32205ff</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Try setting this value to a larger number and see if the&amp;nbsp;connection lasts longer.&lt;/p&gt;
&lt;p&gt;Thanks for a very detailed log by the way! Not very often we see these things, so it is much appreciated.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/182289?ContentTypeID=1</link><pubDate>Tue, 16 Apr 2019 08:27:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6a694683-3089-47de-bb2c-f1ed89411ba0</guid><dc:creator>StephaneJ</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t know how to calculate it but here it is :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;#define CONN_SUP_TIMEOUT MSEC_TO_UNITS(4000, UNIT_10_MS)&lt;/p&gt;
&lt;p&gt;Sorry I&amp;#39;m on my phone&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/182281?ContentTypeID=1</link><pubDate>Tue, 16 Apr 2019 08:12:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:83e9cfe8-3964-46b4-8ae9-951fcb693637</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;For about how long does it take until the device disconnects? It might be that the connection times out. What have you set&amp;nbsp;&amp;nbsp;&lt;span&gt;#define&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;CONN_SUP_TIMEOUT as?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Simon&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/182139?ContentTypeID=1</link><pubDate>Mon, 15 Apr 2019 13:46:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f1b9086b-62c2-4039-8f07-72d01343bf7d</guid><dc:creator>StephaneJ</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/simonr"&gt;Simonr&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;No it&amp;#39;s still here but I simplify my code for an easier reading :)&lt;/p&gt;
&lt;p&gt;I still have the if NRF_DRV_&lt;span&gt;SAADC_EVT_DONE. It&amp;#39;s true that the issue happens always when I try to reconnect after a disconnection while the saadc_callback was fired after the disconnection.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;For example please take a look at this log, I hope it&amp;#39;s clear and that I didn&amp;#39;t make mistake copy/pasting :&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint8_t u8_device_state=0;


void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{
   
  	NRF_LOG_INFO(&amp;quot;u8_device_state: %d&amp;quot;, u8_device_state);
  	NRF_LOG_INFO(&amp;quot;NRF_DRV_SAADC_EVT_DONE: %d&amp;quot;, NRF_DRV_SAADC_EVT_DONE);
  	NRF_LOG_INFO(&amp;quot;p_event-&amp;gt;type: %d&amp;quot;, p_event-&amp;gt;type);
  	NRF_LOG_PROCESS();

    if (p_event-&amp;gt;type == NRF_DRV_SAADC_EVT_DONE &amp;amp;&amp;amp;
        m_conn_handle == NRF_SUCCESS)
    {
 
        ret_code_t err_code;

        err_code = nrf_drv_saadc_buffer_convert(p_event-&amp;gt;data.done.p_buffer, SAMPLES_IN_BUFFER);
	    APP_ERROR_CHECK(err_code);

	    val = p_event-&amp;gt;data.done.p_buffer[0];

	    value_data[0]= (uint8_t) val;
	    value_data[1]= (uint8_t) (val&amp;gt;&amp;gt;8);

		err_code = ble_service_on_value_change(m_conn_handle, &amp;amp;m_service, value_data);
        if (err_code != NRF_SUCCESS &amp;amp;&amp;amp;
            err_code != BLE_ERROR_INVALID_CONN_HANDLE &amp;amp;&amp;amp;
            err_code != NRF_ERROR_INVALID_STATE &amp;amp;&amp;amp;
            err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING &amp;amp;&amp;amp;
            err_code != NRF_ERROR_RESOURCES
           )
          {
            APP_ERROR_CHECK(err_code);
          }

    }
    else{
      if(m_conn_handle != NRF_SUCCESS){
        NRF_LOG_INFO(&amp;quot;m_conn_handle not ready: %d&amp;quot;, m_conn_handle);
        NRF_LOG_PROCESS();
      }
    }
}




static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    uint32_t err_code = NRF_SUCCESS;

    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GAP_EVT_DISCONNECTED:
            u8_device_state=DEVICE_GOtoLowpower;
            m_conn_handle = BLE_CONN_HANDLE_INVALID;
            send_log(&amp;quot;m_conn_handle DISCONNECTED&amp;quot;);
            send_log(&amp;quot;&amp;quot;);
            send_log(&amp;quot;&amp;quot;);
            // LED indication will be changed when advertising starts.
            break;

        case BLE_GAP_EVT_CONNECTED:
           	u8_device_state=DEVICE_SET;
           	// err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
           	// APP_ERROR_CHECK(err_code);
            m_conn_handle = p_ble_evt-&amp;gt;evt.gap_evt.conn_handle;
            NRF_LOG_INFO(&amp;quot;m_conn_handle CONNECTED : %d&amp;quot;, m_conn_handle);
            NRF_LOG_PROCESS();
            err_code = nrf_ble_qwr_conn_handle_assign(&amp;amp;m_qwr, m_conn_handle);
            APP_ERROR_CHECK(err_code);
            // SET TX POWER AFTER CONNECTING
	    	uint32_t err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_CONN, m_conn_handle, TX_POWER_LEVEL); 
	    	APP_ERROR_CHECK(err_code);
            break;

        // Other default cases after here not copy/pasted

        default:
            // No implementation needed.
            break;
    }
}





int main(void)
{
    uint8_t i=0;
    uint32_t err_code;
    bool erase_bonds;

    // Some initialisations before that I did not included...
  
    saadc_init();
    timers_init();
    power_management_init();

    // Some initialisations after here that I did not included...
   
    err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, m_advertising.adv_handle, TX_POWER_LEVEL);
    APP_ERROR_CHECK(err_code);

    u8_device_state=DEVICE_GOtoLowpower;

    // Enter main loop.
    for (;;){ 
 		switch(u8_device_state)
        {
          case DEVICE_CONNECTED :
            if(TimerTwo_IRQ &amp;amp;&amp;amp; m_conn_handle == NRF_SUCCESS)
              {
                send_log(&amp;quot;nrf_drv_saadc_sample&amp;quot;);
                nrf_drv_saadc_sample();
                TimerTwo_IRQ = 0; 
              }
              else{
                if(m_conn_handle != NRF_SUCCESS){
                  NRF_LOG_INFO(&amp;quot;m_conn_handle not ready !!! : %d&amp;quot;, m_conn_handle);
                  NRF_LOG_PROCESS();
                }
              }
            idle_state_handle();
        break; 

        case DEVICE_DISCONNECTED : 
        	idle_state_handle();
        break; 

        case DEVICE_SET :
			send_log(&amp;quot;------------------------------------------------------&amp;quot;);
			saadc_init();
			GPIO_init();
			accel_init();
			start_TimerTwo();
			send_log(&amp;quot;Device SET&amp;quot;);
			NRF_LOG_INFO(&amp;quot;m_conn_handle : %d&amp;quot;, m_conn_handle);
			NRF_LOG_PROCESS();
			u8_device_state=DEVICE_CONNECTED;
			break;

       	case DEVICE_GOtoLowpower :
			send_log(&amp;quot;Start DEVICE_GOtoLowpower&amp;quot;);
			stop_TimerTwo();
			send_log(&amp;quot;Timers stopped&amp;quot;);
			accel_deep_sleep();
			disable_spi();
			send_log(&amp;quot;before saadc_uninit&amp;quot;);
			saadc_uninit();
			send_log(&amp;quot;after saadc_uninit&amp;quot;);
			GPIO_lowpower();
			u8_device_state=DEVICE_DISCONNECTED;
			send_log(&amp;quot;End DEVICE_GOtoLowpower&amp;quot;);
        	break; 

       	default: 
       		break; 

        //nrf_pwr_mgmt_run();
    }
}
}


&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;info&amp;gt; app: m_conn_handle CONNECTED : 0       &amp;lt;--------------------- Start connection request
&amp;lt;info&amp;gt; app: ------------------------------------------------------
&amp;lt;info&amp;gt; app: Device SET
&amp;lt;info&amp;gt; app: m_conn_handle : 0       &amp;lt;--------------------- Connection made
&amp;lt;info&amp;gt; app: nrf_drv_saadc_sample       &amp;lt;--------------------- Perform SAADC sample
&amp;lt;info&amp;gt; app: u8_device_state: 0       &amp;lt;--------------------- Device connected
&amp;lt;info&amp;gt; app: NRF_DRV_SAADC_EVT_DONE: 0       &amp;lt;--------------------- Just a debug for me
&amp;lt;info&amp;gt; app: p_event-&amp;gt;type: 0       &amp;lt;--------------------- NRF_DRV_SAADC_EVT_DONE
&amp;lt;info&amp;gt; app: m_conn_handle: 0
&amp;lt;info&amp;gt; app: err_code: 13313       &amp;lt;--------------------- Waiting for the connected device receive the data
[......]
&amp;lt;info&amp;gt; app: nrf_drv_saadc_sample
&amp;lt;info&amp;gt; app: u8_device_state: 0
&amp;lt;info&amp;gt; app: NRF_DRV_SAADC_EVT_DONE: 0
&amp;lt;info&amp;gt; app: p_event-&amp;gt;type: 0
&amp;lt;info&amp;gt; app: m_conn_handle: 0
&amp;lt;info&amp;gt; app: err_code: 13313
&amp;lt;info&amp;gt; app: nrf_drv_saadc_sample
&amp;lt;info&amp;gt; app: u8_device_state: 0
&amp;lt;info&amp;gt; app: NRF_DRV_SAADC_EVT_DONE: 0
&amp;lt;info&amp;gt; app: p_event-&amp;gt;type: 0
&amp;lt;info&amp;gt; app: m_conn_handle: 0
&amp;lt;info&amp;gt; app: err_code: 0       &amp;lt;--------------------- Now the data are received in the connected device
[......]
&amp;lt;info&amp;gt; app: nrf_drv_saadc_sample
&amp;lt;info&amp;gt; app: u8_device_state: 0
&amp;lt;info&amp;gt; app: NRF_DRV_SAADC_EVT_DONE: 0
&amp;lt;info&amp;gt; app: p_event-&amp;gt;type: 0
&amp;lt;info&amp;gt; app: m_conn_handle: 0
&amp;lt;info&amp;gt; app: err_code: 0
&amp;lt;info&amp;gt; app: nrf_drv_saadc_sample
&amp;lt;info&amp;gt; app: m_conn_handle DISCONNECTED       &amp;lt;--------------------- Disconnected by the device
&amp;lt;info&amp;gt; app:
&amp;lt;info&amp;gt; app:
&amp;lt;info&amp;gt; app: Start DEVICE_GOtoLowpower
&amp;lt;info&amp;gt; app: Timers stopped
&amp;lt;info&amp;gt; app: before saadc_uninit
&amp;lt;info&amp;gt; app: after saadc_uninit
&amp;lt;info&amp;gt; app: End DEVICE_GOtoLowpower
&amp;lt;info&amp;gt; app: u8_device_state: 1       &amp;lt;--------------------- /!\ WARNING : I still receive data on saadc_callback, when this happen, I know next connection will fail to send data
&amp;lt;info&amp;gt; app: NRF_DRV_SAADC_EVT_DONE: 0
&amp;lt;info&amp;gt; app: p_event-&amp;gt;type: 0
&amp;lt;info&amp;gt; app: m_conn_handle not ready: 65535


&amp;lt;info&amp;gt; app: m_conn_handle CONNECTED : 0       &amp;lt;--------------------- Start a new connection request
&amp;lt;info&amp;gt; app: ------------------------------------------------------
&amp;lt;info&amp;gt; app: Device SET
&amp;lt;info&amp;gt; app: m_conn_handle : 0       &amp;lt;--------------------- Connection made
&amp;lt;info&amp;gt; app: nrf_drv_saadc_sample       &amp;lt;--------------------- Perform SAADC sample but never trigger saadc_callback
&amp;lt;info&amp;gt; app: nrf_drv_saadc_sample
&amp;lt;info&amp;gt; app: nrf_drv_saadc_sample
&amp;lt;info&amp;gt; app: nrf_drv_saadc_sample
&amp;lt;info&amp;gt; app: nrf_drv_saadc_sample
&amp;lt;info&amp;gt; app: nrf_drv_saadc_sample
&amp;lt;info&amp;gt; app: nrf_drv_saadc_sample
[.......]&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks for your help and feedbacks !&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;St&amp;eacute;phane&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/182106?ContentTypeID=1</link><pubDate>Mon, 15 Apr 2019 12:33:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:483ba17b-ab35-4bc2-a590-c5e74476709d</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Due to the Easter holiday you will have to expect a delay in replies, sorry for the inconvenience!&lt;/p&gt;
&lt;p&gt;I see that in your&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/45431/different-saadc_callback-for-channel"&gt;previous post&lt;/a&gt;&amp;nbsp;you have made some changes to your saadc_callback function, and that you&amp;#39;ve made further changes to that function in this case as well. It seems you have removed the SAADC_EVT_DONE event, which should be generated when the buffer is filled with samples, which is why I think you are experiencing the crash. Please make sure that this snippet is in your saadc_callback function, and see if that fixes your problem.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;if (p_event-&amp;gt;type == NRF_DRV_SAADC_EVT_DONE)
    {
        ret_code_t err_code;

        err_code = nrf_drv_saadc_buffer_convert(p_event-&amp;gt;data.done.p_buffer, SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);

        int i;
        NRF_LOG_INFO(&amp;quot;ADC event number: %d&amp;quot;, (int)m_adc_evt_counter);

        for (i = 0; i &amp;lt; SAMPLES_IN_BUFFER; i++)
        {
            NRF_LOG_INFO(&amp;quot;%d&amp;quot;, p_event-&amp;gt;data.done.p_buffer[i]);
        }
        m_adc_evt_counter++;
    }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards and happy Easter,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/181941?ContentTypeID=1</link><pubDate>Sat, 13 Apr 2019 16:13:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cc026b63-e55b-471b-8583-e92d2954224b</guid><dc:creator>StephaneJ</dc:creator><description>&lt;p&gt;According to &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/28644/sd_ble_gatts_value_set-returning-invalid-connection-handle-for-a-non-system-attribute"&gt;this post&lt;/a&gt; I have the same behaviour.&lt;/p&gt;
&lt;p&gt;The error appears when my&amp;nbsp;m_conn_handle = 0xFFFF&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;But I don&amp;#39;t think this is the real error. The real error is that sometimes, even if I call&amp;nbsp;nrf_drv_saadc_sample(), it never trigger the&amp;nbsp;saadc_callback() function.&lt;/p&gt;
&lt;p&gt;Could it be because I uninit the saadc every time I do a disconnection to enter in low power ?&lt;/p&gt;
&lt;p&gt;Every time I disconnect I do :&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void saadc_uninit(void)
{
    ret_code_t err_code;
    nrf_drv_saadc_abort();


    nrf_saadc_disable();
    while(NRF_SAADC-&amp;gt;STATUS == (SAADC_STATUS_STATUS_Busy &amp;lt;&amp;lt; SAADC_STATUS_STATUS_Pos))
      {}

    err_code = nrf_drv_saadc_channel_uninit(0);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_saadc_channel_uninit(1);
    APP_ERROR_CHECK(err_code);

    nrf_drv_saadc_uninit();
    NRF_SAADC-&amp;gt;INTENCLR = (SAADC_INTENCLR_END_Clear &amp;lt;&amp;lt; SAADC_INTENCLR_END_Pos);
    NVIC_ClearPendingIRQ(SAADC_IRQn);

}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;It seems more likely to be something to do with the saadc driver for me instead of the connection handler.&lt;/p&gt;
&lt;p&gt;Can this be related to &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/32929/the-saadc-of-issue-of-uninit"&gt;this&lt;/a&gt; or &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/29806/nrf52832-sdk14---saadc-calibration-issues/118302#118302"&gt;this&lt;/a&gt; ?&lt;/p&gt;
&lt;p&gt;Because most of the times I can predict when an error will occurs just by checking my debug from my previous disconnection. If during a disconnection, I see a debug log from&amp;nbsp;&lt;span&gt;saadc_callback&lt;/span&gt;&lt;span&gt;() showing while&amp;nbsp;i&amp;#39;m in&amp;nbsp;the DEVICE_GOtoLowpower case (or after), my next connection will not get data. I hope I make myself clear.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Here are the log :&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;case DEVICE_GOtoLowpower :
        send_log(&amp;quot;Start DEVICE_GOtoLowpower&amp;quot;);
        stop_TimerOne();
        stop_TimerTwo();
        send_log(&amp;quot;Timers stopped&amp;quot;);
        accel_deep_sleep();
        disable_spi();
        send_log(&amp;quot;before saadc_uninit&amp;quot;);
        //saadc_uninit();
        send_log(&amp;quot;after saadc_uninit&amp;quot;);
        GPIO_lowpower();
        u8_device_state=DEVICE_DISCONNECTED;
        send_log(&amp;quot;End DEVICE_GOtoLowpower&amp;quot;);&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;info&amp;gt; app: Start DEVICE_GOtoLowpower
&amp;lt;info&amp;gt; app: Timers stopped
&amp;lt;info&amp;gt; app: before saadc_uninit
&amp;lt;info&amp;gt; app: after saadc_uninit
&amp;lt;info&amp;gt; app: End DEVICE_GOtoLowpower
&amp;lt;info&amp;gt; app: LOG FROM saadc_callback here&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/181937?ContentTypeID=1</link><pubDate>Sat, 13 Apr 2019 14:00:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a159e38b-1a28-4a95-960f-15d1a3a0ca00</guid><dc:creator>StephaneJ</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/simonr"&gt;Simonr&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;As we discussed I&amp;#39;ve put debug in my source code and I checked the return value from&amp;nbsp;&lt;span&gt;ble_service_on_value_change().&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;When it&amp;#39;s working great it returns 0 obviously.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;But when it&amp;#39;s not working, I get 12290 (integer) so I suppose 0x3002&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;So&amp;nbsp;sd_ble_gatts_hvx() returns&amp;nbsp;0x3002&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;It&amp;#39;s :&amp;nbsp;BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;What does it mean to you ?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;By the way, I&amp;#39;m using SDK15.0.0 with Softdevice S132 v6&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks !&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/180198?ContentTypeID=1</link><pubDate>Thu, 04 Apr 2019 08:22:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3e517f12-ca72-4d60-98b2-bf77fae4ad3b</guid><dc:creator>StephaneJ</dc:creator><description>&lt;p&gt;Hi &lt;a href="https://devzone.nordicsemi.com/members/simonr"&gt;Simonr&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This problem is not a very big for us because it&amp;#39;s working 90% of the time or otherwise I can bypass it by deconnecting and reconnecting, this is why we have already some product assembled but I would still like to fix it.&lt;/p&gt;
&lt;p&gt;I will have other board not assembled shortly so I will be able to do proper debug.&lt;/p&gt;
&lt;p&gt;I will take a look at the return of&amp;nbsp;ble_service_on_value_change but so far, what I know is that I never enter the if statement after it is called.&lt;/p&gt;
&lt;p&gt;About my firmware update process, I use DFU with nRF Connect or nRF Toolbox.&lt;/p&gt;
&lt;p&gt;I will let you know here what I found !&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/180157?ContentTypeID=1</link><pubDate>Thu, 04 Apr 2019 06:50:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9f836c84-15f1-46a1-bbe4-5cb9fbebbee3</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;First, I want to say that development without the possibility to debug is very hard, and ill advised, and you should avoid this in the future.&lt;/p&gt;
&lt;p&gt;Next, what you should look at are return values from the ble_service_on_value_change() function, to see how are you updating your firmware? By using a debugger or bootloader? If you do have a debugger you could use the RTT logger, to read these return values. If not you should test this on a development kit first, before implementing it into your product.&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t think this is a race condition per say, but maybe an interrupt from some process with a higher priority. Again, debugging is the correct way of finding out what is happening, as me guessing what the issue is, is really inefficient.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/179972?ContentTypeID=1</link><pubDate>Wed, 03 Apr 2019 11:44:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cf0e2770-39ab-4464-aaf7-25731d37644c</guid><dc:creator>StephaneJ</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/simonr"&gt;Simonr&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;My product is now assembled so I cannot have access to the board, I can only update the firmware so it&amp;#39;s not super easy to put debug.&lt;/p&gt;
&lt;p&gt;Here is the basic process of my code, where do you want to debug ?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define TIMER_TWO_DURATION   		25
#define TIMER_TWO_TICKS_NB 			(TIMER_TWO_DURATION * 1000 / 31)

APP_TIMER_DEF(m_TimerTwo_id); 
uint16_t TimerTwo_IRQ;

uint8_t  value_data[2];


void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{
	err_code = nrf_drv_saadc_buffer_convert(p_event-&amp;gt;data.done.p_buffer, SAMPLES_IN_BUFFER);
    APP_ERROR_CHECK(err_code);

    val = p_event-&amp;gt;data.done.p_buffer[0];

    value_data[0]= (uint8_t) val;
    value_data[1]= (uint8_t) (val&amp;gt;&amp;gt;8);

	err_code = ble_service_on_value_change(m_conn_handle, &amp;amp;m_service, value_data);
        if (err_code != NRF_SUCCESS &amp;amp;&amp;amp;
            err_code != BLE_ERROR_INVALID_CONN_HANDLE &amp;amp;&amp;amp;
            err_code != NRF_ERROR_INVALID_STATE &amp;amp;&amp;amp;
            err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING &amp;amp;&amp;amp;
            err_code != NRF_ERROR_RESOURCES
           )
          {
            APP_ERROR_CHECK(err_code);
          }
}


uint32_t ble_service_on_value_change(uint16_t conn_handle, ble_service_t * p_service, uint8_t value_data[2])
{
    ret_code_t retval;
    ble_gatts_hvx_params_t params;
    uint16_t len = 2;

    memset(&amp;amp;params, 0, sizeof(params));
    params.type   = BLE_GATT_HVX_NOTIFICATION;
    params.handle = p_service-&amp;gt;value_char_handles.value_handle;
    params.p_data = value_data;
    params.p_len  = &amp;amp;len;

    return sd_ble_gatts_hvx(conn_handle, &amp;amp;params);
}



void TimerTwo_timeout_handler(void * p_context)
{
  UNUSED_PARAMETER(p_context);
  
  TimerTwo_IRQ = 1;
}



static void timers_init(void)
{
    // Initialize timer module.
    uint32_t err_code = app_timer_init();
    APP_ERROR_CHECK(err_code);

    // Initialize timer2 module.
    err_code = app_timer_create(&amp;amp;m_TimerTwo_id, APP_TIMER_MODE_REPEATED, TimerTwo_timeout_handler);
    APP_ERROR_CHECK(err_code);
}



void start_TimerTwo(void)
{
	uint32_t err_code;
	
	err_code = app_timer_start(m_TimerTwo_id, (uint32_t)TIMER_TWO_TICKS_NB, NULL);
	APP_ERROR_CHECK(err_code);
}



void stop_TimerTwo(void)
{
	uint32_t err_code;
	
	err_code = app_timer_stop(m_TimerTwo_id); /* stops the fifo timer */
	APP_ERROR_CHECK(err_code);
}



int main(void)
{
    // All initialisation here
    
    timers_init();
    u8_device_state=DEVICE_GOtoLowpower;

    // Enter main loop.
    for (;;)
    { 
 		switch(u8_device_state)
        {
	        case DEVICE_CONNECTED :
	            if(TimerTwo_IRQ)
	              {
	                nrf_drv_saadc_sample();
	                TimerTwo_IRQ = 0;       
	              }
	            idle_state_handle();
	        	break; 

	        case DEVICE_DISCONNECTED : 
	        	idle_state_handle();
	        	break; 

	        case DEVICE_SET :
				saadc_init();
				start_TimerTwo();
				u8_device_state=DEVICE_CONNECTED;
				break; 

	       case DEVICE_GOtoLowpower :
				stop_TimerTwo();
				u8_device_state=DEVICE_DISCONNECTED;
				break; 

	        default : 
	       		break;
	    }
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;What do you think about the race condition for the timer ? It doesn&amp;#39;t looks like it ?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks for your support !&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/179945?ContentTypeID=1</link><pubDate>Wed, 03 Apr 2019 10:42:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:552fc562-4a48-4fbd-8cc7-669e045d9dc6</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Can you try debugging the nRF, see where the notifications are sent, and what they return. Can you print the log whenever the timer sending notifications triggers, to see what value it sends in the log.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/179894?ContentTypeID=1</link><pubDate>Wed, 03 Apr 2019 07:53:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e0344b07-139c-4eab-b075-615b1cc8368b</guid><dc:creator>StephaneJ</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/simonr"&gt;Simonr&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;do not pay attention to my previous answer about changing the&amp;nbsp;&lt;span&gt;TIMER_ONE_DURATION. I was changing the wrong timer........&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I tested again this morning, when I set the timer to 35 it failed after 7 tries.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I tested with a timer 40, after 20 tries it did not failed.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Now my timer is set to 25.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;One new thing, to check if the issue is coming from the timer (maybe not started or whatever), I set a value to 0 after a new connection then in my timer condition, I increase this value and I send it in my Characteristic.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Now I read this value before subscribing to the Notification then I subscribe to my Characteristic.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;When&amp;nbsp;everything is working great the first time I read the value I get approximately 27&amp;nbsp;every time,&amp;nbsp;so a little bit less than one second between the connection is made and just before the subscription. After the subscription I see the value increasing as the timer is fired and my subscription to the notification is successfully made.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;But when it&amp;#39;s not working, the value is not 27&amp;nbsp;but usually 54 (so exactly the double). And the subscription to notification is not working.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Now when it&amp;#39;s not working, I read again the value, and this is the exact same value I get. This make me think that the timer is not fired anymore. Could this be because it&amp;#39;s started twice at the same time or something like that and it crash ?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Here is an illustration of when it&amp;#39;s working and when it&amp;#39;s not working on the console.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/8611.OK.png" /&gt;&lt;/p&gt;
&lt;p&gt;---&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/7853.KO.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;EDIT : could this be the same issue ?&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/9179/app_timer-triggering-twice"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/9179/app_timer-triggering-twice&lt;/a&gt;&amp;nbsp;I don&amp;#39;t understand exactly how to fix this and where to put delay.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/179836?ContentTypeID=1</link><pubDate>Tue, 02 Apr 2019 16:28:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c6c13880-34c9-49a0-bf32-16b28d5b8531</guid><dc:creator>StephaneJ</dc:creator><description>&lt;p&gt;As an illustration, here is what my device looks like when it&amp;#39;s working, I&amp;#39;m connected&amp;nbsp;and I see value on&amp;nbsp;my Characteristic :&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/4667.OK.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Exact same code, after few tries, here is what it look like. I&amp;#39;m connected but this time I see no value on my Characteristic :&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/KO.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/179828?ContentTypeID=1</link><pubDate>Tue, 02 Apr 2019 15:56:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:428d7ebf-c972-48d3-b584-9447f1158b67</guid><dc:creator>StephaneJ</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/simonr"&gt;Simonr&lt;/a&gt; I performed new test just by changing the&amp;nbsp;TIMER_ONE_DURATION value. I tried with values 99, 66, 40, 35, 33, 25.&lt;/p&gt;
&lt;p&gt;In all cases, in opposition to what I stated in my first post, it fails after an average of 3 tries.&lt;/p&gt;
&lt;p&gt;But &lt;strong&gt;it&amp;#39;s not a connection issue&lt;/strong&gt;, because in all cases, I succeed to connect to the device. It&amp;#39;s just that I do not succeed to subscribe to the notification after connecting to my device.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/179794?ContentTypeID=1</link><pubDate>Tue, 02 Apr 2019 13:52:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8a2f31c5-728f-452e-b6c9-9618eb4f4ce9</guid><dc:creator>StephaneJ</dc:creator><description>&lt;p&gt;Ok I will try other value for example 35ms and 50ms and let you know here. Even if this is not a solution because I cannot go slower than 30ms for my notification.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/179792?ContentTypeID=1</link><pubDate>Tue, 02 Apr 2019 13:50:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2134e984-44c9-4b92-ac38-7954aaadfa4c</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;No, I think you might have to make the number bigger than 30ms. As the application has to be able to connect before the notification is sent. Have you tried with any interval values between 30 and 90ms?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/179742?ContentTypeID=1</link><pubDate>Tue, 02 Apr 2019 11:49:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c92f2cc9-86cc-43d7-aeed-a05e663d0977</guid><dc:creator>StephaneJ</dc:creator><description>&lt;p&gt;Hi !&lt;/p&gt;
&lt;p&gt;So according to what you say, if I understand correctly, do you think that if I change my notification timer from 30ms to 20ms for example this can avoid this unwanted behavior ?&lt;/p&gt;
&lt;p&gt;I will take a look at the central side but this is standard as far as I know for my Android and MacBook.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update timer speed once connected</title><link>https://devzone.nordicsemi.com/thread/179684?ContentTypeID=1</link><pubDate>Tue, 02 Apr 2019 09:17:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ca222559-4f72-4f7d-a91f-10f62d327f91</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;It should be fine having set the connection interval to 7.5ms, however this is on the peripheral side, which the central side doesn&amp;#39;t have to &amp;quot;agree&amp;quot; with. Are you able to find the central side connection intervals? If you have a log with timestamps for example, you&amp;#39;ll be able to see how long the device actually uses to connect.&lt;/p&gt;
&lt;p&gt;For most Android phones the minimum connection interval is 25ms or so (30ms for iPhones), which is cutting it close to your notification interval of 30ms. I suspect you might have to increase the notification interval somewhat to make this compatible to any device.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>