2020-08-22 01:07 AM
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
2020-08-22 02:02 AM
I had a similar matter with a stm32h743zi , my adc's buffer always returned the same value even if it was not plug. It was solved when I created a project on cubeMX 5.6.1
2020-08-22 02:58 AM
Can you share the generated code too?
2020-08-22 05:31 AM
> MX_ADC1_Init();
> ...
> HAL_ADC_Start(&hadc2);
The first function initializes ADC1, while the second (tries to) start ADC2 but it isn't yet initialized. That's not going to work.
2020-08-22 05:54 AM
Sry my bad. Copied the wrong line, I initialized ADC1 and also 2 in my code. I will edit it in the first post
2020-08-22 05:54 AM
I will send the generated code later when i'm back on my PC.
2020-08-22 07:20 AM
Did you measure the voltage on the pin with a multimeter? I don't think the bug is in the code you showed.
Forget the potentiometer and hook it up directory to GND and 3V3 until you get the expected result, then add the potentiometer.
2020-08-22 09:14 AM
I connected it directly to the GND and the same value appeared.
2020-08-22 09:57 AM
2020-08-22 12:27 PM
In the file you posted, the only ADC converting channel 13 is ADC3.
ADC1 is converting channel 4 and ADC2 is converting channel 9.
The pin initialization is found in stm32l4xx_hal_msp.c.