HAL with CubeMX ADC2 deinit causes ADC1 to read vrefint channel incorrectly.
- October 2, 2020
- 5 replies
- 3170 views
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.
