<?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>Streaming SAADC data (16kHz sampling rate) over BLE</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/48092/streaming-saadc-data-16khz-sampling-rate-over-ble</link><description>Hi there, 
 I&amp;#39;m currently working on getting a streaming application running which is supposed to sample some audio at 16kHz and send it (uncompressed) to a central device via BLE. 
 Current Status, what works: The SAADC is configured with a double buffer</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 24 Dec 2020 16:51:27 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/48092/streaming-saadc-data-16khz-sampling-rate-over-ble" /><item><title>RE: Streaming SAADC data (16kHz sampling rate) over BLE</title><link>https://devzone.nordicsemi.com/thread/286570?ContentTypeID=1</link><pubDate>Thu, 24 Dec 2020 16:51:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7b8af72d-d219-4625-99e1-ddb7bc628d5c</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;I looked at my older 14.2 code and use a slightly different test:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    do
    {
        uint16_t length = (uint16_t)index;
        err_code = ble_nus_string_send(&amp;amp;m_nus, data_array, &amp;amp;length);
        if ( (err_code != NRF_ERROR_INVALID_STATE) &amp;amp;&amp;amp; (err_code != NRF_ERROR_BUSY) )
        {
            APP_ERROR_CHECK(err_code);
        }
    } while (err_code == NRF_ERROR_BUSY);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;What are the BLE settings and SoftDevice version?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Streaming SAADC data (16kHz sampling rate) over BLE</title><link>https://devzone.nordicsemi.com/thread/286539?ContentTypeID=1</link><pubDate>Thu, 24 Dec 2020 06:54:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c9e1cf21-9f9f-4336-bf97-dcb7598a0d6d</guid><dc:creator>usmanmehmood55</dc:creator><description>&lt;p&gt;Hi Hmolesworth&lt;/p&gt;
&lt;p&gt;Thank you for the information.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;My SAADC callback function looks like this:&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)
{
    if (p_event-&amp;gt;type == NRF_DRV_SAADC_EVT_DONE)
    {
        ret_code_t err_code;
        uint16_t value[SAADC_SAMPLES_IN_BUFFER];
        uint16_t bytes_to_send;
        
        err_code = nrf_drv_saadc_buffer_convert(p_event-&amp;gt;data.done.p_buffer, SAADC_SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);

        uint8_t nus_string[50];

        bytes_to_send = sprintf(nus_string, &amp;quot;%d %d&amp;quot;, data.done.p_buffer[0], data.done.p_buffer[1]);
        err_code = ble_nus_data_send(&amp;amp;m_nus, nus_string, &amp;amp;bytes_to_send, m_conn_handle);

        if ((err_code != NRF_ERROR_INVALID_STATE) &amp;amp;&amp;amp; (err_code != NRF_ERROR_NOT_FOUND))
        {
            APP_ERROR_CHECK(err_code);
        }
	
        m_adc_evt_counter++;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;It&amp;#39;s very similar to your pseudocode. But it fails only after a few seconds. I reached a max of 420Hz by increasing the samples in buffer to 24 (instead of 2), sending the 10 samples in one string, and then calling&amp;nbsp;&lt;em&gt;ble_nus_data_send&lt;/em&gt; again in the very next line and sending 10 more samples in a string.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So my code became something like this&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)
{
    if (p_event-&amp;gt;type == NRF_DRV_SAADC_EVT_DONE)
    {
        ret_code_t err_code;
        uint16_t value[SAADC_SAMPLES_IN_BUFFER];
        uint16_t bytes_to_send;

        err_code = nrf_drv_saadc_buffer_convert(p_event-&amp;gt;data.done.p_buffer, SAADC_SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);

        for (int i = 0; i &amp;lt; SAADC_SAMPLES_IN_BUFFER; i++)
        {
            if (p_event-&amp;gt;data.done.p_buffer[i] &amp;lt;= 0)
            {
                value[i] = 0;
            }
            else
            {
                value[i] = p_event-&amp;gt;data.done.p_buffer[i];
            }
        }

        uint8_t nus_string[50];

        bytes_to_send = sprintf(nus_string, &amp;quot;%d %d %d %d %d %d %d %d %d %d&amp;quot;, value[0], value[1], value[2], value[3], value[4], value[5], value[6], value[7], value[8], value[9]);
        err_code = ble_nus_data_send(&amp;amp;m_nus, nus_string, &amp;amp;bytes_to_send, m_conn_handle);

        bytes_to_send = sprintf(nus_string, &amp;quot;%d %d %d %d %d %d %d %d %d %d&amp;quot;, value[10], value[11], value[12], value[13], value[14], value[15], value[16], value[17], value[18], value[19]);
        err_code = ble_nus_data_send(&amp;amp;m_nus, nus_string, &amp;amp;bytes_to_send, m_conn_handle);

        if ((err_code != NRF_ERROR_INVALID_STATE) &amp;amp;&amp;amp; (err_code != NRF_ERROR_NOT_FOUND))
        {
            if (data_sent_flag == 0)
            {
                data_sent_count = m_adc_evt_counter;
            }
            data_sent_flag = 1;
            if (err_code == NRF_SUCCESS)
            {
                // NRF_LOG_INFO(&amp;quot;Packet %d sent since %d.\n&amp;quot;, m_adc_evt_counter - data_sent_count, data_sent_count); //---------------------------UART
            }
            APP_ERROR_CHECK(err_code);
        }
        m_adc_evt_counter++;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;What am I missing here?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Streaming SAADC data (16kHz sampling rate) over BLE</title><link>https://devzone.nordicsemi.com/thread/286511?ContentTypeID=1</link><pubDate>Wed, 23 Dec 2020 18:28:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bf8de84f-c36d-4770-9eea-fd04dfcae750</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;How are you transferring the data from the ADC buffer to the BLE handler? For example, the Nordic uart service example is slow and clumsy treating incoming uart strings as individual bytes instead of packets of data. This is a sample of a packet transfer:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint32_t StoredPacketTransmit(BlePacketFormat_t *pPacketToTransmit, uint16_t PacketLength)
{
    uint32_t err_code = SOMETHING_BAD;
    // Define the structure to identify the Nordic UART Service
    ble_nus_t * p_m_nus = get_mNUS();
    if (pPacketToTransmit &amp;amp;&amp;amp; PacketLength &amp;amp;&amp;amp; p_m_nus)
    {
        err_code = ble_nus_data_send(p_m_nus, pPacketToTransmit, &amp;amp;PacketLength);
        if (err_code == NRF_SUCCESS)
        {
            // Packet sent, allow next packet to be built when sufficent SAADC samples available
        }
        else
        {
            // Packet not sent, next packet build is disallowed until current packet is sent
            mDelayedPacketCount++;
        }
    }
    // Allow caller to see if packet actually went out
    return err_code;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;ble_nus_data_send()&lt;/em&gt; used to be called&amp;nbsp;&lt;em&gt;ble_nus_string_send()&lt;/em&gt; depending on which SDK you are using.&lt;/p&gt;
&lt;p&gt;If not already doing so also increase the PHY to 2MHz instead of the default 1MHz&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Streaming SAADC data (16kHz sampling rate) over BLE</title><link>https://devzone.nordicsemi.com/thread/286442?ContentTypeID=1</link><pubDate>Wed, 23 Dec 2020 11:48:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b3090c2d-154b-4dd0-afe3-0a4b9962e443</guid><dc:creator>usmanmehmood55</dc:creator><description>&lt;p&gt;Hi Oliver.&amp;nbsp;&lt;/p&gt;
[quote userid="80055" url="~/f/nordic-q-a/48092/streaming-saadc-data-16khz-sampling-rate-over-ble"]The code as of now, works at lower sampling rates of about 1.5kHz[/quote]
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I have made my code on top of the same example, but I cannot go beyond 420Hz - 430Hz without disconnecting. Can you kindly share your code with me so that I can get an idea of what to do? My application requires at least 1k which I am desperately trying to achieve but have not been able to do so yet.&lt;/p&gt;
&lt;p&gt;Any help is greatly appreciated&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Usman&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Streaming SAADC data (16kHz sampling rate) over BLE</title><link>https://devzone.nordicsemi.com/thread/191271?ContentTypeID=1</link><pubDate>Thu, 06 Jun 2019 09:10:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4445e13a-f999-460a-b278-ed16d556002f</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi Oliver&lt;/p&gt;
&lt;p&gt;First of all, thanks for a detailed question. We appreciate that you take the time to describe your setup and what you are doing!&lt;/p&gt;
&lt;p&gt;1. You could try implementing the &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.3.0%2Fhardware_driver_saadc.html&amp;amp;cp=5_1_2_0_12_1_2&amp;amp;anchor=saadc_limits"&gt;NRF_DRV_SAADC_EVT_LIMIT&lt;/a&gt;&amp;nbsp;to see if the converted sample on a given channel is exceeding a limit. I suspect this is the reason you are experiencing disconnects. Have you been able to see an error code when the BLE_GAP_EVT_DISCONNECTED occurs? Might give us some pointers to what exactly is causing the disconnection.&lt;/p&gt;
&lt;p&gt;2. What are your connection parameters (This might be the reason you aren&amp;#39;t able to connect to the Android device) etc.? Also check that your BLE_GAP_PHY_2MBPS is set for the highest possible throughput.&lt;/p&gt;
&lt;p&gt;3. As far as I know, we don&amp;#39;t have any &amp;quot;official&amp;quot; examples of this, but someone might have done it earlier either here on DevZone, or on GitHub.&lt;/p&gt;
&lt;p&gt;4. This can be a variety of reasons. First of all, what pins do you use as UART pins? The ones described in the PS as close to the radio might cause interference if active simultaneously as the radio is. Another reason might be that your slave latency is set to 0. This is the number of failed connection events before the link is broken. By increasing this number the link will tolerate that number of missing connection events before the connection is broken. I suggest setting this to 3 or 4 and tweak it if necessary.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>