<?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>NRF52 reconnection problem</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/31124/nrf52-reconnection-problem</link><description>Hello. I am using ble_app_uart from sdk14.2. I use pca100401, softdevice s132. 
 Advertising is generated using timer RTC. Board advertises and stops advertising without errors if I it starts and I do not connect to it. However, when trying to reconnect</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 07 Mar 2018 07:08:20 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/31124/nrf52-reconnection-problem" /><item><title>RE: NRF52 reconnection problem</title><link>https://devzone.nordicsemi.com/thread/123169?ContentTypeID=1</link><pubDate>Wed, 07 Mar 2018 07:08:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bf47d776-f217-4d81-a60b-40bfd7723c88</guid><dc:creator>Chocol8</dc:creator><description>&lt;p&gt;Thanks to&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/edvin-holmseth"&gt;Edvin&lt;/a&gt;&amp;nbsp;problem was solved. He found out that by default, a variable is set in advertising init. There is a parameter called:&amp;nbsp;&lt;span&gt;init.config.ble_adv_in_disconnect_disabled which is set to false (0) by default. In ble_advertising.c there is an advertising event handler called&amp;nbsp;ble_advertising_on_ble_evt() which is called in parallel with the eventhandler in main.c.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The event handler in ble_advertising.c has the following:&amp;nbsp;&lt;pre class="ui-code" data-mode="text"&gt; // Upon disconnection, whitelist will be activated and direct advertising is started.
        case BLE_GAP_EVT_DISCONNECTED:
            on_disconnected(p_advertising, p_ble_evt);
            break;&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Inside on_disconnected(...) it will call ble_advertising_start() if (p_advertising-&amp;gt;adv_modes_config.ble_adv_on_disconnect_disabled == false) :&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;    if (p_ble_evt-&amp;gt;evt.gap_evt.conn_handle == p_advertising-&amp;gt;current_slave_link_conn_handle &amp;amp;&amp;amp;
        p_advertising-&amp;gt;adv_modes_config.ble_adv_on_disconnect_disabled == false)
    {
       ret = ble_advertising_start(p_advertising, BLE_ADV_MODE_DIRECTED);
       if ((ret != NRF_SUCCESS) &amp;amp;&amp;amp; (p_advertising-&amp;gt;error_handler != NULL))
       {
           p_advertising-&amp;gt;error_handler(ret);
       }
    }&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Since this is called at once when the disconnect happened, it would always be called before the timer from main decided to start advertising.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;To solve this Edvin suggested to start advertising right after disconnection or to&amp;nbsp;change ble_adv_on_disconnect_disabled in the advertising_init() function. Then advertising_init() looks like this:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void advertising_init(void)
{
    uint32_t               err_code;
    ble_advertising_init_t init;

    memset(&amp;amp;init, 0, sizeof(init));

    init.advdata.name_type          = BLE_ADVDATA_FULL_NAME;
    init.advdata.include_appearance = false;
    init.advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;

    init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    init.srdata.uuids_complete.p_uuids  = m_adv_uuids;

    init.config.ble_adv_fast_enabled  = true;
    init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
    init.config.ble_adv_fast_timeout  = APP_ADV_TIMEOUT_IN_SECONDS;
    
    init.config.ble_adv_on_disconnect_disabled = true;

    init.evt_handler = on_adv_evt;

    err_code = ble_advertising_init(&amp;amp;m_advertising, &amp;amp;init);
    APP_ERROR_CHECK(err_code);

    ble_advertising_conn_cfg_tag_set(&amp;amp;m_advertising, APP_BLE_CONN_CFG_TAG);
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 reconnection problem</title><link>https://devzone.nordicsemi.com/thread/123047?ContentTypeID=1</link><pubDate>Tue, 06 Mar 2018 12:05:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:46b90d9e-aea7-4f3a-8286-5cbf2b6d7c3a</guid><dc:creator>Chocol8</dc:creator><description>&lt;p&gt;Yes, you are correct,&amp;nbsp;&lt;span&gt;ble_advertising_init() is used once. Ok, I will do this.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 reconnection problem</title><link>https://devzone.nordicsemi.com/thread/123043?ContentTypeID=1</link><pubDate>Tue, 06 Mar 2018 12:01:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fb578fab-ff1c-44da-a8ed-437d383e05b7</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;And you only use ble_advertising_init() once? Yes. You could do that. It would be great if you link to this case in the private case, so that I&amp;nbsp;can pick it up.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 reconnection problem</title><link>https://devzone.nordicsemi.com/thread/123039?ContentTypeID=1</link><pubDate>Tue, 06 Mar 2018 11:43:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3046b878-7894-412f-bc69-ca2a07b1fca1</guid><dc:creator>Chocol8</dc:creator><description>&lt;p&gt;Thank you for suggestions.&amp;nbsp;&lt;span&gt;m_advertising&amp;nbsp; is defined only in main.c like this:&amp;nbsp;&amp;nbsp;&lt;strong&gt;BLE_ADVERTISING_DEF(m_advertising);&amp;nbsp;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Function &lt;strong&gt;err_code = ble_advertising_start(&amp;amp;m_advertising, BLE_ADV_MODE_FAST); &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt; APP_ERROR_CHECK(err_code);&amp;nbsp;&lt;/strong&gt;is being used only in main() function.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Would it be easier if I upload it to a private case study?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;Best regards&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 reconnection problem</title><link>https://devzone.nordicsemi.com/thread/123017?ContentTypeID=1</link><pubDate>Tue, 06 Mar 2018 10:37:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:00100397-54fe-4dcc-ab88-394b5eb4c0b6</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Ok, so the function ble_advertising_start() returns 8 [NRF_ERROR_INVALID_STATE].&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The app_timer_stop_all() function does not seem to stop the timer that the softdevice uses, only the ones used in app_timer, so that should not be the problem. I tried to use app_timer_stop_all() right before ble_advertising_start(), and that works fine.&lt;/p&gt;
&lt;p&gt;NRF_ERROR_INVALID_STATE usually indicates that ble_advertising_init() has not been called before the ble_advertising_start() function. Since you are able to start advertising before the connection, this is obviously not the case here. Have you changed anything in your m_advertising variable while&amp;nbsp;being in the connection?&lt;/p&gt;
&lt;p&gt;It is a bit difficult to say only from the code snippets, but is the ble_advertising_start() that is called and returns the error the one in your main() function, or is it called from somewhere else? Maybe it is being called twice?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 reconnection problem</title><link>https://devzone.nordicsemi.com/thread/122861?ContentTypeID=1</link><pubDate>Mon, 05 Mar 2018 14:45:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d7c79574-d990-4bba-964b-b47e2f753b1b</guid><dc:creator>Chocol8</dc:creator><description>&lt;p&gt;Thank you for taking time to investigate my problem. I have deleted few line of code that is why RTT shows error in main.c 1418. This is the same error that occurs at 1416. They both bring this to RTT&lt;strong&gt;:&amp;nbsp;&amp;lt;error&amp;gt; app: ERROR 8 [NRF_ERROR_INVALID_STATE] at ..\..\..\main.c:1418&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Moreover, I have tried to change &lt;strong&gt;app_timer_stop_all();&lt;/strong&gt;&amp;nbsp;&amp;nbsp;to just one timer that I use. This change have not solved my problem.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I have tried your proposal to use:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;err_code = app_timer_stop_all();
APP_ERROR_CHECK(err_code);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The result is same as it was before. RTT says that error stems from main.c 1418.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 reconnection problem</title><link>https://devzone.nordicsemi.com/thread/122848?ContentTypeID=1</link><pubDate>Mon, 05 Mar 2018 14:12:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:497effc7-1d30-4cf3-85ab-2816aadf1e53</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I think you posted the wrong screenshot after:&lt;/p&gt;
&lt;p&gt;&amp;quot;&lt;em&gt;This is the error I receive in J-link RTT viewer&lt;/em&gt;&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Can you please try to check the return on app_timer_stop_all();&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;err_code = app_timer_stop_all();
APP_ERROR:CHECK(err_code);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Aslo, what is the RTT printing on line 1416 in main?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>