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

I am using the code :

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();

  }

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

     Error_Handler();

  }

  if (HAL_ADC_Start(ptr_hadc) != HAL_OK){

     Error_Handler();

  }

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

     Error_Handler();

  }

  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;

}

4 REPLIES 4
MM..1
Chief II

I mean your code cant work because raw_value isnt assigned. ELSE is never executed...

AFaya.1
Associate III

0693W000008xzpUQAQ.png

MM..1
Chief II

Sorry i miss you maybe enter code here as code

IF()!=OK

but to problem, maybe left right alligned data is you issue or any conversion float chaos.

AFaya.1
Associate III

OK, thank you for reply. I was previous working for ADC on l4 series but now i am working H7 series. In l4 series this code working fine. But h7 series board only gives the wrong reference value.