cancel
Showing results for 
Search instead for 
Did you mean: 

How to setup Stm32G0 ADC to read 17th Channel (with "not fully configurable sequencer").

PDzie.1
Associate II

I have trouble reading from 17th channel of STM32G0B1 MCU, which is PC4 pin.

I have to read from channel 0 and 17. If I configure ADC for single channel it reads fine from Ch0, but cannot read from Ch17 (I got value from Ch0 instead). If I configure it to read from Ch0 and Ch17 using DMA, values in DMA array are not changing at all.

I share cube-generated MX_ADC1_Init below

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_SEQ_CONV;
  hadc1.Init.LowPowerAutoWait = DISABLE;
  hadc1.Init.LowPowerAutoPowerOff = DISABLE;
  hadc1.Init.ContinuousConvMode = DISABLE;
  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_160CYCLES_5;
  hadc1.Init.OversamplingMode = DISABLE;
  hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_LOW;
  if (HAL_ADC_Init(&hadc1) != HAL_OK)
  {
    Error_Handler();
  }
 
  /** Configure Regular Channel
  */
  sConfig.Channel = ADC_CHANNEL_0;
  sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
 
  /** Configure Regular Channel
  */
  sConfig.Channel = ADC_CHANNEL_17;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN ADC1_Init 2 */
 
  /* USER CODE END ADC1_Init 2 */
 
}

I couldn't find any example how to use ADC with "not fully configurable sequencer". I can live with polling for Ch0 and Ch17 separately, but also have no clue how to make it work.

Best regards

2 REPLIES 2

> I couldn't find any example how to use ADC with "not fully configurable sequencer". I

IMO the description in Channel selection subchapter of ADC chapter is fairly comprehensible, so if it can't be clicked in CubeMX, just go and program it using registers.

JW

EBen-
Associate II

Hi,

Same problem here.

have you found a solution?

I'm using STM32G041J6M6 chip, and trying to read from ADC1 channel 11 & from channel 16. when channel 11 gives good value, but when reading from channel 16 sometimes it gives me the right answer and sometimes it gives me the value in ch11.

any help would be appreciated!

EB