# ADC on STM32 Nucleo 64

I am trying to simply read the value of the PCO ADC on a Nucleo-L476RG Board. I connected a power supply to the PC0 Pin with 2 V and the grounds of the board and the powersupply. When I read the value of the ADC with the code down below I get a value of arround 700. At a reference voltage of 3.3 V and 2 V on the PC0 Pin I should get a value of 2482.

I checked the voltages on the AVDD/VREF, the AGND Pins and the PC0 Pin and the voltage levels where all like they should. So I think it must be a problem with my code.

Can you see what is wrong with my code?

void SystemClock_Config(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_OscInitTypeDef RCC_OscInitStruct = {0};

/* MSI is enabled after System reset, activate PLL with MSI as source */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
RCC_OscInitStruct.PLL.PLLM = 1;
RCC_OscInitStruct.PLL.PLLN = 40;
RCC_OscInitStruct.PLL.PLLR = 2;
RCC_OscInitStruct.PLL.PLLP = 7;
RCC_OscInitStruct.PLL.PLLQ = 4;
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
/* Initialization Error */
while(1);
}

/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
clocks dividers */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
{
/* Initialization Error */
while(1);
}

SystemCoreClockUpdate();

if (HAL_GetREVID() == 0x1001)
__HAL_FLASH_PREFETCH_BUFFER_ENABLE();
}

{
GPIO_InitTypeDef gpioInit;

__HAL_RCC_GPIOC_CLK_ENABLE();

gpioInit.Pin = GPIO_PIN_0;
gpioInit.Mode = GPIO_MODE_ANALOG;
gpioInit.Pull = GPIO_PULLDOWN;
gpioInit.Speed = GPIO_SPEED_HIGH;
HAL_GPIO_Init(GPIOC, &gpioInit);

}

{

return 0;