Polling ADC on STM32F777IIK
I'm having problems getting an ADC value from the STM32F777IIK chip we have embedded in one of our boards.
I have used a digital GPIO application and have confirmed that the ADC pin (PC0) is connected from the chip to the headers that is good.
I have use STM32Cube to generate a simple makefile application that reads the values from the ADC and then outputs the value read on one of the UARTs.
The ADC initialisation looks like this:
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.ScanConvMode = DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
sConfig.Channel = ADC_CHANNEL_10;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}The code that reads the ADC is:
uint16_t uhADCxConvertedValue = 0;
if (HAL_ADC_Start(&hadc1) != HAL_OK)
{
Error_Handler();
}
if (HAL_ADC_PollForConversion(&hadc1, 10) != HAL_OK)
{
Error_Handler();
}
else
{
uhADCxConvertedValue = HAL_ADC_GetValue(&hadc1);
}I have a potentiometer connected to a 3.3V supply and the voltage is ready 2.04V (RMS) on the scope and when this is connected to the board I always get a reading of 3.29V (4095) on the ADC.
Interestingly, when I disconnect the pin from the voltage source I get a returned value of 1.64V (2047).
I have also tried 5 other ADCs on this chip and I am getting the same results.
I would appreciate it if someone could help me resolve this problem.
Thanks in advance,
Mark
