Hello,
I am making a battery service to report the battery that is sampled by the SAADC, so far I am am able to compile it and debug it, however I see how my saadc_event_handler_interrupt is never triggered. Which means to me that the ADC never samples the battery, further, after some itereations I get an error of the softdevice handler.
The function that is triggered once the timer is time out( each 5s) is like this
static void battery_level_update(void)
{
uint32_t err_code;
uint8_t battery_level;
NRF_LOG_INFO("Read value from saadc %d\n",0);
saadc_init(batt_meas_init);
err_code = nrf_drv_saadc_sample();
APP_ERROR_CHECK(err_code);
}
where the method saadc_init() contains the handler saadc_event_handler_interrupt
uint32_t saadc_init(batt_meas_param_t batt_meas_init)
{
uint32_t err_code;
nrf_drv_saadc_config_t saadc_config = NRF_DRV_SAADC_DEFAULT_CONFIG;
err_code = nrf_drv_saadc_init(&saadc_config, saadc_event_handler_interrupt);
//RETURN_IF_ERROR(err_code);
#ifndef DK_BOARD
nrf_saadc_channel_config_t channel_config =
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(nrf_drv_saadc_gpio_to_ain(batt_meas_init.adc_pin_no));
#else
nrf_saadc_channel_config_t channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(batt_meas_init.adc_pin_no);
#endif
/* Burst enabled to oversample the SAADC. */
channel_config.burst = NRF_SAADC_BURST_ENABLED;
channel_config.gain = ADC_GAIN;
channel_config.acq_time = NRF_SAADC_ACQTIME_3US;//NRF_SAADC_ACQTIME_40US;
err_code = nrf_drv_saadc_channel_init(0, &channel_config);
//RETURN_IF_ERROR(err_code);
err_code = nrf_drv_saadc_buffer_convert(m_buffer, ADC_BUF_SIZE);
//RETURN_IF_ERROR(err_code);
return M_BATT_STATUS_CODE_SUCCESS;
}
static void saadc_event_handler_interrupt(nrf_drv_saadc_evt_t const * const p_event)
{
uint32_t err_code;
uint16_t voltage;
if (p_event->type == NRF_DRV_SAADC_EVT_CALIBRATEDONE)
{
m_adc_cal_in_progress = false;
}
else if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
{
err_code = adc_to_batt_voltage(*p_event->data.done.p_buffer, &voltage);
APP_ERROR_CHECK(err_code);
err_code = app_sched_event_put((void*)&voltage, sizeof(voltage), batt_event_handler_adc);
APP_ERROR_CHECK(err_code);
}
nrf_drv_saadc_uninit();
}
and finally this last one calls batt_event_handler_adc that writes the read battery voltage.
static void batt_event_handler_adc(void * p_event_data, uint16_t size)
{
uint32_t err_code;
m_batt_meas_event_t batt_meas_evt;
memcpy(&batt_meas_evt.voltage_mv, p_event_data, size);
batt_meas_evt.valid_voltage = true;
if (batt_meas_evt.voltage_mv <= batt_meas_init.batt_voltage_limit_low)
{
batt_meas_evt.type = M_BATT_MEAS_EVENT_LOW;
}
else if (batt_meas_evt.voltage_mv >= batt_meas_init.batt_voltage_limit_full)
{
batt_meas_evt.type = M_BATT_MEAS_EVENT_FULL;
}
else
{
batt_meas_evt.type = M_BATT_MEAS_EVENT_DATA;
}
uint8_t battery_level_percent;
batt_voltage_to_percent(batt_meas_evt.voltage_mv, &battery_level_percent);
batt_meas_evt.level_percent = battery_level_percent;
if(m_ble_bas_configured)
{
err_code = ble_bas_battery_level_update(&m_bas, battery_level_percent);
if ((err_code != NRF_SUCCESS) &&
(err_code != NRF_ERROR_INVALID_STATE) &&
(err_code != BLE_ERROR_NO_TX_PACKETS) &&
(err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING))
{
APP_ERROR_HANDLER(err_code);
}
}
else
{
m_initial_batt_level_percent = battery_level_percent;
}
m_evt_handler(&batt_meas_evt);
}
So a call to saadc_event_handler_interrupt never happens, I have set a breakpoint in that line, and I don't see anything happen.
Any suggestion?
Thanks in advance,