<?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>sd_ble_gap_disconnect error</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/26195/sd_ble_gap_disconnect-error</link><description>Hello, 
 I have read a lot posts which has the same title unfortunately I am still unable to solve my problem. I am using pca10028, s110, SDK 6. Code is based on BLE_app_uart exapmle. This is my main function: 
 int main(void)
{
 timers_init(); </description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 24 Oct 2017 10:29:18 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/26195/sd_ble_gap_disconnect-error" /><item><title>RE: sd_ble_gap_disconnect error</title><link>https://devzone.nordicsemi.com/thread/103169?ContentTypeID=1</link><pubDate>Tue, 24 Oct 2017 10:29:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:851eecd1-83e9-4d7c-b02d-113f2dcfb090</guid><dc:creator>Chocol8</dc:creator><description>&lt;p&gt;Thank you. This helps a lot!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sd_ble_gap_disconnect error</title><link>https://devzone.nordicsemi.com/thread/103168?ContentTypeID=1</link><pubDate>Tue, 24 Oct 2017 10:26:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dfa7c43a-70d6-45d4-9e24-8c866108a430</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Yes, you can set &lt;code&gt;m_conn_handle = BLE_CONN_HANDLE_INVALID&lt;/code&gt; after calling &lt;code&gt;sd_ble_gap_disconnect()&lt;/code&gt;. By default this is set in &lt;code&gt;on_ble_evt()&lt;/code&gt; handler, when a &lt;code&gt;BLE_GAP_EVT_DISCONNECTED&lt;/code&gt; event is received, but this event might come after your code has had time to call &lt;code&gt;sd_ble_gap_disconnect()&lt;/code&gt; multiple times. By setting it right after starting diconnect procedure, you make sure disconnect function is not called again.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sd_ble_gap_disconnect error</title><link>https://devzone.nordicsemi.com/thread/103170?ContentTypeID=1</link><pubDate>Tue, 24 Oct 2017 09:49:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4c913b4e-698d-43e6-9c5b-5dd576bbf56e</guid><dc:creator>Chocol8</dc:creator><description>&lt;p&gt;Hello, Jorgen. Thank you for coming in help. Before I have read your comment I have tried various things to solve it and came across this question once again: &lt;a href="https://devzone.nordicsemi.com/question/143832/wrong-passkey-leads-to-crash-in-ble_app_gls-example/"&gt;devzone.nordicsemi.com/.../&lt;/a&gt; Joris Roussel proposed solution by inserting &lt;code&gt;m_conn_handle = BLE_CONN_HANDLE_INVALID;&lt;/code&gt; after &lt;code&gt;sd_ble_gap_disconnect()&lt;/code&gt;. While debugging it like this I have not received error.&lt;/p&gt;
&lt;p&gt;Now I understand why placing a break point makes no sense. Break point at statement if &lt;code&gt;(err_code != NRF_SUCCESS)&lt;/code&gt;shows that m_conn_handle is &lt;code&gt;0x0000&lt;/code&gt; which is not equal to &lt;code&gt;BLE_CONN_HANDLE_INVALID&lt;/code&gt; &lt;code&gt;(0xFFFF)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;It&amp;#39;s my unskillfulnes fault by saying that NRF_UART application does not show. It is unnecessery information.&lt;/p&gt;
&lt;p&gt;I would like to hear from you if setting &lt;code&gt;m_conn_handle = BLE_CONN_HANDLE_INVALID&lt;/code&gt; after &lt;code&gt;sd_ble_gap_disconnect()&lt;/code&gt;  is correct solution.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sd_ble_gap_disconnect error</title><link>https://devzone.nordicsemi.com/thread/103167?ContentTypeID=1</link><pubDate>Tue, 24 Oct 2017 08:42:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f6ff554c-30fc-4ed6-a13d-489dd9599529</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Most likely, your application tries to call &lt;code&gt;sd_ble_gap_disconnect()&lt;/code&gt; multiple times before &lt;code&gt;m_conn_handle = BLE_CONN_HANDLE_INVALID&lt;/code&gt; is set, after &lt;code&gt;ble_tx_complete = 1&lt;/code&gt; is set. You should set the breakpoint on the &lt;code&gt;if (err_code != NRF_SUCCESS)&lt;/code&gt; check. When you set the breakpoint on &lt;code&gt;return err_code;&lt;/code&gt;, you will only break when a non-success error code is received. Can you try to set a flag after calling disconnect, to avoid calling this multiple times? What do you mean by &lt;em&gt;&amp;quot;Application does not show it was disconnected to board&amp;quot;&lt;/em&gt;? Only that it does not print disconnect to UART? If you get a hardfault from calling disconnect function multiple times, the application will not continue.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sd_ble_gap_disconnect error</title><link>https://devzone.nordicsemi.com/thread/103166?ContentTypeID=1</link><pubDate>Tue, 24 Oct 2017 06:59:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6645065b-2840-4220-921d-b35fb8cea544</guid><dc:creator>Chocol8</dc:creator><description>&lt;p&gt;I have tried this approach:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{
          if (ble_tx_complete == 1)						
 {
	err_code = sd_ble_gap_disconnect(m_conn_handle, 
         BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
		 if (err_code != NRF_SUCCESS)
			 {
			  return err_code;
			 }
	 }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Application does not show it was disconnected to board. Debugging still get err_code =0x00000008 which led to hard fault handler.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>