<?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>Enable notifications for NUS and another service in BLE Central device avoiding NRF_ERROR_BUSY</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/34914/enable-notifications-for-nus-and-another-service-in-ble-central-device-avoiding-nrf_error_busy</link><description>Hello everyone, 
 I&amp;#39;m developing an application for boards with NRF52832, Softdevice S132 3.00 and SDK 12.3.0. 
 The network architecture consists of: 
 
 one peripheral board (slave) with NUS and BAS services 
 one central plus peripheral board (master</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 31 May 2018 13:41:37 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/34914/enable-notifications-for-nus-and-another-service-in-ble-central-device-avoiding-nrf_error_busy" /><item><title>RE: Enable notifications for NUS and another service in BLE Central device avoiding NRF_ERROR_BUSY</title><link>https://devzone.nordicsemi.com/thread/134203?ContentTypeID=1</link><pubDate>Thu, 31 May 2018 13:41:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:95b39740-2f1a-4e2c-b9ed-cac6aefaf9ed</guid><dc:creator>Bruno Santamaria</dc:creator><description>&lt;p&gt;I think that might be it. I replaced &lt;strong&gt;ble_nus_c.c&lt;/strong&gt; from the SDK with a modified copy which includes the message-buffer technique used in the other services. So far, it works, with no undesired effect.&lt;/p&gt;
&lt;p&gt;I attach the code to this message, for anyone having the same problem. I think it would be reasonable to patch it as well in the SDK if no one reports any side-effect.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/ble_5F00_nus_5F00_c.c"&gt;devzone.nordicsemi.com/.../ble_5F00_nus_5F00_c.c&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Enable notifications for two services in BLE Central device avoiding NRF_ERROR_BUSY</title><link>https://devzone.nordicsemi.com/thread/134129?ContentTypeID=1</link><pubDate>Thu, 31 May 2018 07:53:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ed84bbc6-b538-401d-97b9-0a3b5012e868</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;You might be on to something here. It seems like there is a chance of GATTC write collisions in the NUS client implementation.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I would recommend implementing your own version with a buffer.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Enable notifications for two services in BLE Central device avoiding NRF_ERROR_BUSY</title><link>https://devzone.nordicsemi.com/thread/134070?ContentTypeID=1</link><pubDate>Wed, 30 May 2018 14:37:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4cf3f580-66cc-4571-b8c7-79c9da6d76f3</guid><dc:creator>Bruno Santamaria</dc:creator><description>&lt;p&gt;Thank you for your answer, Martin. You understood it correctly.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve taken a look at the example you mention, although&amp;nbsp;for SDK 12.3.0. I&amp;#39;ve seen that for the two services (HRS and BAS) it uses a buffer that waits for the&amp;nbsp;&lt;span&gt;BLE_GATTC_EVT_WRITE_RSP response from the SD. It is programmed independently inside the central-service c-files (ble_bas_c.c and ble_hrs_c.c). It looks great and it&amp;#39;s independent of the configuration of main.c.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;It seems that my problem lays on the NUS central service. Its structure differs from the one of HRS, BAS and the rest of standard service and doesn&amp;#39;t implement the buffer to enable CCCDs. Do you know if there is any reason for this?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;For example, the cccd_configure functions of NUS...&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief Function for creating a message for writing to the CCCD.
 */
static uint32_t cccd_configure(uint16_t conn_handle, uint16_t cccd_handle, bool enable)
{
    uint8_t buf[BLE_CCCD_VALUE_LEN];

    buf[0] = enable ? BLE_GATT_HVX_NOTIFICATION : 0;
    buf[1] = 0;

    const ble_gattc_write_params_t write_params = {
        .write_op = BLE_GATT_OP_WRITE_REQ,
        .flags    = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE,
        .handle   = cccd_handle,
        .offset   = 0,
        .len      = sizeof(buf),
        .p_value  = buf
    };

    return sd_ble_gattc_write(conn_handle, &amp;amp;write_params);
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;...and BAS...&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief Function for creating a message for writing to the CCCD.
 */
static uint32_t cccd_configure(uint16_t conn_handle, uint16_t handle_cccd, bool notification_enable)
{
    NRF_LOG_DEBUG(&amp;quot;Configuring CCCD. CCCD Handle = %d, Connection Handle = %d\r\n&amp;quot;,
                                                            handle_cccd,conn_handle);

    tx_message_t * p_msg;
    uint16_t       cccd_val = notification_enable ? BLE_GATT_HVX_NOTIFICATION : 0;

    p_msg              = &amp;amp;m_tx_buffer[m_tx_insert_index++];
    m_tx_insert_index &amp;amp;= TX_BUFFER_MASK;

    p_msg-&amp;gt;req.write_req.gattc_params.handle   = handle_cccd;
    p_msg-&amp;gt;req.write_req.gattc_params.len      = WRITE_MESSAGE_LENGTH;
    p_msg-&amp;gt;req.write_req.gattc_params.p_value  = p_msg-&amp;gt;req.write_req.gattc_value;
    p_msg-&amp;gt;req.write_req.gattc_params.offset   = 0;
    p_msg-&amp;gt;req.write_req.gattc_params.write_op = BLE_GATT_OP_WRITE_REQ;
    p_msg-&amp;gt;req.write_req.gattc_value[0]        = LSB_16(cccd_val);
    p_msg-&amp;gt;req.write_req.gattc_value[1]        = MSB_16(cccd_val);
    p_msg-&amp;gt;conn_handle                         = conn_handle;
    p_msg-&amp;gt;type                                = WRITE_REQ;

    tx_buffer_process();
    return NRF_SUCCESS;
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;What do you recommend? I can&amp;#39;t alter the SDK files in order to keep other projects working.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Should I create my own version of ble_nus_c.c using the structure and behavior of BAS and the other services? Would that suffice for this purpose of enabling two CCCDs?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Enable notifications for two services in BLE Central device avoiding NRF_ERROR_BUSY</title><link>https://devzone.nordicsemi.com/thread/134055?ContentTypeID=1</link><pubDate>Wed, 30 May 2018 13:53:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6a731bbf-bf03-44a0-9ce9-f46ef7232a1f</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;So if I understand you correctly the problem is that you can&amp;#39;t enable two CCCDs back-to-back because you get the busy error when you write to the second CCCD attribute?&lt;/p&gt;
&lt;p&gt;I advise you to have a look at the &lt;a title="BLE Heart Rate Collector Example" href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.0.0/ble_sdk_app_hrc.html?cp=4_0_0_4_1_0_1"&gt;BLE Heart Rate Collector Example&lt;/a&gt;. It shows how a central can enable CCCDs on two or more characteristics one after another. Shortly explained, the example sets up a buffer of &amp;quot;messages&amp;quot; to be written and then processes this buffer on every successive BLE_GATTC_EVT_WRITE_RSP event.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>