[STM32H7] HAL_ADCEx_Calibration_Start()作AD校准出错

[复制链接]
 楼主| t60yz 发表于 2022-4-30 21:40 | 显示全部楼层 |阅读模式
AD, IO, ST, TI, ar
1. Calibration prerequisite: ADC must be disabled (execute this function before HAL_ADC_Start() or after HAL_ADC_Stop() )

函数说明很清楚,ADC校准需在ADC开始前或结束后。

2. 官方代码
  1. /**
  2.   * [url=home.php?mod=space&uid=247401]@brief[/url]  Perform an ADC automatic self-calibration
  3.   *         Calibration prerequisite: ADC must be disabled (execute this
  4.   *         function before HAL_ADC_Start() or after HAL_ADC_Stop() ).
  5.   * @param  hadc       ADC handle
  6. * @param  CalibrationMode       Selection of calibration offset or
  7.   *         linear calibration offset.
  8.   *           [url=home.php?mod=space&uid=2817080]@ARG[/url] ADC_CALIB_OFFSET       Channel in mode calibration offset
  9.   *           @arg ADC_CALIB_OFFSET_LINEARITY Channel in mode linear calibration offset
  10.   * @param  SingleDiff Selection of single-ended or differential input
  11.   *         This parameter can be one of the following values:
  12.   *           @arg [url=home.php?mod=space&uid=144993]@ref[/url] ADC_SINGLE_ENDED       Channel in mode input single ended
  13.   *           @arg @ref ADC_DIFFERENTIAL_ENDED Channel in mode input differential ended
  14.   * @retval HAL status
  15.   */
  16. HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef *hadc, uint32_t CalibrationMode, uint32_t SingleDiff)
  17. {
  18.   HAL_StatusTypeDef tmp_hal_status;
  19.   __IO uint32_t wait_loop_index = 0UL;

  20.   /* Check the parameters */
  21.   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
  22.   assert_param(IS_ADC_SINGLE_DIFFERENTIAL(SingleDiff));

  23.   /* Process locked */
  24.   __HAL_LOCK(hadc);

  25.   /* Calibration prerequisite: ADC must be disabled. */

  26.   /* Disable the ADC (if not already disabled) */
  27.   tmp_hal_status = ADC_Disable(hadc);

  28.   /* Check if ADC is effectively disabled */
  29.   if (tmp_hal_status == HAL_OK)
  30.   {
  31.     /* Set ADC state */
  32.     ADC_STATE_CLR_SET(hadc->State,
  33.                       HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
  34.                       HAL_ADC_STATE_BUSY_INTERNAL);

  35.     /* Start ADC calibration in mode single-ended or differential */
  36.     LL_ADC_StartCalibration(hadc->Instance, CalibrationMode, SingleDiff);

  37.     /* Wait for calibration completion */
  38.     while (LL_ADC_IsCalibrationOnGoing(hadc->Instance) != 0UL)
  39.     {
  40.       wait_loop_index++;
  41.       if (wait_loop_index >= ADC_CALIBRATION_TIMEOUT)
  42.       {
  43.         /* Update ADC state machine to error */
  44.         ADC_STATE_CLR_SET(hadc->State,
  45.                           HAL_ADC_STATE_BUSY_INTERNAL,
  46.                           HAL_ADC_STATE_ERROR_INTERNAL);

  47.         /* Process unlocked */
  48.         __HAL_UNLOCK(hadc);

  49.         return HAL_ERROR;
  50.       }
  51.     }

  52.     /* Set ADC state */
  53.     ADC_STATE_CLR_SET(hadc->State,
  54.                       HAL_ADC_STATE_BUSY_INTERNAL,
  55.                       HAL_ADC_STATE_READY);
  56.   }
  57.   else
  58.   {
  59.     SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL);

  60.     /* Note: No need to update variable "tmp_hal_status" here: already set    */
  61.     /*       to state "HAL_ERROR" by function disabling the ADC.              */
  62.   }

  63.   /* Process unlocked */
  64.   __HAL_UNLOCK(hadc);

  65.   /* Return function status */
  66.   return tmp_hal_status;
  67. }





olivem55arlowe 发表于 2022-12-6 18:38 | 显示全部楼层
运行ADC之前就是需要校准的。              
ccook11 发表于 2022-12-6 18:47 | 显示全部楼层
AD校准有什么错误呢?              
Undshing 发表于 2022-12-6 18:58 | 显示全部楼层
校准一下试试
AloneKaven 发表于 2022-12-6 20:34 | 显示全部楼层
校准有什么错误啊?
jtracy3 发表于 2022-12-10 08:47 | 显示全部楼层
stm32cubmex生成的代码就是这个样子的。
Henryko 发表于 2022-12-10 15:51 | 显示全部楼层
用cubeMX直接生成试试
yeates333 发表于 2022-12-12 11:01 | 显示全部楼层
不同通道之间有干扰怎么解决呢?              
nomomy 发表于 2022-12-15 09:53 | 显示全部楼层
必须在ADC转换启动前或停止后  
Bowclad 发表于 2022-12-15 10:57 | 显示全部楼层
直接生成一下试试
mickit 发表于 2022-12-15 22:42 | 显示全部楼层
自动校准ADC,调用即可吧   
nomomy 发表于 2022-12-16 23:25 | 显示全部楼层
ADC的配置很简答,直接DMA+ADC就行。
gygp 发表于 2022-12-17 10:29 | 显示全部楼层
有些芯片不支持校准               
macpherson 发表于 2022-12-17 11:58 | 显示全部楼层
这个代码可以运行的。              
belindagraham 发表于 2023-3-4 20:35 | 显示全部楼层
ADC校准需在ADC开始前或结束后。  
lzbf 发表于 2023-3-4 22:13 | 显示全部楼层
这个使用的是哪个库函数呢              
Stahan 发表于 2023-3-5 19:47 | 显示全部楼层
cubeMX生成的代码吗?
claretttt 发表于 2023-3-7 20:32 | 显示全部楼层
ADC校准需在ADC开始前或结束后。  
pentruman 发表于 2023-3-10 10:46 | 显示全部楼层
这个使用的是哪个库函数呢              
51xlf 发表于 2023-3-18 11:40 | 显示全部楼层
使用hal库中adc采样频率如何查看和修改?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

187

主题

1189

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部