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

nrf52832 battery measurement

Hi, I am trying to update the battery level through an example of the HID keyboard of nrf52832.I'm trying to connect 3.3V battery to SAADC AIN0, but as shown in the picture above, the Bluetooth screen keeps saying 0%. Is there a problem with my code? The (+) portion of the battery holder was connected to the board GPIO P0.02.

void saadc_init(void) 
{
    //  SAADC config & calibrate
    nrfx_saadc_config_t saadc_config = NRFX_SAADC_DEFAULT_CONFIG;
    APP_ERROR_CHECK(nrfx_saadc_init(&saadc_config, saadc_event_handler));
    APP_ERROR_CHECK(nrfx_saadc_calibrate_offset());
    while (nrfx_saadc_is_busy())
        sd_app_evt_wait();

    // Channels config
    nrf_saadc_channel_config_t battery_config = NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN0);
    APP_ERROR_CHECK(nrfx_saadc_channel_init(AIN_BATTERY, &battery_config));

    // double buffering
    APP_ERROR_CHECK(nrfx_saadc_buffer_convert(buffer[0], INPUTS));
    APP_ERROR_CHECK(nrfx_saadc_buffer_convert(buffer[1], INPUTS));

    // start SAADC timer
    APP_ERROR_CHECK(app_timer_create(&saadc_timer, APP_TIMER_MODE_REPEATED, saadc_timeout_handler));
    APP_ERROR_CHECK(app_timer_start(saadc_timer, APP_TIMER_TICKS(TIMER), NULL));
}

  • Hello,

    I'm trying to connect 3.3V battery to SAADC AIN0
    The (+) portion of the battery holder was connected to the board GPIO P0.02.

    If you are working with a nRF52 DK then powering your device from a battery the supply will be unregulated, so you could instead have the SAADC sample the VDD bus directly, instead of going the route through P0.02.

    but as shown in the picture above, the Bluetooth screen keeps saying 0%.

    What values does your SAADC sample, and how do you convert them to a percentage of remaining charge?
    If you connect to the device using nRF Connect for Desktop, what is the value the is device sending through the Battery Service?
    The function for converting voltage to a battery percentage that exists in the SDK is made for a coincell battery, so it can not be used with any other battery. You will then have to create this mapping yourself, based on the discharge curve of the specific batteries you are working with. You will find this discharge curve in the batteries datasheet.

    I suspect that the output of the SAADC is not being handled correctly, and thus the Battery Service indicates 0.
    Could you share more of your code, specifically the part where you process your SAADC samples and use them to update the Battery Service?

    Best regards,
    Karl

Related