This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF52832 board not sensing voltages applied to any of analog pin.

Hi,

I have my custom board wired to the nRF52 development board. I am using SDK 15 and softdevice 132 for this. I am trying to set up SAADC to measure adc data on Analog channel 0 of nrf52832 controller.  However the output count of adc is not what I expect.

Not getting Expected Output  as shown below on giving  0 V, between 0 to 3.3 V, i am getting below fixed output only in all cases which seems is there anything missing or incorrect in my attached code:

ADC reading =1024

Can you please give me the solution to get exact adc count relative to voltage apply as soon as possible. Thanks for your help.

My code is as follows:

//-------------------------------------------------------------------------------------


static void saadc_event_handler(nrf_drv_saadc_evt_t const * p_event)
{
nrf_saadc_value_t adc_result;

if( p_event->type == NRF_DRV_SAADC_EVT_DONE )
{

ret_code_t err_code;

for (uint8_t i = 0; i < SAADC_SAMPLES_IN_BUFFER; i++)
{
adc_result = p_event->data.done.p_buffer[i]; // take N samples in a row
}

err_code = nrf_drv_saadc_buffer_convert( p_event->data.done.p_buffer,SAADC_SAMPLES_IN_BUFFER);
APP_ERROR_CHECK(err_code);

NRF_LOG_INFO("ADC reading =%d\r\n", adc_result);
}
}


void saadc_init(void)
{
ret_code_t err_code;

nrf_drv_saadc_config_t saadc_config;
nrf_saadc_channel_config_t channel_config;

//Configure SAADC
saadc_config.resolution = NRF_SAADC_RESOLUTION_10BIT;
saadc_config.oversample = NRF_SAADC_OVERSAMPLE_DISABLED;
saadc_config.interrupt_priority = APP_IRQ_PRIORITY_LOW;
saadc_config.low_power_mode = true; 

////Initialize SAADC
err_code = nrf_drv_saadc_init(&saadc_config, saadc_event_handler);//NULL
APP_ERROR_CHECK(err_code);

//Configure SAADC channel
channel_config.resistor_p = NRF_SAADC_RESISTOR_DISABLED; //Disable pullup resistor on the input pin
channel_config.resistor_n = NRF_SAADC_RESISTOR_DISABLED; //Disable pulldown resistor on the input pin
channel_config.gain = NRF_SAADC_GAIN1_6; 
channel_config.reference = NRF_SAADC_REFERENCE_INTERNAL; //Set internal reference of fixed 0.6 volts
channel_config.acq_time = NRF_SAADC_ACQTIME_10US;
channel_config.mode = NRF_SAADC_MODE_SINGLE_ENDED;
channel_config.burst = NRF_SAADC_BURST_DISABLED;
channel_config.pin_p = NRF_SAADC_INPUT_AIN0;
channel_config.pin_n = NRF_SAADC_INPUT_DISABLED; 

//Sets saadc channel
err_code = nrf_drv_saadc_channel_init(0, &channel_config);
APP_ERROR_CHECK(err_code);

err_code = nrf_drv_saadc_buffer_convert(adc_buf, 1);
APP_ERROR_CHECK(err_code);
}

void saadc_get(void)
{
ret_code_t err_code;

err_code = nrf_drv_saadc_sample();
APP_ERROR_CHECK(err_code);
}
//-------------------------------------------------------------------------------------

int main(void)
{

// Initialize.
uart_init();
log_init();
timers_init();
power_management_init();
ble_stack_init();
gap_params_init();
gatt_init();
services_init();
advertising_init();
conn_params_init();

// Start execution.
printf("\r\nUART started.\r\n");
NRF_LOG_INFO("Debug logging for UART over RTT started.");
advertising_start();
saadc_init();

for (;;)
{
saadc_get();
nrf_delay_ms(1000);
idle_state_handle();
}
}

Parents Reply
  • Something is seriously wrong, I do not think it is possible to get a value of 1024 from 21mV with any configuration of the SAADC. 

    Do you see the issue on both the DK and your custom board?

    If it's only the custom board then it's either a faulty schematics/layout, bad solder job, or the ESD diode that connects AIN0 to VDD is blown and short circuited. 

Children
No Data
Related