Skip to main content
Explorer II
February 18, 2025
Solved

STM32 ADC Calibration Function

  • February 18, 2025
  • 1 reply
  • 1160 views

Good afternoon, 

 

I am currently trying to calibrate my ADC4 of my NUCLEO U545 and I am using the following function: 

HAL_ADCEx_Calibration_Start(&hadc4, CalibrationMode, SingleDiff);

As said before the first parameter is going to be the ADC4 that I am using but what about the other two parameters?

What are they exactly? Do i have to declare the parameters somewhere in the code? Is there anyway that I can see in the documentation what are this parameters and the value i have to introduce to them? And finally, the ADC1 configuration is done the same way as in the ADC4?

 

Thank you, 

 

Marc 

    This topic has been closed for replies.
    Best answer by TDK

    The source code is documented and shows what the arguments should be. In this case:

    /**
     * @brief Perform an ADC automatic self-calibration
     * Calibration prerequisite: ADC must be disabled (execute this
     * function before HAL_ADC_Start() or after HAL_ADC_Stop() ).
     * @PAram hadc ADC handle
     * @PAram CalibrationMode Selection of calibration offset or
     * linear calibration offset.
     * @arg ADC_CALIB_OFFSET Channel in mode calibration offset
     * @arg ADC_CALIB_OFFSET_LINEARITY Channel in mode linear calibration offset
     * @PAram SingleDiff Selection of single-ended or differential input
     * This parameter can be one of the following values:
     * @arg @ref ADC_SINGLE_ENDED Channel in mode input single ended
     * @arg @ref ADC_DIFFERENTIAL_ENDED Channel in mode input differential ended
     * @retval HAL status
     */
    HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef *hadc, uint32_t CalibrationMode, uint32_t SingleDiff)

     

    Probably you want this:

    HAL_ADCEx_Calibration_Start(&hadc4, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED);

     

    Further information on these can be found in the reference manual in the section "33.4.8 Calibration (ADCAL, ADCALLIN, ADC_CALFACT)".

     

    > And finally, the ADC1 configuration is done the same way as in the ADC4?

    Yes.

    1 reply

    TDKAnswer
    Super User
    February 18, 2025

    The source code is documented and shows what the arguments should be. In this case:

    /**
     * @brief Perform an ADC automatic self-calibration
     * Calibration prerequisite: ADC must be disabled (execute this
     * function before HAL_ADC_Start() or after HAL_ADC_Stop() ).
     * @PAram hadc ADC handle
     * @PAram CalibrationMode Selection of calibration offset or
     * linear calibration offset.
     * @arg ADC_CALIB_OFFSET Channel in mode calibration offset
     * @arg ADC_CALIB_OFFSET_LINEARITY Channel in mode linear calibration offset
     * @PAram SingleDiff Selection of single-ended or differential input
     * This parameter can be one of the following values:
     * @arg @ref ADC_SINGLE_ENDED Channel in mode input single ended
     * @arg @ref ADC_DIFFERENTIAL_ENDED Channel in mode input differential ended
     * @retval HAL status
     */
    HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef *hadc, uint32_t CalibrationMode, uint32_t SingleDiff)

     

    Probably you want this:

    HAL_ADCEx_Calibration_Start(&hadc4, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED);

     

    Further information on these can be found in the reference manual in the section "33.4.8 Calibration (ADCAL, ADCALLIN, ADC_CALFACT)".

     

    > And finally, the ADC1 configuration is done the same way as in the ADC4?

    Yes.