This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF52832 physical pin analogRead

Hello,

I'm trying to read an ADC value from a sensor(for POC I'll be using a pot wired to 3.3V VDD and GND) but all the examples I found only demonstrated reading the internal VDD with the 0.6V reference:

for example(simplest code I found):

github.com/.../main.c

and nothing with the VDD reference and an actual physical pin....

does anybody has an idea were can you get such an example or at least how should the example code be modified to work with say pin "P0.04" sins I'm quite a noobie?

Thanks for your time.

Parents Reply Children
  • Hi  Matt,

    I also try this sample, but I do not how the result counts. Are there any alogrithm about  the sample?

    The code segemnt is the followings:

    void saadc_callback(nrf_drv_saadc_evt_t const *p_event)
    {
        if (p_event->type == NRF_DRV_SAADC_EVT_DONE) {
            ret_code_t err_code;

            err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAMPLES_IN_BUFFER);
            APP_ERROR_CHECK(err_code);

            int i;
            NRF_LOG_INFO("ADC event number: %d", (int)m_adc_evt_counter);

            for (i = 0; i < SAMPLES_IN_BUFFER; i++) {
                NRF_LOG_INFO("%d", p_event->data.done.p_buffer[i]);
            }
            NRF_LOG_INFO(" voltage: %d\n", nrfx_saadc_buffer_convert(nrf_saadc_buffer_pointer_get(),SAMPLES_IN_BUFFER));
            m_adc_evt_counter++;
        }
    }

    void saadc_init(void)
    {
        ret_code_t err_code;
        nrf_saadc_channel_config_t channel_config_0 = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE( NRF_SAADC_INPUT_AIN0);

        nrf_saadc_channel_config_t channel_config_1 = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE( NRF_SAADC_INPUT_AIN1);
        err_code = nrf_drv_saadc_init(NULL, saadc_callback);
        APP_ERROR_CHECK(err_code);

        err_code = nrf_drv_saadc_channel_init(0, &channel_config_0);
        APP_ERROR_CHECK(err_code);

        err_code = nrf_drv_saadc_channel_init(1, &channel_config_1);
        APP_ERROR_CHECK(err_code);

        err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0], SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);

        err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[1], SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);

    }

    void saadc_stop()
    {
        nrf_drv_timer_disable(&m_timer);
        nrf_drv_timer_uninit(&m_timer);
        nrf_drv_ppi_channel_disable(m_ppi_channel);
        nrf_drv_ppi_uninit();
        nrf_drv_saadc_abort();
        nrf_drv_saadc_uninit();
        while(nrf_drv_saadc_is_busy());
    }

    And here is the results printed out:
    /**

    results of saadc sample

Related