I'm using Nucleo-32 board with STM32F031K6 MCU. I have some weird problem with ADC measurement. When ADC pin (PA4 in my case) is connected directly to VREF or 3V3 the value is always in range of 4031-4032 instead if 4095... For measuring low voltages, the ADC value has higher offset from the correct one (20% lower then it should be for 0.5V measuring).

Could anybody please explain this behavior?

  ADC_ChannelConfTypeDef sConfig;

/**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
*/

{
Error_Handler();
}

/**Configure for the selected ADC regular channel to be converted.
*/
{
Error_Handler();
}


Pin configuration:

__HAL_RCC_ADC1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();

GPIO_InitStruct.Pin = GPIO_PIN_4;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

• Did you measure vref with a multimeter? How do you supply the board? Aug 25, 2016 at 9:02
• The Voltages that you are supplying to the ADC pin might not be the same. For example : 3.3V onboard will be ~3.2-3.3V(loading). Aug 25, 2016 at 11:09
• Board is powered by USB. Nothing external is connected ot it. ADC pin is connected directly to VREF pin!!! Multimeter shows exactly 3.3V for VREF and 3V3 Aug 25, 2016 at 14:57

Thank everyone for help. Finally I found solution myself

This function call after ADC initialization makes all the magic to solve the issue

HAL_ADCEx_Calibration_Start(&hadc)


A couple of thoughts:

1. I wonder if your VDDA or VREF voltage has an offset. I took a look at the Nucleo-32 board schematic here and saw these pins connected to a bead which could have some DC resistance that matters if you are drawing a lot of current from that node which sometimes is used on ADCs for measurement reference.

Maybe try measuring the voltage at pin 5 of the MCU (VDDA/VREF+)?

1. How much time are you allowing for settling? It seems that the ADCs are 5Msps? It should be pretty fast but you might have some capacitance slowing your signal down more than you think.

2. Do you see the same problem on another analog input (e.g. PA1)? If so, this may indicate a VREF issue as well.

• ADC is connected to VDDA/VREF+. Anyway measurements are the same for 3V3, either. I measure voltage each 0,5 sec with the longest conversion time. PA5 acts the same Aug 25, 2016 at 15:00
• I ran into this electronics.stackexchange.com/questions/52894/… post about checking the correct ADC settings. Hopefully you have already done that. So it seems you are off by ~50 codes at the full scale. Is this offset constant over the whole range?... this may be expected. Do you have a link to the ADC specs? I couldn't find one using a quick search. Aug 25, 2016 at 16:42