cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to get a valid ADC-value

FEich.1
Associate II

Hello everyone,

at first the Discoveryboard I'm using is the P-L496G-Cell02 / STM32L496G-DISC.

To test the ADC I tried to recieve a value from a potentiometer.

So I started a new STM32CuvbeIDE project, Selected the board I'm using and changed the Pins (via the CubeMX Interface) to the correct Input. I tried it several times with different pins:

PC4 -> ADC2_IN13

PC1-> ADC1_IN2

PC3-> ADC1_IN4

And i changed the associated channel to Single-ended.

In the main fuction, i declared a variable raw and added the code in the while-loop

int main(void)
{
	uint16_t raw;
	HAL_Init();
	SystemClock_Config();
	MX_ADC2_Init();
	while (1)
	{
    /* USER CODE END WHILE */
	    HAL_ADC_Start(&hadc2);
	    HAL_ADC_PollForConversion(&hadc2, HAL_MAX_DELAY);
	    raw = HAL_ADC_GetValue(&hadc2);
	    HAL_Delay(2);
    /* USER CODE BEGIN 3 */
	}
  /* USER CODE END 3 */
 
}

As a result raw is always 4095 (3.3V) even if i unplug the cable to the potentiometer.

I hope somebody can help me with this problem

11 REPLIES 11
FEich.1
Associate II

So here is the hal_msp

FEich.1
Associate II

Today I tried several things:

1.Changed the ADC2 regular Channel to 13 and got the same result.

sConfig.Channel = ADC_CHANNEL_13;

2. Connected PC4 to the potentiometer ->4095

3. Connected PC4 to ground ->4095

4. Connected PC4 to 3.3V ->4095

5. Connecteed PC4 to ground with an resistor in between -> showing 0 and 4095 in irregular intervals

6. Generate the code with an older MX-Version 5.6.1 ->4095

7.Tried the code snippet I posted in the first post on an other discoveryboard (stm32f4) with the generated code from the CubeMX->Everything is working as it should