cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with ADC on B_U585I_IOT02A

Chamo
Associate II

Hello, I'm using the demoboard (B_U585I_IOT02A) in order to read an analogic input (between 1V and 2V for my tests) and I'm currently trying to use the ADC. I say "trying" because, for now, I still haven't been able to read the values ​​correctly. For the code below, I keep having the value 0 in rawForData, and I have not been able to read anything with ADC. I did suceed to read with HAL_GPIO_ReadPin, so the pins are working correctly. I don't know where I am wrong, I tried to follow tutorials on internet but it seems that I've missed something. Could you help me please ?

Here is part of my code using ADC :

-----------------------------------------------------------------

ADC_HandleTypeDef hadc1;

uint32_t rawForData;

int main(void) {

 HAL_Init();

 /* Configure the system clock */

 SystemClock_Config();

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_ADC1_Init();

 while (1) {

HAL_ADC_Start(&hadc1);

// I tried several configurations where I placed HAL_ADC_Start out of the while loop, but it didn't change anything

if (HAL_ADC_PollForConversion(&hadc1, 100) == HAL_OK) {

rawForData = HAL_ADC_GetValue(&hadc1);

}

// Just to explain, I tried using HAL_ADC_Stop after too, but in this case the code was not working at all

HAL_Delay(100);

}

}

-----------------------------------------------------------------

I'm using the pin PC0 configured in ADC1_IN1 state and i'm using IN1 Single-ended mode

And the configuration of the ADC is :

Mode Independent mode

Clock prescaler Asynchronous clock mode divided by 4

Resolution 14 bits

Gain compensation 0

Scan conversion mode Disabled

Continous conversion mode Disabled (I tried Enabled too but it didn't

change anything)

End of conversion selection End of single conversion

Conversion data management mode Regular conversion data stored in DR register

Enable Regular conversions Enable

Number of conversions 1

External trigger conversion source Regular conversion launched by software

Rank 1

Channel Channel 1

Sampling time 5 cycles

For clock configuration, it's based on HSI with a frequency of 16MHz

I tried to modify this configuration a lot of times, trying even to use interruptions or DMA, but I keep having 0 in rawForData.

Thanks for helping,

1 ACCEPTED SOLUTION

Accepted Solutions
Chamo
Associate II

Hello again,

I finally found how to solve my problem thanks to this topic I didn't see before : https://community.st.com/s/question/0D53W000014zCdASAU/stm32u5-cannot-enable-adc-timeout-on-polling-for-adcisrasrdy

For those who have the same problem, there is a bit (ASV in PWR_SVMCR register) to set in order to enable the VDDA for ADC. You can find this in section 10.4.4 of the reference manual.

With HAL library, you only have to add this line : HAL_PWREx_EnableVddA();

View solution in original post

1 REPLY 1
Chamo
Associate II

Hello again,

I finally found how to solve my problem thanks to this topic I didn't see before : https://community.st.com/s/question/0D53W000014zCdASAU/stm32u5-cannot-enable-adc-timeout-on-polling-for-adcisrasrdy

For those who have the same problem, there is a bit (ASV in PWR_SVMCR register) to set in order to enable the VDDA for ADC. You can find this in section 10.4.4 of the reference manual.

With HAL library, you only have to add this line : HAL_PWREx_EnableVddA();