cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMx doesn't configure Sampling Time on more than one ADC channel

Bruno Conceição
Associate II
Posted on June 01, 2017 at 13:59

Hi,

I'm quite new to ST environment so please excuse any big mistake.

I,m using STM32CubeMX (4.20.1) and a Nucleo F429ZI to evaluate for an upcoming project. While experimenting with ADC I've realized that with Scan Conversion Mode enabled for 3 ADC channels (ADC1) the generated code doesn't configure the sampling time for the 2nd and 3rd channel.

Is this a bug or I'm doing something wrong?

Best regards,

static void MX_ADC1_Init(void)

{

  ADC_ChannelConfTypeDef sConfig;

    /**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_DIV4;

  hadc1.Init.Resolution = ADC_RESOLUTION_12B;

  hadc1.Init.ScanConvMode = ENABLE;

  hadc1.Init.ContinuousConvMode = DISABLE;

  hadc1.Init.DiscontinuousConvMode = DISABLE;

  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

  hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;

  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;

  hadc1.Init.NbrOfConversion = 3;

  hadc1.Init.DMAContinuousRequests = DISABLE;

  hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;

  if (HAL_ADC_Init(&hadc1) != HAL_OK)

  {

    Error_Handler();

  }

    /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

    */

  sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;

  sConfig.Rank = 1;

  sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES;

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

  {

    Error_Handler();

  }

    /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

    */

  sConfig.Channel = ADC_CHANNEL_0;

  sConfig.Rank = 2;

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

  {

    Error_Handler();

  }

    /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

    */

  sConfig.Channel = ADC_CHANNEL_VREFINT;

  sConfig.Rank = 3;

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

  {

    Error_Handler();

  }

}

1 REPLY 1
Cyril FENARD
ST Employee
Posted on September 26, 2017 at 13:21

Hi,

sConfig variable sets its SamplingTime field to ADC_SAMPLETIME_480CYCLES at first, then this structure is used for next calls without change to this SamplingTime field.

Did you check with debugger that the SamplingTime value field is passed to HAL_ADC_ConfigChannel() with the same value?

Regards.

Cyril