<?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 done event not occurring</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/50832/saadc-done-event-not-occurring</link><description>I&amp;#39;m using SAADC like this: 
 
 And I&amp;#39;m not getting the done event. I&amp;#39;ve also tried not low power mode. 
 If I place a breakpoint in nrfx_saadc.c nrfx_saadc_irq_handler, after nrfx_saadc_sample is called it gets hit. But then stepping through the code</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 13 Aug 2019 10:39:28 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/50832/saadc-done-event-not-occurring" /><item><title>RE: SAADC done event not occurring</title><link>https://devzone.nordicsemi.com/thread/203784?ContentTypeID=1</link><pubDate>Tue, 13 Aug 2019 10:39:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:666e7bd1-3220-43c8-92c8-329aa3c094f8</guid><dc:creator>nrbrook</dc:creator><description>&lt;p&gt;I see now that the pin input and channel number are different. Also the size of the buffer is the number of samples expected, not the size in bytes. (The header comment uses &amp;quot;words&amp;quot;, but the size of a value is 16 bits, not sure if &amp;quot;words&amp;quot; is appropriate?). Correcting my code to work:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;nrfx_saadc_config_t config = NRFX_SAADC_DEFAULT_CONFIG;

config.resolution = NRF_SAADC_RESOLUTION_14BIT;
config.oversample = NRF_SAADC_OVERSAMPLE_DISABLED;
config.interrupt_priority = NRFX_SAADC_CONFIG_IRQ_PRIORITY;
config.low_power_mode = true;

err_code = nrfx_saadc_init(&amp;amp;config, adc_event_handler);
APP_ERROR_CHECK(err_code);

nrf_saadc_channel_config_t config = NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_VDD);
config.reference = NRF_SAADC_REFERENCE_INTERNAL;
config.gain = NRF_SAADC_GAIN1_5;
err_code = nrfx_saadc_channel_init(0, &amp;amp;config);
APP_ERROR_CHECK(err_code);

nrfx_saadc_buffer_convert(m_adc_buffer, 1);

nrfx_err_t err_code = nrfx_saadc_sample();
APP_ERROR_CHECK(err_code);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC done event not occurring</title><link>https://devzone.nordicsemi.com/thread/203781?ContentTypeID=1</link><pubDate>Tue, 13 Aug 2019 10:23:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0a277774-a64f-4645-b050-75401901f095</guid><dc:creator>nrbrook</dc:creator><description>&lt;p&gt;Ok thanks I had missed that, that helps. It seems the SAADC driver should check that. Also there is no reference to the nrf_saadc_input_t enum in&amp;nbsp;NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE, and the parameters for&amp;nbsp;nrfx_saadc_channel_init are not documented in the header comment.&lt;/p&gt;
&lt;p&gt;But I&amp;#39;m trying to read VDD voltage. I saw&amp;nbsp;&lt;/p&gt;
&lt;pre&gt;&lt;span&gt;NRF_SAADC_INPUT_VDD&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;so I switched my code to use that:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;nrfx_saadc_config_t config = NRFX_SAADC_DEFAULT_CONFIG;

config.resolution = NRF_SAADC_RESOLUTION_14BIT;
config.oversample = NRF_SAADC_OVERSAMPLE_DISABLED;
config.interrupt_priority = NRFX_SAADC_CONFIG_IRQ_PRIORITY;
config.low_power_mode = true;

err_code = nrfx_saadc_init(&amp;amp;config, adc_event_handler);
APP_ERROR_CHECK(err_code);

nrf_saadc_channel_config_t config = NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_VDD);
config.reference = NRF_SAADC_REFERENCE_INTERNAL;
config.gain = NRF_SAADC_GAIN1_5;
err_code = nrfx_saadc_channel_init(NRF_SAADC_INPUT_VDD, &amp;amp;config);
APP_ERROR_CHECK(err_code);

nrfx_saadc_buffer_convert(m_adc_buffer, sizeof(nrf_saadc_value_t) * 1);

nrfx_err_t err_code = nrfx_saadc_sample();
APP_ERROR_CHECK(err_code);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;However, this doesn&amp;#39;t work, because&amp;nbsp;&lt;/p&gt;
&lt;pre&gt;&lt;span&gt;NRF_SAADC_CHANNEL_COUNT&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Is defined as 8, but the value of&amp;nbsp;&lt;/p&gt;
&lt;pre&gt;&lt;span&gt;NRF_SAADC_INPUT_VDD&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;is 9, so in&amp;nbsp;nrfx_saadc_channel_init,&amp;nbsp;m_cb.psel[channel].pselp is garbage in&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;if (m_cb.psel[channel].pselp == NRF_SAADC_INPUT_DISABLED)
{
    ++m_cb.active_channels;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;, so the read doesn&amp;#39;t occur. I see there is an assertion for the channel parameter at the top of &lt;span&gt;nrfx_saadc_channel_init&lt;/span&gt;, but for some reason this isn&amp;#39;t hit.&lt;/p&gt;
&lt;p&gt;How can I read VDD?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC done event not occurring</title><link>https://devzone.nordicsemi.com/thread/203713?ContentTypeID=1</link><pubDate>Tue, 13 Aug 2019 05:15:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:948bdd9a-bd6f-46e0-8356-1ed52f949529</guid><dc:creator>H&amp;#229;vard</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;Nick, it is possible that the initialization&amp;nbsp;NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(0); is incorrect&lt;/p&gt;
&lt;p&gt;0 meaning:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define SAADC_CH_PSELP_PSELP_NC (0UL) /*!&amp;lt; Not connected */&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The following code seemed to work fine on my desk.&lt;/p&gt;
&lt;p&gt;(To test this easily, replace the main file of \examples\peripheral\saadc with the code below)&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
 *
 * The information contained herein is property of Nordic Semiconductor ASA.
 * Terms and conditions of usage are described in detail in NORDIC
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 *
 * Licensees are granted free, non-transferable use of the information. NO
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 * the file.
 *
 */

/** @file
 * @defgroup nrf_adc_example main.c
 * @{
 * @ingroup nrf_adc_example
 * @brief ADC Example Application main file.
 *
 * This file contains the source code for a sample application using ADC.
 *
 * @image html example_board_setup_a.jpg &amp;quot;Use board setup A for this example.&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.h&amp;quot;
#include &amp;quot;nrf_drv_saadc.h&amp;quot;
#include &amp;quot;boards.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;
#include &amp;lt;string.h&amp;gt;

#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;

#define SAMPLES_IN_BUFFER 1

static nrf_saadc_value_t m_buffer[SAMPLES_IN_BUFFER];

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);
        
        NRF_LOG_INFO(&amp;quot;%d\r\n&amp;quot;, p_event-&amp;gt;data.done.p_buffer[0]);
    }
}

void saadc_init(void)
{
    ret_code_t err_code;
    nrf_saadc_channel_config_t channel_config 
        = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN0);

    nrfx_saadc_config_t config = NRFX_SAADC_DEFAULT_CONFIG;
    config.resolution = NRF_SAADC_RESOLUTION_14BIT;
    config.oversample = NRF_SAADC_OVERSAMPLE_DISABLED;
    config.interrupt_priority = NRFX_SAADC_CONFIG_IRQ_PRIORITY;
    config.low_power_mode = true;

    err_code = nrf_drv_saadc_init(&amp;amp;config, saadc_callback);
    APP_ERROR_CHECK(err_code);


    channel_config.reference = NRF_SAADC_REFERENCE_INTERNAL;
    channel_config.gain = NRF_SAADC_GAIN1_3;
    channel_config.resistor_p = NRF_SAADC_RESISTOR_VDD1_2;
    err_code = nrf_drv_saadc_channel_init(0, &amp;amp;channel_config);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_saadc_buffer_convert(m_buffer, SAMPLES_IN_BUFFER);
    APP_ERROR_CHECK(err_code);
}

/**
 * @brief Function for main application entry.
 */
int main(void)
{
    uint32_t err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_DEFAULT_BACKENDS_INIT();

    NRF_LOG_INFO(&amp;quot;SAADC HAL simpler example.&amp;quot;);
    saadc_init();

    while (1)
    {
        nrf_drv_saadc_sample();
        nrf_delay_ms(100);
        NRF_LOG_FLUSH();
    }
}

/** @} */&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>