cancel
Showing results for 
Search instead for 
Did you mean: 

ADC read error after updating to new version of cubemx 5.6

Shrikant Patel_2
Associate II

Hi I am using below configuration to read adc channels but I get some good values and some very bad values.

My configurations are :

void MX_ADC1_Init(void)

{

 /* USER CODE BEGIN ADC1_Init 0 */

 /* USER CODE END ADC1_Init 0 */

 ADC_MultiModeTypeDef multimode = {0};

 ADC_ChannelConfTypeDef sConfig = {0};

 /* USER CODE BEGIN ADC1_Init 1 */

 /* USER CODE END ADC1_Init 1 */

 /** Common config 

 */

 hadc1.Instance = ADC1;

 hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV8;

 hadc1.Init.Resolution = ADC_RESOLUTION_12B;

 hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;

 hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;

 hadc1.Init.LowPowerAutoWait = DISABLE;

 hadc1.Init.ContinuousConvMode = DISABLE;

 hadc1.Init.NbrOfConversion = 1;

 hadc1.Init.DiscontinuousConvMode = DISABLE;

 hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;

 hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

 hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;

 hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;

 hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;

 hadc1.Init.OversamplingMode = DISABLE;

 if (HAL_ADC_Init(&hadc1) != HAL_OK)

 {

  Error_Handler();

 }

 /** Configure the ADC multi-mode 

 */

 multimode.Mode = ADC_MODE_INDEPENDENT;

 if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)

 {

  Error_Handler();

 }

 /** Configure Regular Channel 

 */

 sConfig.Channel = ADC_CHANNEL_3;

 sConfig.Rank = ADC_REGULAR_RANK_1;

 sConfig.SamplingTime = ADC_SAMPLETIME_64CYCLES_5;

 sConfig.SingleDiff = ADC_SINGLE_ENDED;

 sConfig.OffsetNumber = ADC_OFFSET_NONE;

 sConfig.Offset = 0;

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

 {

  Error_Handler();

 }

 /* USER CODE BEGIN ADC1_Init 2 */

 /* USER CODE END ADC1_Init 2 */

}

and function to read :

 ADC_ChannelConfTypeDef sConfig;

  uint32_t retval;

  HAL_StatusTypeDef result = HAL_OK;

  sConfig.Channel = ch;

  sConfig.Rank = ADC_REGULAR_RANK_1;

  sConfig.SamplingTime = ADC_SAMPLETIME_64CYCLES_5;

  sConfig.OffsetNumber = ADC_OFFSET_NONE;

  sConfig.Offset = 0;

  result = HAL_ADC_ConfigChannel(pAdc, &sConfig);

  HAL_ADC_MspInit(pAdc);

  result += HAL_ADC_Start(pAdc);

  result += HAL_ADC_PollForConversion(pAdc, 10);

  if(result != HAL_OK)

  {

   printf("we are getting adc error result = %d",result);

  }

  retval = HAL_ADC_GetValue(pAdc);

  HAL_ADC_Stop(pAdc);

  retval = (retval * ADC_CORRECTION);

  sConfig.Channel = ch;

  sConfig.Rank = ADC_REGULAR_RANK_2;

  sConfig.SamplingTime = ADC_SAMPLETIME_64CYCLES_5;

  sConfig.OffsetNumber = ADC_OFFSET_NONE;

  sConfig.Offset = 0;

  result = HAL_ADC_ConfigChannel(pAdc, &sConfig);

  return retval;

And the values I am getting is (expected 4095) :

4095 

4788

4788

4790

4790

4788

4790

4095

4790

4790

4095

4790

4790

why the data is changing.

and I am reading 7 channels in independent mode with single conversion.

Regards,

-Shrikant

2 REPLIES 2
Imen GH
ST Employee

​Hello,

Which product you used ?

Regards

I am using stm32h7543