‎2020-10-02 10:48 AM
I've had some issues to calculate the correct VREF+ voltage for the ADC on an STM32L476RGT6 MCU. After some investigation, I isolated the cause to be that I called `HAL_ADC_DeInit()` on ADC2 after I used it during setup before the main loop. If I just remove the call to `HAL_ADC_DeInit(&hadc2);`, ADC1 reads the vrefint channel correctly.
Any ideas? I can just keep ADC2 initialized, but the application will need to consume as little power as possible, since it will be powered by a battery and solar panel. Is deinitializing the ADC actually going to save power, or doesn't it matter?
Attached are the main.c and stm32l4xx_hal_msp.c files for my minimal reproduction project. If I comment the call to `HAL_ADC_DeInit(&hadc2)` on line 132 of main.c, vrefint is read correctly. If I just add that line back and change nothing else, vrefint reads 2-3x too low.
Solved! Go to Solution.
‎2020-10-09 08:34 AM
Hi @Community member​ ,
HAL_ADC_DeInit calls HAL_ADC_MspDeInit. In this later, the call of __HAL_RCC_ADC_CLK_DISABLE will reset all ADCs as they are using the same clock.
As a workaround, you can call MX_ADC1_Init() after HAL_ADC_DeInit(&hadc2).
As your purpose is to minimize power consumption, you can put ADC2 in Deep-power-down by writing 1 to DEEPPWD inADC_CR register, instead of calling HAL_ADC_DeInit.
For farther recommendations on how to optimize power consumption for your application, have a look to AN4746.
-Amel
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
‎2020-10-09 08:34 AM
Hi @Community member​ ,
HAL_ADC_DeInit calls HAL_ADC_MspDeInit. In this later, the call of __HAL_RCC_ADC_CLK_DISABLE will reset all ADCs as they are using the same clock.
As a workaround, you can call MX_ADC1_Init() after HAL_ADC_DeInit(&hadc2).
As your purpose is to minimize power consumption, you can put ADC2 in Deep-power-down by writing 1 to DEEPPWD inADC_CR register, instead of calling HAL_ADC_DeInit.
For farther recommendations on how to optimize power consumption for your application, have a look to AN4746.
-Amel
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
‎2020-10-10 06:00 AM
Thanks @Amel NASRI​ for the explanation. Of course disabling the clock will mess with things! I'll take a look at AN4746.
‎2020-10-12 01:28 AM
Hello @Community member​
Thanks for your post.
Feedback raised internally to be reviewed and treated accordingly to the priority. We will give you an update as soon as possible.
Thanks for your contribution!
Best regards,
Nesrine
‎2020-10-12 09:49 AM
Thanks! The behaviour I'd expect would be that the HAL only disables the clock if all ADCs are deinitialized, not when any ADC is deinitialized.
‎2020-10-13 04:34 AM
This is exactly what was suggested and is being internally reviewed :)
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.