Using ADC with a NRF52811

Hi,

I try to use the ADC of a NRF52811. The ADC input is on p.030,

that should be AIN6 according the datasheet.

The following I'm doing for initialization and I call over an app timer the function

nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, 1); every 5000ms.

I never get any saadc_callback response, so, what I'm missing in my initialization?

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, 1);
        APP_ERROR_CHECK(err_code);

        int i;
        NRF_LOG_INFO("ADC value: %d", (int)p_event->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_AIN6);

    err_code = nrf_drv_saadc_init(NULL, saadc_callback);
    APP_ERROR_CHECK(err_code);

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

    err_code = nrf_drv_saadc_buffer_convert(&adc_v_bat, 1);
    APP_ERROR_CHECK(err_code);
}

  • Hi,

    P0.30 and AIN6 is the same pin on the nRF52811, so that is good. The code snippets shown here look good. Have you checked if the app_timer runs? It requires that the LF clock is started, which does not happen automatically unless you have a SoftDevice enabled. If not, it is your responsibility to start it.

Related