cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 ADC Calibration Function

Marc3
Associate

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 

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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.

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

View solution in original post

1 REPLY 1
TDK
Guru

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.

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