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

ADC for read battery level the event is not trigger in second time?

We are using nRF52840 SDK 15.0 with Segger embedded studio. We have referred ble_app_proximity example only for read battery level using ADC. Now in our application used SAADC for read 3 axis sensor data for that we have configured saadc_init(); For battery level read we have configured adc_configure_battery();

Meaning there are two function used for different ADC configuration, my saadc_init() function worked properly and also their saadc_callback(..) getting. But problem coming for adc_configure_battery() function event call back is not triggering means saadc_battry_event_handler() not trigger in second time.

I have called this function like 

void saadc_battry_event_handler(nrf_drv_saadc_evt_t const *p_event) {
  if (p_event->type == NRF_DRV_SAADC_EVT_DONE) {
    nrf_saadc_value_t adc_result;
    uint32_t err_code;

    err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, 1);
    APP_ERROR_CHECK(err_code);
    adc_result = p_event->data.done.p_buffer[0];
//    NRF_LOG_INFO("%d", adc_result);
    s_info.batt_lvl_in_milli_volts = ADC_RESULT_IN_MILLI_VOLTS(adc_result) +
                              DIODE_FWD_VOLT_DROP_MILLIVOLTS;
    s_info.percentage_batt_lvl = battery_level_in_percentage(s_info.batt_lvl_in_milli_volts);
    err_code = ble_bas_battery_level_update(&m_bas, s_info.percentage_batt_lvl, BLE_CONN_HANDLE_ALL);
    if (
        (err_code != NRF_SUCCESS) &&
        (err_code != NRF_ERROR_INVALID_STATE) &&
        (err_code != NRF_ERROR_RESOURCES) &&
        (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)) {
      APP_ERROR_HANDLER(err_code);
    }
  }
}

/**@brief Function for configuring ADC to do battery level conversion.
 */
static void adc_configure_battery(void) {
  ret_code_t err_code;
  nrf_saadc_value_t adc_battery_buf[2];
  NRF_LOG_DEBUG("adc_configure_battery call");
  nrf_saadc_channel_config_t config =
  NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_VDD);

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

  err_code = nrf_drv_saadc_channel_init(3, &config);
  APP_ERROR_CHECK(err_code);

  err_code = nrf_drv_saadc_buffer_convert(&adc_battery_buf[0], 1);
  APP_ERROR_CHECK(err_code);

  err_code = nrf_drv_saadc_buffer_convert(&adc_battery_buf[1], 1);
  APP_ERROR_CHECK(err_code);
}

  adc_configure_battery();
  err_code = nrf_drv_saadc_sample();
  APP_ERROR_CHECK(err_code);

My battery level not updating when sensor device wake up then i called above functions to trigger adc_configure_battery(); event handler.

My question is any problem is i used two ADC configuration function?

2. Why battery event means saadc_battry_event_handler(); is not triggering?

Related