cancel
Showing results for 
Search instead for 
Did you mean: 

ADC Calibration Fails After wake up from STOP mode

sebastian239955_st
Associate
Posted on July 27, 2016 at 15:00

Hello everyone.

I am writing an application for a STM32L4 that is 99% of the time in stop mode 2 to save power, and some time it wake up (with an exti) based on an externall event. When it wakes up it takes a measurement of a voltage using the ADC1, stores it on a micro sd card and goes back to STOP mode.

In order to save as much power as possible, I have made a function that power up the ADC, performs the calibration, takes the measurement and power down the ADC including clock gating it. This funcion works well, no matter how many times I call it.

However, after going to STOP mode, when the microcontroller wakes up and takes the measurement, the internat auto calibration function does not work. I reset the perhiperal, then aply clock to it:

RCC -> AHB2RSTR |= RCC_AHB2RSTR_ADCRST; //Reset ADCs

RCC -> AHB2RSTR &= (~RCC_AHB2RSTR_ADCRST);

RCC -> AHB2ENR  |= RCC_AHB2ENR_ADCEN; //Clock to the ADC module

ADC1 -> CR = (ADC1 -> CR & 0xDFFFFFFF); //DEEPPWD=0, Deep power down = 0 

espera_us(10); //(waits 10 microsenconds)

ADC1 -> CR = (ADC1 -> CR & 0xEFFFFFFF) + 0x10000000; //ADVREGEN=1 ADC regulator on

espera_us(50);

//(waits

5

0 microsencon

ds)

ADC1 -> ISR |= 0x000007FF; //Clear All Flags

ADC123_COMMON -> CCR |= 0x00400000; //Enable ADCREF

ADC1-> CR &= 0xBFFFFFFF; //ADCALDIF=0, we are going to make a single ended calibration

ADC1-> CR |= 0x80000000; //ADCAL=1, Begin calibration

while((ADC1->CR & 0x80000000)!=0); // Calibration never ends

The ADCAL bit never goes back to 0 indicating the end of the calibration process.

I don't know where is the problem.

Thanks in advance for your help.

#adc-stop-calibration-stm32l4
0 REPLIES 0