Question
Analog read is not returning the maximum value
Hi there.
I was making some tests and I have observed that, when I shortcircuit 3V3 into my analog pin (in this case PA0), the reading I'm having is 4022 instead of 4095.
Why this difference? I'm using HAL libraries as follows:
//Function to obtain ADC value
uint32_t adc_get_value(uint8_t channel)
{
uint32_t value;
uint32_t adcChannel;
ADC_ChannelConfTypeDef sConfig;
GPIO_InitTypeDef GPIO_InitStruct;
//Returns ADC channel and sets up GPIO port
adcChannel = adc_get_channel(channel, &GPIO_InitStruct);
/* Configuration of channel on ADCx regular group on sequencer rank 1 */
sConfig.Channel = adcChannel; /* Sampled channel number */
sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; /* Minimum sampling time */
sConfig.Rank = ADC_REGULAR_RANK_1; /* Rank of sampled channel number ADCx_CHANNEL */
if (HAL_ADC_ConfigChannel(&adc_handle_, &sConfig) != HAL_OK)
{
/* Channel Configuration Error */
return -1;
}
if(HAL_ADC_Start(&adc_handle_) != HAL_OK)
{
/* Enables ADC Error */
return -1;
}
if (HAL_ADC_PollForConversion(&adc_handle_, 10) != HAL_OK)
{
/* Poll for conversion Error */
return -1;
}
value = HAL_ADC_GetValue(&adc_handle_);
if (HAL_ADC_Stop(&adc_handle_) != HAL_OK)
{
/* Stop ADC conversion Error */
return -1;
}
return value;
}Thank you in advance!
Areify ~
