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

nRF52832 ADC

I try to combine SPI master and ADC sample code, I add below code to my spi master example, the saadc_init() is called in the main function. However I found that the saadc_callback is not called after a while. Please comment!

I am using nRF5_15.2.0 SDK


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]);
        }
        m_adc_evt_counter++;
*/
    }
}

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);
    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(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);
}
  • I have tried the saadc example. It work. All my pcb boards are sent to customer, I have no boards to try now. I will try to set the SAMPLES_IN_BUFFER to 1 for next batch. The callback will be triggered every time I call nrfx_saadc_sample() if I set  SAMPLES_IN_BUFFER to 1. Right?

    SAMPLES
  • yes. But you should trigger this using a timer rather than in the callback event.

    With your implementation below you risk that nrfx_saadc_sample() does not return NRF_SUCCESS for some reason. In this case, adc_complete is false, and you have not triggered a new sample, and you will not get a new callback, and never trigger the new sample. 

    Therefore you should at least not set adc_complete to false without checking that nrfx_saadc_sample() returned true.

Related