<?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_gattc_write not working</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/40549/sd_ble_gattc_write-not-working</link><description>Hi, 
 I am currently trying send value to a write characteristic of the server of a custom central device with a nrf52832 peripheral device. I have been able to connect with NRFConnect to the central device and write the characteristic and connect to</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 20 Nov 2018 08:39:37 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/40549/sd_ble_gattc_write-not-working" /><item><title>RE: sd_ble_gattc_write not working</title><link>https://devzone.nordicsemi.com/thread/158118?ContentTypeID=1</link><pubDate>Tue, 20 Nov 2018 08:39:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b5901841-bd3a-4439-a256-64a45bec8a39</guid><dc:creator>AndreasF</dc:creator><description>&lt;p&gt;Hi.&lt;/p&gt;
&lt;p&gt;Sorry for the late reply.&lt;/p&gt;
&lt;p&gt;I did not notice you tried to write &lt;strong&gt;from the peripheral to the central&lt;/strong&gt;, the API &lt;strong&gt;ble_nus_c_string_send()&lt;/strong&gt; is for the central UART. Can you try the equivalent &lt;strong&gt;API&lt;/strong&gt; for the peripheral UART, &lt;strong&gt;ble_nus_string_send()&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;There is more documentation on the&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/support-private/support/217979/%20http:/infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.2.0%2Fgroup__ble__nus.html&amp;amp;cp=4_0_0_6_3_23"&gt;&lt;strong&gt;Nordic UART Service&lt;/strong&gt; &lt;strong&gt;API&lt;/strong&gt; here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Best regards.&lt;/p&gt;
&lt;p&gt;Andreas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sd_ble_gattc_write not working</title><link>https://devzone.nordicsemi.com/thread/157768?ContentTypeID=1</link><pubDate>Fri, 16 Nov 2018 15:10:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:72f6a522-c7b9-4827-aca2-bbb3d17f7f0d</guid><dc:creator>jf.chenier</dc:creator><description>&lt;p&gt;I am using the APP_ERROR_CHECK macro to make sure there is no error returned by the&amp;nbsp;ble_nus_c_string_send function. The function is always returning&amp;nbsp;NRF_SUCCESS.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sd_ble_gattc_write not working</title><link>https://devzone.nordicsemi.com/thread/157764?ContentTypeID=1</link><pubDate>Fri, 16 Nov 2018 14:45:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5892671b-c1b5-4106-b498-a4b0cd1b6523</guid><dc:creator>AndreasF</dc:creator><description>&lt;p&gt;Hi.&lt;/p&gt;
&lt;p&gt;Have you tried to debug when you attempt to write?&lt;/p&gt;
&lt;p&gt;If &lt;strong&gt;ble_nus_c_string_send&lt;/strong&gt; is unsuccessful it should trigger an error&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint32_t ble_nus_c_string_send(ble_nus_c_t * p_ble_nus_c, uint8_t * p_string, uint16_t length)
{
    VERIFY_PARAM_NOT_NULL(p_ble_nus_c);

    if (length &amp;gt; BLE_NUS_MAX_DATA_LEN)
    {
        NRF_LOG_WARNING(&amp;quot;Content too long.&amp;quot;);
        return NRF_ERROR_INVALID_PARAM;
    }
    if (p_ble_nus_c-&amp;gt;conn_handle == BLE_CONN_HANDLE_INVALID)
    {
        NRF_LOG_WARNING(&amp;quot;Connection handle invalid.&amp;quot;);
        return NRF_ERROR_INVALID_STATE;
    }

    ble_gattc_write_params_t const write_params =
    {
        .write_op = BLE_GATT_OP_WRITE_CMD,
        .flags    = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE,
        .handle   = p_ble_nus_c-&amp;gt;handles.nus_rx_handle,
        .offset   = 0,
        .len      = length,
        .p_value  = p_string
    };

    return sd_ble_gattc_write(p_ble_nus_c-&amp;gt;conn_handle, &amp;amp;write_params);
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;As you can see in &lt;strong&gt;ble_nus_c.c, &lt;/strong&gt;check if you get either NRF_ERROR_INVALID_PARAM or NRF_ERROR_INVALID_STATE when you try to debug.&lt;/p&gt;
&lt;p&gt;- Andreas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>