/**@brief Function for handling the ADC interrupt. * * @details This function will fetch the conversion result from the ADC, convert the value into * percentage and send it to peer. */ void ADC_IRQHandler(void) { if (nrf_adc_conversion_finished()) { uint8_t adc_result; uint16_t batt_lvl_in_milli_volts; uint8_t percentage_batt_lvl; uint32_t err_code; nrf_adc_conversion_event_clean(); adc_result = nrf_adc_result_get(); batt_lvl_in_milli_volts = ADC_RESULT_IN_MILLI_VOLTS(adc_result) + DIODE_FWD_VOLT_DROP_MILLIVOLTS; percentage_batt_lvl = battery_level_in_percent(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_BUFFERS) && (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING) ) { APP_ERROR_HANDLER(err_code); } } }
/** * @brief Blocking function for executing single ADC conversion. * * This function selects desired input, starts single conversion, * waits for its finish and returns result. * ADC is left in STOP state, given input is selected. * This function does not check if ADC is initialized and powered. * * @param[in] input is requested input to be selected * * @return conversion result */ int32_t nrf_adc_convert_single(nrf_adc_config_input_t input) { int32_t val; nrf_adc_input_select(input); nrf_adc_start(); while (!nrf_adc_conversion_finished()) { } nrf_adc_conversion_event_clean(); val = nrf_adc_result_get(); nrf_adc_stop(); return val; }