cancel
Showing results for 
Search instead for 
Did you mean: 

ADC calibration problem for Stm32CubeIde?

adaniel
Associate III

 Chip:   STM32L030

 Trying to calibrate the ADC at startup with the following code into the initialization procedure:

   ADC1->CR |= 0X80000000;      // calibration started

   while (!(ADC1->ISR & 0X800));   // waiting for the calibration to finish

 When compiled with Atollic, version 9.2.0, this code works perfectly. But when compiled with Stm32CubeIde, it gets trapped into the calibration command which never finish!

11 REPLIES 11
adaniel
Associate III

Thanks for the advice! Since Atollic is dead and only STM32 is being updated, I wish to use STM32.The only problem, for the time being , is with the ADC calibration which I don't need. In my project the ADC is used to monitor a PIR device for motion detection. The exact value of the A/D is unimportant; the only relevant data is its rate of change.

Anyway, thanks for your attention. I see the case closed, but no solved, until some update in the future?

Piranha
Chief II

The calibration complete waiting has one more requirement. RM0451 section 13.3.3:

The ADCAL bit can remain set for some time even after EOCAL has been set. As a result, the software must wait for ADCAL=0 after EOCAL=1 to be able to set ADEN=1 for next ADC conversions.

After calibration ADC enable and conversion start cannot be done in a single operation. One must enable ADEN, wait for ADRDY and only then ADSTART can be set.

ADC1->CR |= 5;          // ADC started

ADRDY: ADC ready

This bit is set by hardware after the ADC has been enabled (bit ADEN=1) and when the ADC reaches a state where it is ready to accept conversion requests.

There is nothing technically wrong with read-modify-write operations, just some of them are unnecessary and can be replaced with simple writes. Also the fact that code compiles successfully or even works with some compiler version with some settings, doesn't prove it's correct. The code ir correct only when it formally guarantees the required sequence of actions.