cancel
Showing results for 
Search instead for 
Did you mean: 

Value optimized out when reading from ADC.

MReyn
Associate II

Hello everyone,

i'm encountering a strange issue, I'm trying to read from the ADC on a STM32f429zi.

When my pin is grounded the value of the ADC is not 0 but around 1000. When i try to debug the value it doesn't give me any result but says: <optimized out>. This is the code i'm using:

	  uint32_t value = 0;
	  HAL_ADC_Start(&hadc1);
	  HAL_ADC_PollForConversion(&hadc1, 100);
	  value = HAL_ADC_GetValue(&hadc1);
	  HAL_ADC_Stop(&hadc1);

I'm using system workbench for stm32 with a ST-link using SWD. I hope somebody can help me solve this issue. Thank you all! 0693W0000000Ax6QAE.jpg

13 REPLIES 13

I just checked my vrefint with ADC1 and got 4095 as a result. So this means my chip is broken?

My input is just a voltage divider with a 10k resistor to ground and the LDR connected to v+.

I've tested this with a nucleo and this worked fine so i guess this is not the issue?

So i have no other option than re soldering?

/* ADC1 init function */
static void MX_ADC1_Init(void)
{
 
  ADC_ChannelConfTypeDef sConfig;
 
    /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) 
    */
  hadc1.Instance = ADC1;
  hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
  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(__FILE__, __LINE__);
  }
 
    /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. 
    */
  sConfig.Channel = ADC_CHANNEL_VREFINT;
  sConfig.Rank = 1;
  sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }
 
}

Thank you for your feedback.

I'm pretty sure it's a hardware issue, my code is working fine.

What value pot meter did you use?

Please see my reply above since i did a test on VREFINT resulting in a funky value.

Replace the chip, be more diligent about grounding yourself when working with electronics. The ST chips are pretty ESD safe but nothing is immune.

If you feel a post has answered your question, please click "Accept as Solution".

So the chip is broken? I have to say i didn't care about ESD. I never had issues with it in the past. And since I2C and SPI are working fine i guess the chip should be alright? So because of the VREFINT ADC readout of 4095 you are sure the chip is broken or am i miss understanding this result? Where can i find more information about VREFINT?

In my original PCB i wired the voltage divider to a pin with no ADC capabilities(yes very stupid), so now i have wired this to the channel i'm using right now with a regular wire.

So the ADC input pin is also connected to a unused microcontroller pin and my voltage divider. Could this be the issue? It took me some time to realize this.

I should cut a trace and see what is happening after that.

Thank you for your feedback!