Hello all,
I am trying to activate ADC to measure a voltage every few seconds using nrf51822. When it is done, I supposedly deactivate ADC so it does not consumes while I don't need it. I find that the consumption increases when I activate the ADC, but it does not decreases when it is finished, so I suppose I am not deactivating well.
Code:
Every few seconds, I run this function:
void measure_voltage(void)
{
uint32_t err_code;
// Configure ADC
NRF_ADC->INTENSET = ADC_INTENSET_END_Msk;
NRF_ADC->CONFIG = (ADC_CONFIG_RES_8bit << ADC_CONFIG_RES_Pos) |
(ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos) |
(ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos) |
(ADC_CONFIG_PSEL_Disabled << ADC_CONFIG_PSEL_Pos) |
(ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos);
NRF_ADC->EVENTS_END = 0;
NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;
// Enable ADC interrupt
err_code = sd_nvic_ClearPendingIRQ(ADC_IRQn);
APP_ERROR_CHECK(err_code);
err_code = sd_nvic_SetPriority(ADC_IRQn, NRF_APP_PRIORITY_LOW);
APP_ERROR_CHECK(err_code);
err_code = sd_nvic_EnableIRQ(ADC_IRQn);
APP_ERROR_CHECK(err_code);
NRF_ADC->EVENTS_END = 0; // Stop any running conversions.
NRF_ADC->TASKS_START = 1;
}
Then, I wait for the handler to come up:
void ADC_IRQHandler(void)
{
if (NRF_ADC->EVENTS_END != 0)
{
uint8_t adc_result;
NRF_ADC->EVENTS_END = 0;
adc_result = NRF_ADC->RESULT;
NRF_ADC->TASKS_STOP = 1;
NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Disabled;
paquet_advertising[0]=adc_result;
}
}
Am I missing something?
Thank you very much