Hi,
I am trying to integrate ADC in my project(ble_app_template) but getting garbage data. I have nothing connected with pin P0.4(NRF_SAADC_INPUT_AIN1). (Means not applied any voltage)
The behavior is the same with/without connecting NRF_SAADC_INPUT_AIN1 with input signal.
Here is my implementation.
void saadc_init(void) { // A variable to hold the error code ret_code_t err_code; // Create a config struct and assign it default values along with the Pin number for ADC Input // Configure the input as Single Ended(One Pin Reading) // Make sure you allocate the right pin. // nrf_saadc_channel_config_t channel_config = NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN1); nrf_saadc_channel_config_t channel_config = NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_DIFFERENTIAL(NRF_SAADC_INPUT_VDD,NRF_SAADC_INPUT_AIN1); // Initialize the saadc // first parameter is for configuring the adc resolution and other features, we will see in future tutorial //on how to work with it. right now just pass a simple null value err_code = nrf_drv_saadc_init(NULL, saadc_callback_handler); APP_ERROR_CHECK(err_code); // Initialize the Channel which will be connected to that specific pin. err_code = nrfx_saadc_channel_init(0, &channel_config); APP_ERROR_CHECK(err_code); }
// Enter main loop. for (;;) { idle_state_handle(); // a blocking function which will be called and the processor waits until the value is read // the sample value read is in 2's complement and is automatically converted once retrieved // first parameter is for the adc input channel // second parameter is to pass the address of the variable in which we store our adc sample value nrfx_saadc_sample_convert(0, &adc_val); // print this value using nrf log : here %d represents the integer value NRF_LOG_INFO("Sample value Read: %d", adc_val); // use nrf log and float marker to show the floating point values on the log // calculate the voltage by this: input_sample * 3.6 / 2^n (where n = 8 or 10 or 12 or 14 depending on our configuration for resolution in bits) NRF_LOG_INFO("Volts: " NRF_LOG_FLOAT_MARKER "\r\n", NRF_LOG_FLOAT(adc_val / 16384)); // give 500ms delay nrf_delay_ms(2000); }

Any suggestions, please?