打印
[STM32U5]

STM32U575 ADC采样

[复制链接]
301|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
zyj213|  楼主 | 2022-8-30 16:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
目前在调试STM32U575的ADC驱动,系统时钟及ADC初始化接口相同,但是从单驱动调试OK情况下移植至业务代码中出现ADC校准超时,有知道什么原因吗? ADC Init Failed. Error happened in the adc calibration process. How to solve it

使用特权

评论回复
沙发
zyj213|  楼主 | 2022-8-30 16:34 | 只看该作者
    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;

      UNUSED(SingleDiff); /* STM32U5 calibration is not making difference between Single and Diff ended */
      /* We keep this to be inligne with old products API and for any further use */

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

      __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);

        /* 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);

            __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.              */
      }

      __HAL_UNLOCK(hadc);

      return tmp_hal_status;
    }

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

34

主题

143

帖子

0

粉丝