/**
 * @brief Configure and initialize the ADC
 */
static void adc_config(void)
{
    ret_code_t ret_code;
    nrf_drv_adc_config_t adc_config = NRF_DRV_ADC_DEFAULT_CONFIG;                                              //Get default ADC configuration
    static nrf_drv_adc_channel_t adc_channel_config = NRF_DRV_ADC_DEFAULT_CHANNEL(NRF_ADC_CONFIG_INPUT_2);     //Get default ADC channel configuration
	
    //Uncomment the following two lines to sample the supply voltage of the nRF51 directly (not from a pin)
    //adc_channel_config.config.config.input = NRF_ADC_CONFIG_SCALING_SUPPLY_ONE_THIRD;
    //adc_channel_config.config.config.ain = NRF_ADC_CONFIG_INPUT_DISABLED;
	
    ret_code = nrf_drv_adc_init(&adc_config, adc_event_handler);              //Initialize the ADC
    APP_ERROR_CHECK(ret_code);

    nrf_drv_adc_channel_enable(&adc_channel_config);                          //Configure and enable an ADC channel
}
Example #2
0
#include "nrf.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "nrf_drv_adc.h"
#include "nordic_common.h"
#include "boards.h"
#include "nrf_log.h"
#include "app_error.h"
#include "nrf_delay.h"
#include "app_util_platform.h"


#define ADC_BUFFER_SIZE 10                                /**< Size of buffer for ADC samples.  */
static nrf_adc_value_t       adc_buffer[ADC_BUFFER_SIZE]; /**< ADC buffer. */
static nrf_drv_adc_channel_t m_channel_config = NRF_DRV_ADC_DEFAULT_CHANNEL(NRF_ADC_CONFIG_INPUT_2); /**< Channel instance. Default configuration used. */

/**
 * @brief ADC interrupt handler.
 */
static void adc_event_handler(nrf_drv_adc_evt_t const * p_event)
{
    if (p_event->type == NRF_DRV_ADC_EVT_DONE)
    {
        uint32_t i;
        for (i = 0; i < p_event->data.done.size; i++)
        {
            NRF_LOG_PRINTF("Current sample value: %d\r\n", p_event->data.done.p_buffer[i]);
        }
    }
}
Example #3
0
#if USE_COMP == 0
#ifdef ADC_PRESENT
#include "nrf_drv_adc.h"

/**
 * @defgroup adc_defines ADC defines to count input voltage.
 * @{
 */
#define ADC_RES_10BIT           1024
#define ADC_INPUT_PRESCALER     3
#define ADC_REF_VBG_VOLTAGE     1.2
/* @} */

/* ADC channel used to call conversion. */
static nrf_drv_adc_channel_t adc_channel = NRF_DRV_ADC_DEFAULT_CHANNEL(0);
#elif defined(SAADC_PRESENT)
#include "nrf_drv_saadc.h"

/**
 * @defgroup saadc_defines SAADC defines to count input voltage.
 * @{
 */
#define SAADC_RES_10BIT           1024
#define SAADC_INPUT_PRESCALER     3
#define SAADC_REF_VBG_VOLTAGE     0.6
/* @} */

/* SAADC channel used to call conversion. */
static nrf_saadc_channel_config_t saadc_channel = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN0);
#endif //ADC_PRESENT