I am trying to read the battery level on a custom NRF52 board and I am getting a value that is around half of real voltage. The same code works fine on NRF52 DK ( I was expecting to have only the diode difference among the two boards).
This is how I am initializing the SAADC :
ret_code_t err_code = nrf_drv_saadc_init(NULL, saadc_event_handler);
APP_ERROR_CHECK(err_code);
nrf_saadc_channel_config_t config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_VDD);
err_code = nrf_drv_saadc_channel_init(0, &config);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_buffer_convert(&adc_buf[0], 1);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_buffer_convert(&adc_buf[1], 1);
APP_ERROR_CHECK(err_code);
And this is what I am receiving in the event handler:
nrf_saadc_value_t adc_result;
uint16_t batt_lvl_in_milli_volts;
uint32_t err_code;
adc_result = p_event->data.done.p_buffer[0];
err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, 1);
APP_ERROR_CHECK(err_code);
batt_lvl_in_milli_volts = ADC_RESULT_IN_MILLI_VOLTS(adc_result) + DIODE_FWD_VOLT_DROP_MILLIVOLTS;
On my custom board I receive around 400 or adc_result while on NRF52 DK I receive 800 that with the macro conversion correctly convert to real battery voltage. Please note both board are powered by a power supply so I do not expect the battery to drop under any load.
Any idea on what could be wrong ?
best Marco