<?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>Simplest way to read an ADC input</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/17683/simplest-way-to-read-an-adc-input</link><description>Dear All,
I would like a simple way to read the voltage on one ADC pin without using any &amp;quot;adc_event_handler&amp;quot;-like solution.
I tried 
 reading=nrf_adc_convert_single(NRF_ADC_CONFIG_INPUT_2); 
 but without success. 
 Thanks 
 Francesco</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 03 May 2020 14:41:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/17683/simplest-way-to-read-an-adc-input" /><item><title>RE: Simplest way to read an ADC input</title><link>https://devzone.nordicsemi.com/thread/247741?ContentTypeID=1</link><pubDate>Sun, 03 May 2020 14:41:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b43c4896-14a0-4057-af50-d5d06e5236d8</guid><dc:creator>marian_g</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Can you convert this example to sdk16? I am having trouble converting it myself.&lt;/p&gt;
&lt;p&gt;Thanks a lot!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Simplest way to read an ADC input</title><link>https://devzone.nordicsemi.com/thread/68036?ContentTypeID=1</link><pubDate>Mon, 14 Nov 2016 15:36:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0e11fa98-d815-4dcc-8bdd-673911f883fe</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;How long time before the measurement is ready depend on what bit mode you use on the ADC.
The default configuration uses 10-bit, and takes 68 μs to sample. If you use 8-bit mode it takes 20 μs (50K samples per second). The nrf_delay_ms() is just there to not overflow the uart.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Simplest way to read an ADC input</title><link>https://devzone.nordicsemi.com/thread/68035?ContentTypeID=1</link><pubDate>Mon, 14 Nov 2016 15:21:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8d5999d3-7b9b-4f87-bf63-0c45e21698f4</guid><dc:creator>leron</dc:creator><description>&lt;p&gt;Thanks Sigurd,
how long does it take to have a measurement ready?
Can I shorten the nrf_delay_ms() to 10ms (of course after removing the UART)?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Simplest way to read an ADC input</title><link>https://devzone.nordicsemi.com/thread/68034?ContentTypeID=1</link><pubDate>Mon, 14 Nov 2016 15:15:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e99414a7-f187-48d4-bc83-9b0edab1cbfe</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;First of all, event-driven ADC is recommended, so that the CPU can be turned off during inactive periods. But if you don’t want that, here is a very simple way to read the ADC without using any events, using the &lt;code&gt;nrf_drv_adc_sample_convert&lt;/code&gt; &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v11.0.0/group__nrf__adc__drv.html?cp=4_0_1_6_7_0_0_17#ga13ce7b2be107538728ed74c6f647903d"&gt;function&lt;/a&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;quot;nrf.h&amp;quot;
#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;quot;nrf_drv_adc.h&amp;quot;
#include &amp;quot;nordic_common.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;app_util_platform.h&amp;quot;


static nrf_adc_value_t       adc_value; /**&amp;lt; ADC buffer. */
static nrf_drv_adc_channel_t m_channel_config = NRF_DRV_ADC_DEFAULT_CHANNEL(NRF_ADC_CONFIG_INPUT_2); 

/**
 * @brief Function for main application entry.
 */
int main(void)
{
    UNUSED_RETURN_VALUE(NRF_LOG_INIT());
    NRF_LOG_PRINTF(&amp;quot;ADC example\r\n&amp;quot;);

    while (true)
    {
        nrf_drv_adc_sample_convert(&amp;amp;m_channel_config,&amp;amp;adc_value);
        NRF_LOG_PRINTF(&amp;quot;ADC buffer: %d\r\n&amp;quot;,adc_value);
        nrf_delay_ms(100);
    }
}
/** @} */
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Simplest way to read an ADC input</title><link>https://devzone.nordicsemi.com/thread/68033?ContentTypeID=1</link><pubDate>Fri, 11 Nov 2016 17:28:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1afe2033-2ff0-4079-b904-ff7d8c76c012</guid><dc:creator>leron</dc:creator><description>&lt;p&gt;Let me explain better.
This is my main.
It is basically the adc example where I tried not to use the interrupts or the handler to have a reading.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;quot;nrf.h&amp;quot;
#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;quot;nrf_drv_adc.h&amp;quot;
#include &amp;quot;nordic_common.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;app_util_platform.h&amp;quot;

#define ADC_BUFFER_SIZE 1 /**&amp;lt; Size of buffer for ADC samples. */

static nrf_adc_value_t adc_buffer[ADC_BUFFER_SIZE]; /* ADC buffer. */ 
static nrf_drv_adc_channel_t m_channel_config = NRF_DRV_ADC_DEFAULT_CHANNEL(NRF_ADC_CONFIG_INPUT_2); /* Channel instance. Default configuration used. */

static void adc_event_handler(nrf_drv_adc_evt_t const * p_event) 
{ 
// if (p_event-&amp;gt;type == NRF_DRV_ADC_EVT_DONE) 
// { // uint32_t i; 
// for (i = 0; i &amp;lt; p_event-&amp;gt;data.done.size; i++) 
// { 
// NRF_LOG_PRINTF(&amp;quot;Current sample value: %d\r\n&amp;quot;, p_event-&amp;gt;data.done.p_buffer[i]); // 
// } 
// } 
}

static void adc_config(void) 
{ 
ret_code_t ret_code; 
nrf_drv_adc_config_t config = NRF_DRV_ADC_DEFAULT_CONFIG;
ret_code = nrf_drv_adc_init(&amp;amp;config, adc_event_handler);
    APP_ERROR_CHECK(ret_code);
nrf_drv_adc_channel_enable(&amp;amp;m_channel_config);
}

int main(void)
{ 
nrf_adc_value_t myvalue; 
LEDS_CONFIGURE(BSP_LED_0_MASK); 
LEDS_OFF(BSP_LED_0_MASK);
adc_config();
UNUSED_RETURN_VALUE(NRF_LOG_INIT());

NRF_LOG_PRINTF(&amp;quot;ADC example\r\n&amp;quot;);

while(1)
{
APP_ERROR_CHECK(nrf_drv_adc_buffer_convert(adc_buffer,ADC_BUFFER_SIZE));
nrf_drv_adc_sample();
nrf_delay_ms(100);
LEDS_INVERT(BSP_LED_0_MASK);\
myvalue=nrf_adc_convert_single(NRF_ADC_CONFIG_INPUT_2);
NRF_LOG_PRINTF(&amp;quot;Currently my value: %d\r\n&amp;quot;,myvalue);
}

}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I would like to know more details about:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&amp;quot;APP_ERROR_CHECK(nrf_drv_adc_buffer_convert(adc_buffer,ADC_BUFFER_SIZE));&amp;quot;: without this it does not work&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;2: if I understand properly first a measurement is triggered with nrf_drv_adc_sample() while
nrf_adc_convert_single makes accessible the first of the measurements. Am I correct?&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Simplest way to read an ADC input</title><link>https://devzone.nordicsemi.com/thread/68032?ContentTypeID=1</link><pubDate>Fri, 11 Nov 2016 17:13:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:321c543d-e2c9-4ff3-9e3d-b6d94172e6c6</guid><dc:creator>awneil</dc:creator><description>&lt;blockquote&gt;
&lt;p&gt;The function does not check if the ADC is initialized and powered&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;See: &lt;a href="https://developer.nordicsemi.com/nRF5_SDK/nRF51_SDK_v8.x.x/doc/8.0.0/s110/html/a00754.html#ga23c9071d2c15461db6bf6c8a144339b8"&gt;developer.nordicsemi.com/.../a00754.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;So are you sure that you have correctly initialized and powered the ADC?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>