STM32
直播中

邓长生

10年用户 916经验值
擅长:可编程逻辑
私信 关注
[问答]

STM32G030K6T6使用HAL库ADC DMA多通道采样数据为什么不正确?

ADC DMA多通道  进行采样时,获取到得数据与实际不一致,单通道时是对的

void MX_ADC1_Init(void)
{
  ADC_ChannelConfTypeDef sConfig = {0};

  /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
  */
  hadc1.Instance = ADC1;
  hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
  hadc1.Init.Resolution = ADC_RESOLUTION_12B;
  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
  hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  hadc1.Init.LowPowerAutoWait = DISABLE;
  hadc1.Init.LowPowerAutoPowerOff = DISABLE;
  hadc1.Init.ContinuousConvMode = ENABLE;
  hadc1.Init.NbrOfConversion = 12;
  hadc1.Init.DiscontinuousConvMode = DISABLE;
  hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc1.Init.DMAContinuousRequests = ENABLE;
  hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
  hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_39CYCLES_5;
  hadc1.Init.SamplingTimeCommon2 = ADC_SAMPLETIME_39CYCLES_5;
  hadc1.Init.OversamplingMode = DISABLE;
  hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
  if (HAL_ADC_Init( hadc1) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Regular Channel
  */

  sConfig.Channel = ADC_CHANNEL_0;
  sConfig.Rank = 0;
  sConfig.SamplingTime = ADC_SAMPLETIME_39CYCLES_5;
  if (HAL_ADC_ConfigChannel( hadc1,  sConfig) != HAL_OK)
  {
    Error_Handler();
  }

        sConfig.Channel = ADC_CHANNEL_1;
  sConfig.Rank = 1;
  if (HAL_ADC_ConfigChannel( hadc1,  sConfig) != HAL_OK)
  {
    Error_Handler();
  }
        
        sConfig.Channel = ADC_CHANNEL_2;
sConfig.Rank = 2;
  if (HAL_ADC_ConfigChannel( hadc1,  sConfig) != HAL_OK)
  {
    Error_Handler();
  }
        
        sConfig.Channel = ADC_CHANNEL_3;
  sConfig.Rank = 3;
  if (HAL_ADC_ConfigChannel( hadc1,  sConfig) != HAL_OK)
  {
    Error_Handler();
  }
        
        sConfig.Channel = ADC_CHANNEL_4;
  sConfig.Rank = 4;
  if (HAL_ADC_ConfigChannel( hadc1,  sConfig) != HAL_OK)
  {
    Error_Handler();
  }
        
        sConfig.Channel = ADC_CHANNEL_5;
  sConfig.Rank = 5;
  if (HAL_ADC_ConfigChannel( hadc1,  sConfig) != HAL_OK)
  {
    Error_Handler();
  }
        
        sConfig.Channel = ADC_CHANNEL_6;
  sConfig.Rank = 6;
  if (HAL_ADC_ConfigChannel( hadc1,  sConfig) != HAL_OK)
  {
    Error_Handler();
  }
        
        sConfig.Channel = ADC_CHANNEL_7;
  sConfig.Rank = 7;
  if (HAL_ADC_ConfigChannel( hadc1,  sConfig) != HAL_OK)
  {
    Error_Handler();
  }
        
        sConfig.Channel = ADC_CHANNEL_8;
  sConfig.Rank = 8;
  if (HAL_ADC_ConfigChannel( hadc1,  sConfig) != HAL_OK)
  {
    Error_Handler();
  }
        
        sConfig.Channel = ADC_CHANNEL_9;
  sConfig.Rank = 9;
  if (HAL_ADC_ConfigChannel( hadc1,  sConfig) != HAL_OK)
  {
    Error_Handler();
  }
        
        sConfig.Channel = ADC_CHANNEL_10;
  sConfig.Rank = 10;
  if (HAL_ADC_ConfigChannel( hadc1,  sConfig) != HAL_OK)
  {
    Error_Handler();
  }
        
        sConfig.Channel = ADC_CHANNEL_11;
  sConfig.Rank = 11;
  if (HAL_ADC_ConfigChannel( hadc1,  sConfig) != HAL_OK)
  {
    Error_Handler();
  }
}



void adc_Dma_start(void)
{
        HAL_ADCEx_Calibration_Start( hadc1);
        HAL_ADC_Start_DMA( hadc1,(uint32_t *) adcBuff,12);
}

回帖(1)

刘凯

2024-3-29 15:38:37
关于G0系列的ADC,你要注意下有两种采集序列的选择问题,如果你选择了 Sequencer set of fully configurable, 此时最多支持8个通道,而且这8个通道还只能在CH0~CH14间选择。如果你希望转换的通道超过8个,请选择 not fully configurable模式。
举报

更多回帖

发帖
×
20
完善资料,
赚取积分