<?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>SAADC does not sample</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/50484/saadc-does-not-sample</link><description>I&amp;#39;m trying to sample analog input but there is no value after sampling. 
 I tested the input by configuring it as digital input and it worked correctly. 
 Below is code. Any help would be greatly appreciated.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 05 Aug 2019 14:09:02 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/50484/saadc-does-not-sample" /><item><title>RE: SAADC does not sample</title><link>https://devzone.nordicsemi.com/thread/202462?ContentTypeID=1</link><pubDate>Mon, 05 Aug 2019 14:09:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9734d921-8218-488f-9d52-f0c12f13eea8</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;LOL: This is an example on how to &lt;strong&gt;not&lt;/strong&gt; use a pointer variable. &lt;/p&gt;
&lt;p&gt;This is how it is supposed to look:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static volatile int16_t nrf_adc_result;

int16_t readResult(){
        NRF_SAADC-&amp;gt;RESULT.PTR = (uint32_t)&amp;amp;nrf_adc_result;

        nrf_saadc_task_trigger(NRF_SAADC_TASK_START);
        while (nrf_saadc_event_check(NRF_SAADC_EVENT_STARTED) == 0);
        nrf_saadc_task_trigger(NRF_SAADC_TASK_SAMPLE);
        while (nrf_saadc_event_check(NRF_SAADC_EVENT_END) == 0);
        nrf_saadc_event_clear(NRF_SAADC_EVENT_END);
        if (nrf_adc_result &amp;lt;0)
        {
            nrf_adc_result = 0;
        }

      return nrf_adc_result;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Note that you can eliminate the pointer variable altogether here.&lt;/p&gt;
&lt;p&gt;I also notices that I was mistaken above: You need to read at least &lt;strong&gt;two&lt;/strong&gt; books: One for basic C programming, one for programming C on a microcontroller like the ARM Cortex-M variants. The latter tells you about interrupts and the use of volatile among many other details.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC does not sample</title><link>https://devzone.nordicsemi.com/thread/202437?ContentTypeID=1</link><pubDate>Mon, 05 Aug 2019 12:59:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:06276ee8-72f7-41da-80c2-a4cb9bcdb780</guid><dc:creator>eBrock</dc:creator><description>&lt;p&gt;Your explanation was useful. Your insult was not.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC does not sample</title><link>https://devzone.nordicsemi.com/thread/201995?ContentTypeID=1</link><pubDate>Thu, 01 Aug 2019 20:55:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:730f3219-ce0f-4792-8ea7-5f86766c8a40</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int16_t * adcResult = 0;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;That points to flash address zero, which is part of the MBR and countains the lower half of the inital stack pointer.&lt;/p&gt;
&lt;p&gt;You should point it to something in RAM like:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static int16_t nrf_adc_result = 0;
int16_t * adcResult = &amp;amp;nrf_adc_result;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Also, get a book about the C programming language and read it. This is a very basic beginner question, and C cannot be learned properly just from forum posts.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC does not sample</title><link>https://devzone.nordicsemi.com/thread/201988?ContentTypeID=1</link><pubDate>Thu, 01 Aug 2019 18:32:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e761f749-072b-4a43-a3fb-02abb4d1c2fe</guid><dc:creator>eBrock</dc:creator><description>&lt;p&gt;What exactly looks like a NULL pointer?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC does not sample</title><link>https://devzone.nordicsemi.com/thread/201985?ContentTypeID=1</link><pubDate>Thu, 01 Aug 2019 18:13:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:312da1c4-9805-4fcf-8ebd-073eda56d46c</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;That looks a lot like a NULL pointer to me.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Hopefully OP set adcResult pointer to a more sensible RAM location in code not shown here.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC does not sample</title><link>https://devzone.nordicsemi.com/thread/201984?ContentTypeID=1</link><pubDate>Thu, 01 Aug 2019 18:03:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8961f5a9-48e4-4d19-899e-085624db2e86</guid><dc:creator>eBrock</dc:creator><description>&lt;p&gt;OK, I have figured this out. My code had several problems. The first problem, which made it very difficult to debug,&lt;/p&gt;
&lt;p&gt;was that the SAMPLE task only executes once and then apparently the SAADC stops. So, when I want to sample&lt;/p&gt;
&lt;p&gt;again,&amp;nbsp;I have to start the SAADC and then I can start the SAMPLE task. The second problem is that I needed to configure&lt;/p&gt;
&lt;p&gt;the SAADC result address as &amp;amp;adcResult. The third problem is that I was assuming the placement of the 8-bit value&lt;/p&gt;
&lt;p&gt;and the sign bit. Both were wrong. There is missing information from the nRF52832 data sheet. Even for 8-bit value,&lt;/p&gt;
&lt;p&gt;the sign bit is bit 15 of the result. Also, when configured for an 8-bit value, the SAADC result is not little endian.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Here are the changes I made to the code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;NRF_SAADC-&amp;gt;RESULT.PTR = (uint32_t)&amp;amp;adcResult;

        nrf_saadc_task_trigger(NRF_SAADC_TASK_START);
        while (nrf_saadc_event_check(NRF_SAADC_EVENT_STARTED) == 0);
        nrf_saadc_task_trigger(NRF_SAADC_TASK_SAMPLE);
        while (nrf_saadc_event_check(NRF_SAADC_EVENT_END) == 0);
        nrf_saadc_event_clear(NRF_SAADC_EVENT_END);
        nrf_adc_result = (uint16_t)adcResult;
        if (nrf_adc_result &amp;gt;&amp;gt; 15 == 1)
        {
            nrf_adc_result = 0;
        }&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC does not sample</title><link>https://devzone.nordicsemi.com/thread/201901?ContentTypeID=1</link><pubDate>Thu, 01 Aug 2019 13:05:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:058c2888-0bdc-46d0-9776-1cbdbb15b2c7</guid><dc:creator>eBrock</dc:creator><description>&lt;p&gt;I forgot to include other details...&lt;/p&gt;
&lt;p&gt;I&amp;#39;m using SES for IDE and the nRF52 Dev board. I&amp;#39;ve already tried many variations of pointer declaration just to see if it would effect the result.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve looked at the SDK example as well as other examples and I think my code should work.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Here is the definition code:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;quot;sdk_common.h&amp;quot;
#include &amp;quot;nrf52.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;nrf_saadc.h&amp;quot;

#define LED_1           17                      // I/O for LED 1 = P0.17
#define LED_2           18                      // I/O for LED 2 = P0.18
#define LED_3           19                      // I/O for LED 3 = P0.19
#define LED_4           20                      // I/O for LED 4 = P0.20

static uint16_t nrf_adc_result = 0;
int16_t * adcResult = 0;&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC does not sample</title><link>https://devzone.nordicsemi.com/thread/201697?ContentTypeID=1</link><pubDate>Wed, 31 Jul 2019 22:42:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b7c0678f-e8d5-4553-93fe-fb4f56654881</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;Missing defintition of&amp;nbsp; &amp;quot;adcResult&amp;quot;, which is likely used wrong here.&lt;/p&gt;
&lt;p&gt;Note that there is SAADC example code in the SDK.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>