How to calibrate the ADCs on STM32 using the HAL library?
Hello,
I am using the the HAL library for calibrating the ADC on STM32L in single ended mode
As per the documentation and Cube ADC examples I make a call to :
HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED) at system startup.
Do I also need to call HAL_ADCEx_Calibration_GetValue() and and use this value? or is the calibration factor already applied?
Below is my code to read the ADC value.
uint16_t get_adc_val(
int input_index
) { uint16_t uhADCxConvertedValue = 0;ADC_ChannelConfTypeDef sConfig;
/*Set the adc channel based on index*/
if (input_index==0) { sConfig.Channel = ADC_CHANNEL_8; } else if (input_index==1) { sConfig.Channel = ADC_CHANNEL_11; } else if (input_index==2) { sConfig.Channel = ADC_CHANNEL_12; }sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5; sConfig.SingleDiff = ADC_SINGLE_ENDED; sConfig.OffsetNumber = ADC_OFFSET_NONE; sConfig.Offset = 0; if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { Error_Handler(); }/*Start the conversion process*/
if (HAL_ADC_Start(&hadc1) != HAL_OK) { Error_Handler(); }/*Wait for the end of conversion*/
if (HAL_ADC_PollForConversion(&hadc1, 1000) != HAL_OK) { Error_Handler(); } else /* ADC conversion completed */ { uhADCxConvertedValue = HAL_ADC_GetValue(&hadc1); } return uhADCxConvertedValue;}Thanks!
#adc #hal #calibration