cancel
Showing results for 
Search instead for 
Did you mean: 

How to calibrate STM32L412 ADC

deep_rune
Associate III

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

2 REPLIES 2
TDK
Guru

You need to start the ADC clock prior to calibration. Plenty of examples to follow:

https://github.com/STMicroelectronics/STM32CubeL4/blob/d023c0d560ace11509f9b761c8913a9e48fcf194/Projects/NUCLEO-L4R5ZI/Examples/ADC/ADC_RegularConversion_Polling/Src/main.c

If you feel a post has answered your question, please click "Accept as Solution".
Imen.D
ST Employee

Hi @deep_rune​ ,

If @TDK​ 's​  answer resolved your issue, please mark his reply as best answer by clicking on "Select as Best".

If you still need help, feel free to ask your question in more detail.

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen