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

SAADC Battery Service Customization

I tried to get ADC values from my nrf52 based custom board on nrf connect app. I already made necessary changes in SAADC example program and able to get the voltage readings of the LiPo battery. My goal is to add these SAADC function in ble_app_hrs program so that simulated values of battery to be replaced with actual battery voltage/percentage. As per sample program I need to replace these lines:
static void battery_level_update(void)
{
    ret_code_t err_code;
    uint8_t  battery_level;
    
   
    //TODO:This line need to be replaced with actual function reading the battery level
    battery_level = (uint8_t)sensorsim_measure(&m_battery_sim_state, &m_battery_sim_cfg);
    err_code = ble_bas_battery_level_update(&m_bas, battery_level, BLE_CONN_HANDLE_ALL);
    if ((err_code != NRF_SUCCESS) &&
        (err_code != NRF_ERROR_INVALID_STATE) &&
        (err_code != NRF_ERROR_RESOURCES) &&
        (err_code != NRF_ERROR_BUSY) &&
        (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
       )
    {
        APP_ERROR_HANDLER(err_code);
    }
}

The added one-by-one the required piece of code and able to compile successfully. I passed actual battery ADC values in battery_level_update() function. The three main functions added in main section as following:

void main(void)
{
    ....
    ....
    
    // Start execution.
    NRF_LOG_INFO("Heart Rate Sensor example started.");
    printf("Heart Rate Sensor example started.");
    application_timers_start();
    advertising_start(erase_bonds);
    
    //Additional function calls for SAADC battery service 
    saadc_init();
    saadc_sampling_event_init();
    saadc_sampling_event_enable();
    
    // Enter main loop.
    for (;;)
    {
        idle_state_handle();
    }
    
}

However, after these changes, there is no sign of advertising app in nRF Connect App.
As per my understanding, there is a conflict between app_timer, nrf_drv_timer and nrf_drv_ppi. How to resolve it so that I could get battery ADC values on app?
Please help me with good resources to understand different timers in nRF SDK and how to use them.
Parents Reply Children
No Data
Related