[其他ST产品] stm32cube测试ADC问题转换结果不准确.

[复制链接]
 楼主| cr315 发表于 2022-4-15 10:15 | 显示全部楼层 |阅读模式
大家好,使用stm32cube测试单通道ADC发现转换后的结果不准,相差了300mv左右,而使用库版本程序测试转换电压正常.
cube设置如图,主程序代码如下:

#include "stm32f1xx_hal.h"

/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private variables ---------------------------------------------------------*/
ADC_HandleTypeDef hadc1;
DMA_HandleTypeDef hdma_adc1;

/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_ADC1_Init(void);

/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/


/* USER CODE END PFP */

/* USER CODE BEGIN 0 */
uint16_t ADC_ConvertedValue[1];
      
//extern ADC_HandleTypeDef hadc1;
/* USER CODE END 0 */

int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_ADC1_Init();

  /* USER CODE BEGIN 2 */
HAL_ADC_Start_DMA(&hadc1,(uint32_t *)ADC_ConvertedValue,1);  
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
      
  }
  /* USER CODE END 3 */

}
调试2天了,无果,希望做过的朋友帮忙看看.
df51dad1778f9d9f3e3570db1d184268.png f30da77799b7818d5b867edeade80891.png 14231e2727a458099cc02275959ef221.png

 楼主| cr315 发表于 2022-4-15 10:16 | 显示全部楼层
补充下DMA的设置部分.
519216258d57a8d055.png
内政奇才 发表于 2022-4-15 10:30 | 显示全部楼层
我以前用HAL1.3库和1.2。1库,同样的程序,对内部参考电压的采样差别很大,不知道什么原因(有校准)。
七毛钱 发表于 2022-4-16 10:00 | 显示全部楼层
DMA启动前先校准,注意adc频率,太快也会导致偏差,之前遇到过,增大采样周期后与专门的adc芯片对比采集的数据一样,差距很小(个位数)
麻花油条 发表于 2022-4-16 10:00 | 显示全部楼层
在while 前面添加HAL_ADCEx_Calibration_Start(&hadc1);函数校准
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1448

主题

4810

帖子

0

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