Skip to main content
chriskuku
Senior II
Apr 23, 2025 10:43 AM UTC
Solved

HAL_ADCEx_Calibration_Start

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?

This topic has been closed for replies.
TDK
TDKBest answer
Apr 23, 2025 1:49 PM UTC

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

Pass ADC_SINGLE_ENDED.

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

7 replies

TDK
Apr 23, 2025 12:11 PM UTC

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
Apr 23, 2025 12:37 PM UTC

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
Apr 23, 2025 1:00 PM UTC

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
Apr 23, 2025 12:15 PM UTC

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.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.