打印
[STM32F0]

STM32F030 ADC多通道DMA方式采集配置问题

[复制链接]
471|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
AD, ADC, DM, DMA, ST
我用的是STM32F030使用多通道DMA采集,发现F0芯片使用cubemx配置跟F1一样的,但是就是读值全都不对,原来F1没有遇到过这种问题,有用过的大神看下配置上有什么需要改的吗?之前有个帖子说自己添加通道,我也添加过了读值还是不对,只配置一个通道设置跟多通道一模一样读值就正确的,应该就是多通道添加有问题。
void MX_ADC_Init(void)

{

  ADC_ChannelConfTypeDef sConfig = {0};



  /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)

  */

  hadc.Instance = ADC1;

  hadc.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;

  hadc.Init.Resolution = ADC_RESOLUTION_12B;

  hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;

  hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;

  hadc.Init.EOCSelection = ADC_EOC_SEQ_CONV;

  hadc.Init.LowPowerAutoWait = DISABLE;

  hadc.Init.LowPowerAutoPowerOff = DISABLE;

  hadc.Init.ContinuousConvMode = ENABLE;

  hadc.Init.DiscontinuousConvMode = DISABLE;

  hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;

  hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

  hadc.Init.DMAContinuousRequests = ENABLE;

  hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED;

  if (HAL_ADC_Init(&hadc) != HAL_OK)

  {

    Error_Handler();

  }

  /** Configure for the selected ADC regular channel to be converted.

  */

  sConfig.Channel = ADC_CHANNEL_0;

  sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;

  sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;

  if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)

  {

    Error_Handler();

  }

  /** Configure for the selected ADC regular channel to be converted.

  */

  sConfig.Channel = ADC_CHANNEL_1;

  if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)

  {

    Error_Handler();

  }

  /** Configure for the selected ADC regular channel to be converted.

  */

  sConfig.Channel = ADC_CHANNEL_2;

  if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)

  {

    Error_Handler();

  }

  /** Configure for the selected ADC regular channel to be converted.

  */

  sConfig.Channel = ADC_CHANNEL_3;

  if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)

  {

    Error_Handler();

  }

  /** Configure for the selected ADC regular channel to be converted.

  */

  sConfig.Channel = ADC_CHANNEL_4;

  if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)

  {

    Error_Handler();

  }

  /** Configure for the selected ADC regular channel to be converted.

  */

  sConfig.Channel = ADC_CHANNEL_5;

  if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)

  {

    Error_Handler();

  }



}



这个是添加通道设置

void init_ADCRank(void)

{

ADC_ChannelConfTypeDef sConfig;

sConfig.Channel = ADC_CHANNEL_1;

sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;

sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;

HAL_ADC_ConfigChannel(&hadc, &sConfig);





sConfig.Channel = ADC_CHANNEL_2;

sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;

sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;

HAL_ADC_ConfigChannel(&hadc, &sConfig);





sConfig.Channel = ADC_CHANNEL_3;

sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;

sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;

HAL_ADC_ConfigChannel(&hadc, &sConfig);





sConfig.Channel = ADC_CHANNEL_4;

sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;

sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;

HAL_ADC_ConfigChannel(&hadc, &sConfig);



sConfig.Channel = ADC_CHANNEL_5;

sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;

sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;

HAL_ADC_ConfigChannel(&hadc, &sConfig);



}












favorite.png (13.42 KB )

favorite.png

使用特权

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

本版积分规则

2039

主题

7368

帖子

10

粉丝