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

Battery Service (BAS) never receiving notification

I'm using standard ble_bas from sdk12.3. I set up a timer at 60s interval to use saadc to read battery voltage. Below is my code in saadc event handler for battery level update.

Battery service property has Read and Notify. Using Read, I could get the correct battery level in nRF Connect App. But after notification is enabled, I have never received battery level update. What would be the cause of the issue?

void saadc_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;
        uint16_t          batt_lvl_in_milli_volts;
        uint8_t           percentage_batt_lvl;
        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);
        percentage_batt_lvl = myBatteryLevel(batt_lvl_in_milli_volts);
        err_code = ble_bas_battery_level_update(&m_bas, percentage_batt_lvl);
        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);
        }
        // stop saadc to save power
        nrf_drv_saadc_uninit();
        NRF_SAADC->INTENCLR = (SAADC_INTENCLR_END_Clear << SAADC_INTENCLR_END_Pos);
                NVIC_ClearPendingIRQ(SAADC_IRQn);
    }
}

Parents Reply Children
Related