Hello, I'm using nRF51822-mKIT for a research.
To verify ADC readings from analog input, I've connected P0_5 to GND and ran the following code:
uint16_t adc_result;
NRF_ADC->INTENSET = (ADC_INTENSET_END_Disabled << ADC_INTENSET_END_Pos); /*!< Interrupt enabled. */
// config ADC
NRF_ADC->CONFIG = (ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos) /*!< Analog external reference inputs disabled. */
| (ADC_CONFIG_PSEL_AnalogInput6 << ADC_CONFIG_PSEL_Pos)
| (ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos) /*!< Use internal 1.2V bandgap voltage as reference for conversion. */
| (ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos) /*!< Analog input specified by PSEL with 1/3 prescaling used as input for the conversion. */
| (ADC_CONFIG_RES_10bit << ADC_CONFIG_RES_Pos); /*!< 10bit ADC resolution. */
// enable ADC
NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled; /* Bit 0 : ADC enable. */
// start ADC conversion
NRF_ADC->TASKS_START = 1;
// wait for conversion to end
while (!NRF_ADC->EVENTS_END)
{}
NRF_ADC->EVENTS_END = 0;
//Save your ADC result
adc_result = NRF_ADC->RESULT;
//Use the STOP task to save current. Workaround for PAN_028 rev1.1 anomaly 1.
NRF_ADC->TASKS_STOP = 1;
return adc_result;
I was expecting adc_result to be 0x00, but I got a value of 0xAA. Funnier thing is, when I connected P0_5 to VCC (which is around 3V), I still get adc_result of 0xAA. I spent a lot of time trying to find the root cause.
- I tried changing ADC config, but none of the configuration gave me the expected value
- I read about LPCOMP that needs to be disabled before ADC gets enabled, so I tried that, but still no luck
- I doubted my hardware, so I swapped the eval board to a new one, but it the issue still remains.
Could someone give me an idea what might be a root cause?