<?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>How to send SAADC Data over BLE?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/66607/how-to-send-saadc-data-over-ble</link><description>Hi, I&amp;#39;m using nrf52833 with SDK 17.0.0. 
 
 I want to send SAADC data over BLE. 
 So, I want to see data in my phone. 
 I&amp;#39;ve modified codes. 
 I want to use macro(ble_nus_data_code). 
 So, I add this macro in saadc_callback(line 687). 
 But, I can&amp;#39;t see</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 07 Oct 2020 07:55:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/66607/how-to-send-saadc-data-over-ble" /><item><title>RE: How to send SAADC Data over BLE?</title><link>https://devzone.nordicsemi.com/thread/273375?ContentTypeID=1</link><pubDate>Wed, 07 Oct 2020 07:55:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:176a63e0-540d-407c-a96b-d3542e8613a1</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;It doesn&amp;#39;t seem as you are checking the error code from&amp;nbsp;ble_nus_data_send()?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send SAADC Data over BLE?</title><link>https://devzone.nordicsemi.com/thread/272831?ContentTypeID=1</link><pubDate>Sat, 03 Oct 2020 14:16:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:29c29cd8-e011-4fb7-9543-cf46be8f88c0</guid><dc:creator>ENENER</dc:creator><description>&lt;p&gt;Thank you.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So I tried like this.&lt;pre class="ui-code" data-mode="text"&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;

        err_code = nrf_drv_saadc_buffer_convert(p_event-&amp;gt;data.done.p_buffer, SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);

        int i;
        printf(&amp;quot;ADC event number: %d\r\n&amp;quot;, (int)m_adc_evt_counter);
		
        for (i = 0; i &amp;lt; SAMPLES_IN_BUFFER; i++)
        {
            printf(&amp;quot;%d\r\n&amp;quot;, p_event-&amp;gt;data.done.p_buffer[i]);
        }
				   uint16_t BUFFER_SIZE = SAMPLES_IN_BUFFER * 2;
				
				err_code = ble_nus_data_send(&amp;amp;m_nus, (uint8_t *)p_event-&amp;gt;data.done.p_buffer, (uint16_t *)BUFFER_SIZE, m_conn_handle);				
        m_adc_evt_counter++;
    }
}&lt;/pre&gt;There are no warning&amp;amp;errors.&lt;/p&gt;
&lt;p&gt;But, I can&amp;#39;t still receive any messages on my phone.&lt;/p&gt;
&lt;p&gt;Can you find any problem??&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send SAADC Data over BLE?</title><link>https://devzone.nordicsemi.com/thread/272830?ContentTypeID=1</link><pubDate>Sat, 03 Oct 2020 13:27:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ed31ec40-8ea0-46fb-a5f4-8131904f0be2</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;I see it takes a pointer as the length argument. You need to declare a new variable and set its value to 2x SAMPLES_IN_BUFFER, then use the address of this variable as the length field.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send SAADC Data over BLE?</title><link>https://devzone.nordicsemi.com/thread/272829?ContentTypeID=1</link><pubDate>Sat, 03 Oct 2020 13:19:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64ae007e-3e33-4694-9a6f-a16686954d5a</guid><dc:creator>ENENER</dc:creator><description>&lt;p&gt;Thanks for your answer.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I tried your code, but there are 1 errors &amp;amp; warnings.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&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;

        err_code = nrf_drv_saadc_buffer_convert(p_event-&amp;gt;data.done.p_buffer, SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);

        int i;
        printf(&amp;quot;ADC event number: %d\r\n&amp;quot;, (int)m_adc_evt_counter);

        for (i = 0; i &amp;lt; SAMPLES_IN_BUFFER; i++)
        {
            printf(&amp;quot;%h\r\n&amp;quot;, p_event-&amp;gt;data.done.p_buffer[i]);
        }
				err_code = ble_nus_data_send(&amp;amp;m_nus, (uint8_t *)p_event-&amp;gt;data.done.p_buffer[i], ((uint16_t *)SAMPLES_IN_BUFFER * 2), m_conn_handle);				
        m_adc_evt_counter++;
    }
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;..\..\..\main.c(701): warning: #181-D: argument is incompatible with corresponding format string conversion&lt;br /&gt; printf(&amp;quot;%s\r\n&amp;quot;, p_event-&amp;gt;data.done.p_buffer[i]);&lt;br /&gt;..\..\..\main.c(703): error: #32: expression must have arithmetic type&lt;br /&gt; err_code = ble_nus_data_send(&amp;amp;m_nus, (uint8_t *)p_event-&amp;gt;data.done.p_buffer[i], ((uint16_t *)SAMPLES_IN_BUFFER * 2), m_conn_handle); &lt;br /&gt;..\..\..\main.c: 1 warning, 1 error&lt;br /&gt;&amp;quot;.\_build\nrf52833_xxaa.axf&amp;quot; - 1 Error(s), 1 Warning(s).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Do you know how to solve this??&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send SAADC Data over BLE?</title><link>https://devzone.nordicsemi.com/thread/272825?ContentTypeID=1</link><pubDate>Sat, 03 Oct 2020 09:52:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9a8039c6-38cf-4854-8d0f-96352d3cd98f</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;The only time you sample is if m_conn_handle is invalid. After you&amp;#39;ve triggered the sample task 5 times the saadc buffer is full and it&amp;#39;s callback is called. At which point you ask the service to send data over over a non-existing connection, at which point you would haver gotten an error message if you&amp;#39;d checked your logs.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Also:&amp;nbsp;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;for (i = 0; i &amp;lt; SAMPLES_IN_BUFFER; i++)
        {
            printf(&amp;quot;%d\r\n&amp;quot;, p_event-&amp;gt;data.done.p_buffer[i]);
						uint32_t err_code = ble_nus_data_send(&amp;amp;m_nus, (uint8_t *) p_event-&amp;gt;data.done.p_buffer[i], (uint16_t *)SAMPLES_IN_BUFFER, m_conn_handle);
        }&lt;/pre&gt;&lt;br /&gt;This makes no sense, why are you using a for loop to send data when the APIs take a pointer and length parameter? You&amp;#39;re transmitting a lot of unnecessary garbage, replace with:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;for (i = 0; i &amp;lt; SAMPLES_IN_BUFFER; i++)
        {
            printf(&amp;quot;%h\r\n&amp;quot;, p_event-&amp;gt;data.done.p_buffer[i]);
        }
uint32_t err_code = ble_nus_data_send(&amp;amp;m_nus, (uint8_t *) p_event-&amp;gt;data.done.p_buffer[i], ((uint16_t *)SAMPLES_IN_BUFFER * 2), m_conn_handle);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Also, note that %d in a printf statement is a signed integer whereas the saadc samples are short signed integers, so you need to use %h instead.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;You also need to double the length parameter in the call to ble_nus_data_send as the length is the number of bytes it will copy, starting from the given data pointer.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>