/** * @brief ADC initialization. */ static void adc_config(void) { ret_code_t ret_code; nrf_drv_adc_config_t config = NRF_DRV_ADC_DEFAULT_CONFIG; ret_code = nrf_drv_adc_init(&config, adc_event_handler); APP_ERROR_CHECK(ret_code); nrf_drv_adc_channel_enable(&m_channel_config); }
/** * @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 }
/** * @brief Function for initializing ADC. */ static ret_code_t adc_init(void) { ret_code_t err_code; adc_channel.config.config.input = NRF_ADC_CONFIG_SCALING_INPUT_ONE_THIRD; nrf_drv_adc_config_t adc_config = NRF_DRV_ADC_DEFAULT_CONFIG; err_code = nrf_drv_adc_init(&adc_config, adc_handler); if(err_code != NRF_SUCCESS) { return NRF_ERROR_INTERNAL; } nrf_gpio_pin_set(m_csense.output_pin); return NRF_SUCCESS; }
void analogin_init(analogin_t *obj, PinName pin) { obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); MBED_ASSERT(obj->adc != (ADCName)NC); uint32_t pinFunc = pinmap_function(pin, PinMap_ADC); MBED_ASSERT(pinFunc != (uint32_t)NC); obj->adc_pin = pinFunc; NVIC_SetVector(ADC_IRQn, (uint32_t)ADC_IRQHandler); ret_code_t ret_code; // p_config, event_handler ret_code = nrf_drv_adc_init(NULL , NULL); // select blocking mode MBED_ASSERT((ret_code == NRF_SUCCESS) || (ret_code == NRF_ERROR_INVALID_STATE)); //NRF_ERROR_INVALID_STATE expected for multiple channels used. }