2016-07-27 06:00 AM
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 ADCsRCC -> AHB2RSTR &= (~RCC_AHB2RSTR_ADCRST); RCC -> AHB2ENR |= RCC_AHB2ENR_ADCEN; //Clock to the ADC moduleADC1 -> 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 onespera_us(50);//(waits
50 microsencon
ds)ADC1 -> ISR |= 0x000007FF; //Clear All FlagsADC123_COMMON -> CCR |= 0x00400000; //Enable ADCREFADC1-> CR &= 0xBFFFFFFF; //ADCALDIF=0, we are going to make a single ended calibrationADC1-> CR |= 0x80000000; //ADCAL=1, Begin calibrationwhile((ADC1->CR & 0x80000000)!=0); // Calibration never endsThe 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