2021-03-23 10:58 PM
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;
}
2021-03-24 01:14 AM
I mean your code cant work because raw_value isnt assigned. ELSE is never executed...
2021-03-26 03:21 AM
2021-03-26 03:39 AM
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.
2021-03-26 03:52 AM
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.