How to calibrate STM32L412 ADC
I have a STM32L412, I am using a 3V external reference but my ADC is not very accurate - it never reaches its full value, even though the voltage present is the same as the external voltage. I want to calibrate the ADC to see if it improves the performance.
The HAL reference states I need to use the HAL_ADCEx_Calibration_Start before the ADC is enabled, so I have used it just before the HAL initialisation, but when I do this my ADC stops working - none of the bits are set in the subsequent initialisation etc. My exact code for the setup is below. What do I need to do to make HAL_ADCEx_Calibration_Start work properly?
int main(void)
{
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_I2C2_Init();
HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED);
MX_ADC1_Init();
MX_TIM1_Init();
MX_TIM2_Init();
MX_RNG_Init();
MX_TIM16_Init();
ADC12_COMMON ->CCR |= 1<<19 | 1 <<17; // set ADC clock options
ADC1->CR |= 1>>0; // enable ADC