• I have 3V from a power supply connected to pin PA3 on the Nucleo. Verified that the pin on the processor reads 3V.
• Grounds from the power supply and the Nucleo are connected.
• I checked the voltages on AVDD/VREF, they are correct at ~3.3V

However, when I read the ADC value, it shows up as ~600. 3V should give me ~3700. I have tried varying power supply voltage so that the voltage at the pin is 1V to 3V, however the values from the ADC remain constant at ~630.

I have tried the other two pins initialized in my code, PC0 and PC3, and they behave the same way.

I have a suspicion that the ADC is not configured properly. Is there something wrong with my code?

ADC_HandleTypeDef hadc1;

{

{
_Error_Handler(__FILE__, __LINE__);
}

/**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
*/
sConfig.Rank = 1;
sConfig.Offset = 0;
{
_Error_Handler(__FILE__, __LINE__);
}

/**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
*/
sConfig.Rank = 2;
sConfig.Offset = 0;
{
_Error_Handler(__FILE__, __LINE__);
}

/**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
*/
sConfig.Rank = 3;
sConfig.Offset = 0;
{
_Error_Handler(__FILE__, __LINE__);
}

/**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
*/
sConfig.Rank = 4;
sConfig.Offset = 0;
{
_Error_Handler(__FILE__, __LINE__);
}

/**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
*/
sConfig.Rank = 5;
sConfig.Offset = 0;
{
_Error_Handler(__FILE__, __LINE__);
}
}

{

GPIO_InitTypeDef GPIO_InitStruct;
{
/* USER CODE BEGIN ADC1_MspInit 0 */

/* USER CODE END ADC1_MspInit 0 */

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

GPIO_InitStruct.Pin = GPIO_PIN_0||GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

{
_Error_Handler(__FILE__, __LINE__);
}

/* USER CODE BEGIN ADC1_MspInit 1 */

/* USER CODE END ADC1_MspInit 1 */
}
}

void SystemClock_Config(void)
{

RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;

/**Configure the main internal regulator output voltage
*/
__HAL_RCC_PWR_CLK_ENABLE();

__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);

/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}

/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}

PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART3;
PeriphClkInitStruct.Usart3ClockSelection = RCC_USART3CLKSOURCE_PCLK1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}

/**Configure the Systick interrupt time
*/
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

/**Configure the Systick
*/
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}

int main(void)
{

HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_DMA_Init();
MX_TIM1_Init();
MX_USART3_UART_Init();
MX_TIM3_Init();
MX_NVIC_Init();

sprintf(buffer, "Nucleo Phase Shift\n");
print((char *)buffer);

HAL_Delay(250);

while (1)
{

}
}


• I have not checked if all fields in local structs are initialized. It's good practice to explicitly initialize all local structs, e.g.

ADC_ChannelConfTypeDef sConfig = {};
GPIO_InitTypeDef GPIO_InitStruct = {};

• Are the values from the internal channels, VREFINT and temperature, plausible? When yes, then ADC and DMA work, and GPIO setup is probably wrong.

• Are the GPIO and DMA clocks enabled? Can't find __HAL_RCC_GPIOA_CLK_ENABLE(), __HAL_RCC_GPIOC_CLK_ENABLE(), or __HAL_RCC_DMA2_CLK_ENABLE() in your code.

• This expression is wrong

GPIO_InitStruct.Pin = GPIO_PIN_0||GPIO_PIN_3;


there should be a single vertical bar |, meaning bitwise OR, instead of a double one ||, which is a logical OR.

• Make sure that other peripherals that you are using, e.g. TIM1, don't take DMA2 Stream0 away from the ADC.

UPDATE:

ADC channel numbers are all wrong.

PA3 is ADC_CHANNEL_3

PC0 is ADC_CHANNEL_10

PC3 is ADC_CHANNEL_13

You can get the channel numbers from the last column of Table 10 in the datasheet, or by just clicking on the pin in CubeMX.

• Thank you for the response! -The internal VREFINT and temperature values show up as ~1490 and~ 930 respectively. -Yes, the GPIO and DMA clocks are enabled. -The logical OR (||) in place of the bitwise OR (|) was a typo on my part. -I tried running the code without initializing TIM1 and TIM3, and still receive the same values on the ADC. – notransients Nov 15 '17 at 14:16
• @notransients check the updated answer – berendi - protesting Nov 15 '17 at 15:44