2020-12-23 05:24 AM
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
2020-12-23 05:41 AM
You need to start the ADC clock prior to calibration. Plenty of examples to follow:
2021-01-07 11:57 PM
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