Exemple #1
0
/**@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)
{
    uint32_t err_code;
    uint16_t adc_value;
    uint8_t  percentage_batt_lvl;
    uint16_t batt_lvl_in_milli_volts;
    nrf_adc_conversion_event_clean();
    nrf_adc_stop();
    
    adc_value = nrf_adc_result_get();
    
    
    batt_lvl_in_milli_volts = ADC_RESULT_IN_MILLI_VOLTS(adc_value);
    
    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_PACKETS)
        &&
        (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
       )
    {
        APP_ERROR_HANDLER(err_code);
    }
}
Exemple #2
0
/**
 * @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;
}