Showing results for 
Search instead for 
Did you mean: 

stm32g030k8 ADC

Associate III

Hi I am working on multichannel ADC ,if its a single conversion I am getting correct values but when it is more than 1 i am getting same conversion values from all channels.


void Adc_Vbat(void)
	 ADC_ChannelConfTypeDef sConfig = {0};
	 sConfig.Channel = ADC_CHANNEL_16;
	 sConfig.Rank = ADC_REGULAR_RANK_1;
	 sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_1;
	  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)

void ADC_Mains(void)
	ADC_ChannelConfTypeDef sConfig = {0};
	sConfig.Channel = ADC_CHANNEL_5;
		  		  sConfig.Rank = ADC_REGULAR_RANK_1;
		  		  sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_1;
		  		  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
static void MX_ADC1_Init(void)

  /* USER CODE BEGIN ADC1_Init 0 */

  /* USER CODE END ADC1_Init 0 */

  ADC_ChannelConfTypeDef sConfig = {0};

  /* USER CODE BEGIN ADC1_Init 1 */

  /* USER CODE END ADC1_Init 1 */

  /** 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_SEQ_FIXED;
  hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  hadc1.Init.LowPowerAutoWait = DISABLE;
  hadc1.Init.LowPowerAutoPowerOff = DISABLE;
  hadc1.Init.ContinuousConvMode = ENABLE;
  hadc1.Init.NbrOfConversion = 1;
  hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc1.Init.DMAContinuousRequests = DISABLE;
  hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
  hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_39CYCLES_5;
  hadc1.Init.OversamplingMode = DISABLE;
  hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
  if (HAL_ADC_Init(&hadc1) != HAL_OK)


Can someone points out the error I made please 

ST Employee

Hello @meena,

Here some guidance :

  • Do you want to use the polling mode ? You have to respect the four points below for ADC Conversion :
    • Activate ADC peripheral and start conversions using function HAL_ADC_Start()
    • Wait for ADC conversion completion using function HAL_PollForConversion()
    • Retrieve conversion results using function HAL_ADC_GetValue()
    • Stop conversion and disable the ADC peripheral using function HAL_ADC_Stop()
  • But in the polling mode, you are polling the EOC (End Of Conversion) single flag configured with EOCSelection. You should set this parameter to ADC_EOC_SEQ_CONV and poll this flag to indicate the end of sequence conversions because you have multichannel.
  • For ScanConvMode, ADC_SCAN_SEQ_FIXED means not fully configurable: sequencer length and each rank affection to a channel are fixed by channel HW number (channel 0 fixed on rank 0, channel 1 fixed on rank 1...) . You have to use ADC_SCAN_ENABLE if you want to configure it yourself.
  • You also need to enter the right number of channel in NbrOfConversion parameter (number of ranks that will be converted, if you use other ranks...).

Best Regards,


To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Senior II

you need to use the ADC's scanning mode properly. The scanning mode allows you to perform conversions on multiple channels by specifying their sequence.

You can get help from the following threads.