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

SAADC callback never called.

Hi, 

I am trying to add the SAADC to an existing project. SDK 14.2 - Softdevice.

I quickly changed the existing code as follows:

static void saadc_callback(nrf_drv_saadc_evt_t const *p_event) {

  uint32_t err_code;

  NRF_LOG_DEBUG("saadc_callback");
}


int main(void) {

  bool erase_bonds;
  ret_code_t err_code;

  // Initialize.
  timers_init();
  buttons_leds_init(&erase_bonds);
  ble_stack_init();
  gap_params_init(configuration.board_name);
  gatt_init();
  services_init();

  advertising_init();
  conn_params_init();
  peer_manager_init();

  application_timers_start();

  ////////////

  APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE);
  advertising_start(erase_bonds);


  nrf_drv_saadc_config_t saadc_config = NRF_DRV_SAADC_DEFAULT_CONFIG;
  saadc_config.resolution = NRF_SAADC_RESOLUTION_14BIT;
  saadc_config.oversample = NRF_SAADC_OVERSAMPLE_DISABLED;

  err_code = nrf_drv_saadc_init(&saadc_config, saadc_callback);
  APP_ERROR_CHECK(err_code);

  nrf_saadc_channel_config_t channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN3);
  
  channel_config.reference = NRF_SAADC_REFERENCE_INTERNAL;
  channel_config.acq_time = NRF_SAADC_ACQTIME_3US;
  channel_config.pin_p = NRF_SAADC_INPUT_AIN3;
  channel_config.pin_n = NRF_SAADC_INPUT_DISABLED;
  channel_config.gain = NRF_SAADC_GAIN1_6;
  channel_config.burst = NRF_SAADC_BURST_DISABLED;

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

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

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

  NRF_LOG_DEBUG("Manual Measuring....");
  err_code = nrf_drv_saadc_sample();
  APP_ERROR_CHECK(err_code);


  // Enter main loop.
  for (;;) {

    app_sched_execute();

    if (NRF_LOG_PROCESS() == false) {
      power_manage();
    }
  }
}

Unfortunately, the callback gets never been called. 

Please, what am I doing wrong?

Thanks

Parents
  • Hello,

    What is your SAMPLES_IN_BUFFER size?

    If this is greater than 1, and you only call nrf_drv_saadc_sample() once, it will not trigger the event. If you look in the saadc example in the SDK, you will see that it sets up a timer with the saadc to call the sampling function on regular intervals in the function saadc_sampling_event_init(). It uses the ppi, so it is a bit cryptic to read. 

     

    Try to change your SAMPLES_IN BUFFER to 1, and you should see the event.

     

    Best regards,

    Edvi

  • Hi Edvi,

    Thank you.

    If SAMPLES_IN_BUFFER is equal to n, I have to call nrf_drv_saadc_sample() n times to get the callback been called.

    I usually use a fast timer and ppi to start the saadc and so far I haven't realized that n saadc external activations are required to fill the buffer.

    Changing the timer interval to 2000ms in the saadc sample, the callback is called about every 10s (2000ms x 5). I simply thought that a sigle saadc activation was enough to automatically fill the buffer up.

    I think this behavior should be better documented in the SDK.

    Regards,

    Fab.

  • Hello,

    I agree that it is not very intuitive. But it says on infocenter, and in nrf_drv_saadc.h (line 140) that the NRF_DRV_SAADC_EVT_DONE event is generated when the buffer is filled with samples. But to stumble upon that description is rather random Slight smile

    Best regards,

    Edvin

Reply Children
No Data
Related