cancel
Showing results for 
Search instead for 
Did you mean: 

I am working for stm32h753zi and i am trying to measure ADC reference voltage. But i got 5.74466228 instead of 3.3v.Please any one give me the guidance. I have attached steps i followed, Thank you.

AFaya.1
Associate III
 
2 REPLIES 2
AFaya.1
Associate III

int read_adc_data(ADC_HandleTypeDef *ptr_hadc, uint32_t channelx)

{

   uint16_t vrefint_cal;

   float adc_read_value = 0.0, adc_reference_voltage = 0.0;

   ADC_ChannelConfTypeDef sConfig;

   sConfig.Channel     = ADC_CHANNEL_VREFINT;               /* Sampled channel number */

   sConfig.Rank        = ADC_REGULAR_RANK_1;         /* Rank of sampled channel number ADCx_CHANNEL */

   sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;   /* Sampling time (number of clock cycles unit) */

   sConfig.SingleDiff  = ADC_SINGLE_ENDED;           /* Single-ended input channel */

   sConfig.OffsetNumber = ADC_OFFSET_NONE;            /* No offset subtraction */

   sConfig.Offset = 0;

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

   {

      Error_Handler();

      return -1;

   }

   if (HAL_ADCEx_Calibration_Start(ptr_hadc, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED) != HAL_OK)

   {

      Error_Handler();

      return -1;

   }

   if (HAL_ADC_Start(ptr_hadc) != HAL_OK)

   {

      Error_Handler();

      return -1;

   }

   if (HAL_ADC_PollForConversion(ptr_hadc, 100) != HAL_OK)

   {

      /* End Of Conversion flag not set on time */

      Error_Handler();

      return -1;

   }

   else

   {

      /* ADC conversion completed */

      /*##-5- Get the converted value of regular channel ########################*/

      raw_value = HAL_ADC_GetValue(ptr_hadc);

   }

   HAL_ADC_Stop(ptr_hadc);

   vrefint_cal= *((uint16_t*)VREFINT_CAL_ADDR); // read VREFINT_CAL_ADDR memory location

   /*Calculating the actual V DDA voltage using the internal reference voltage*/

   adc_reference_voltage = (float)(((float) 3.3* (float) vrefint_cal)/(float)raw_value);/*3.3 V x VREFINT_CAL / VREFINT_DATA*/

   return 0;

}

AFaya.1
Associate III

I was removed the HAL_ADC_PollForConversion that working fine.