HAL_ADCEx_Calibration_Start
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-23 3:43 AM
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?
Solved! Go to Solution.
- Labels:
-
STM32CubeIDE
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-23 6:49 AM
It's documented in the source code as well as at the link I provided.
Pass ADC_SINGLE_ENDED.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-23 5:11 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-23 5:15 AM - edited ‎2025-04-23 5:16 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-23 5:37 AM - edited ‎2025-04-23 5:55 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-23 6:00 AM - edited ‎2025-04-23 6:02 AM
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.
HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef *hadc, uint32_t SingleDiff)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-23 6:24 AM
I cannot figure out what value to pass when I want Single ended conversion. Can't find it documented anywhere.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-23 6:49 AM
It's documented in the source code as well as at the link I provided.
Pass ADC_SINGLE_ENDED.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-23 7:08 AM - edited ‎2025-04-23 7:12 AM
@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.
