1. Calibration prerequisite: ADC must be disabled (execute this function before HAL_ADC_Start() or after HAL_ADC_Stop() )
函数说明很清楚,ADC校准需在ADC开始前或结束后。
2. 官方代码- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] 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.
- * [url=home.php?mod=space&uid=2817080]@ARG[/url] 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 [url=home.php?mod=space&uid=144993]@ref[/url] 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)
- {
- HAL_StatusTypeDef tmp_hal_status;
- __IO uint32_t wait_loop_index = 0UL;
- /* Check the parameters */
- assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
- assert_param(IS_ADC_SINGLE_DIFFERENTIAL(SingleDiff));
- /* Process locked */
- __HAL_LOCK(hadc);
- /* Calibration prerequisite: ADC must be disabled. */
- /* Disable the ADC (if not already disabled) */
- tmp_hal_status = ADC_Disable(hadc);
- /* Check if ADC is effectively disabled */
- if (tmp_hal_status == HAL_OK)
- {
- /* Set ADC state */
- ADC_STATE_CLR_SET(hadc->State,
- HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
- HAL_ADC_STATE_BUSY_INTERNAL);
- /* Start ADC calibration in mode single-ended or differential */
- LL_ADC_StartCalibration(hadc->Instance, CalibrationMode, SingleDiff);
- /* Wait for calibration completion */
- while (LL_ADC_IsCalibrationOnGoing(hadc->Instance) != 0UL)
- {
- wait_loop_index++;
- if (wait_loop_index >= ADC_CALIBRATION_TIMEOUT)
- {
- /* Update ADC state machine to error */
- ADC_STATE_CLR_SET(hadc->State,
- HAL_ADC_STATE_BUSY_INTERNAL,
- HAL_ADC_STATE_ERROR_INTERNAL);
- /* Process unlocked */
- __HAL_UNLOCK(hadc);
- return HAL_ERROR;
- }
- }
- /* Set ADC state */
- ADC_STATE_CLR_SET(hadc->State,
- HAL_ADC_STATE_BUSY_INTERNAL,
- HAL_ADC_STATE_READY);
- }
- else
- {
- SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL);
- /* Note: No need to update variable "tmp_hal_status" here: already set */
- /* to state "HAL_ERROR" by function disabling the ADC. */
- }
- /* Process unlocked */
- __HAL_UNLOCK(hadc);
- /* Return function status */
- return tmp_hal_status;
- }
|