cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_ADCEx_Calibration_Start

chriskuku
Senior II

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?

7 REPLIES 7
TDK
Guru

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".
Hl_st
ST Employee

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.

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?

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".

I cannot figure out what value to pass when I want Single ended conversion. Can't find it documented anywhere.

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".

@TDK wrote:

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

Pass ADC_SINGLE_ENDED.


Thanks. I didn't find it on the first glance. I would have expected the autocomplete to suggest these defines.

But now, that you are saying this, I found it in

stm32h5xx_hal_adc_ex.c

 

in the function description.