Skip to main content
chriskuku
Senior II
April 23, 2025
Solved

HAL_ADCEx_Calibration_Start

  • April 23, 2025
  • 2 replies
  • 1046 views

Just a question: I'm using the following code snippet:

 

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
	if (htim == mod_timer){
		pwm_timer->Instance->CCR4 = sinetab[loop_cnt++]*global_adc1/4096.;	//setzt neuen PWM-Wert aus Tabelle
	 if(loop_cnt == MAX_SAMPLES){
			loop_cnt=0;
			HAL_ADC_Start_IT(&hadc1);
			HAL_GPIO_WritePin(LED_GPIO_Port,LED_Pin, SET);
	 }
	}
}
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc)
{
	global_adc1= HAL_ADC_GetValue(hadc);
	HAL_GPIO_WritePin(LED_GPIO_Port,LED_Pin,RESET);
}

 

 

Do I have to care about  HAL_ADCEx_Calibration_Start(&hadc1 );
If yes, I assume I would do that once in program start in main()? And how do I wait for calibration completion?

Best answer by TDK

It's documented in the source code as well as at the link I provided.

Pass ADC_SINGLE_ENDED.

2 replies

TDK
Super User
April 23, 2025

What chip are you using?

On a lot of families, you must calibrate the ADC before using it.

HAL_ADCEx_Calibration_Start completes before it returns. No additional waiting needed.

"If you feel a post has answered your question, please click ""Accept as Solution""."
chriskuku
chriskukuAuthor
Senior II
April 23, 2025

Thanks. I'm using H503.

 

BTW, what I don't understand:

The call that is accepted, is 

HAL_ADCEx_Calibration_Start(hadc);

 

But when I type CTRL-Space (suggestion/autocomplete), I'm getting

HAL_ADCEx_Calibration_Start(hadc, SingleDiff);

 

But using the latter leads to a syntax error.There is no HAL_ADCEx_CalibrationStart with two parameters.


EDIT: I'm confused. Suddenly I'm asked for two parameters. Has the interface changed? And if yes, what is "SingleDiff" (sounds like Single vs. Differential mode). But what are the defines for this?

TDK
Super User
April 23, 2025

The call is different on other families. I would suggest relying on the source code and API documentation first, and "autocomplete" second.

On the H5, with the latest library, it requires two arguments.

stm32h5xx-hal-driver/Src/stm32h5xx_hal_adc_ex.c at 8c41bbe0b445f5036163d2ac637b50962d8b2f21 · STMicroelectronics/stm32h5xx-hal-driver

HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef *hadc, uint32_t SingleDiff)
"If you feel a post has answered your question, please click ""Accept as Solution""."
ST Employee
April 23, 2025

Hello,

for better ADC results should be called HAL_ADCEx_Calibration_Start(&hadc1 ); function once at the beginning of the program (between calling MX_ADC1_Init(); and HAL_ADC_Start_xxx();). The calibration function provides waiting for calibration complete inside. No waiting for calibration complete is needed.