# Reading analog values in STM32DUINO

**URL:** https://community.simplefoc.com/t/reading-analog-values-in-stm32duino/6605
**Category:** hardware support
**Created:** [January 18, 2025, 7:35pm UTC](https://community.simplefoc.com/t/reading-analog-values-in-stm32duino/6605 "2025-01-18T19:35:16Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![sgordon777](https://community.simplefoc.com/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@sgordon777](https://community.simplefoc.com/u/sgordon777)
#### Post date: [January 18, 2025, 7:35pm UTC](https://community.simplefoc.com/t/reading-analog-values-in-stm32duino/6605/1 "2025-01-18T19:35:16Z")

</div>

Hi,

I have a need to read some ADC values in a SimpleFOC app. The Arduino AnalogRead take too much time and interfere with FOC operation, so I’d like to use the HAL.

Board: NUCLEO64-STM32G474RE  
Platform: PlatformIO with vscode

a) I tried the code here on a fresh project, fresh board:

> [@STM32 ADC code using stm32duino](https://community.simplefoc.com/t/stm32-adc-code-using-stm32duino/346):
>
> Hey guys, I’ve spent some time in the last few weeks trying to implement a simple yet efficient way to read the adc for the stm32 boards, and more specifically to read the adc efficiently enough to be able to run it in each cycle of the PWM (for low side sensing). I am trying to avoid using DMA, now I am not sure if this is going to be a final verdict, but at the moment I would like to create the simplest possible code which works smiley And pooling seems like the reasonable solution. The …

But it hung at the first call to HAL\_ADC\_ConfigChannel:

sConfig.Channel = ADC\_CHANNEL\_0;  
sConfig.Rank = 1;  
sConfig.SamplingTime = ADC\_SAMPLINGTIME;  
HAL\_ADC\_ConfigChannel(&hadc, &sConfig); \<\<\<\<\< HANG HERE

b) Is there any way to leverage the current shunt code, which I assume also uses STM32DUINO. I am NOT using current shunt for my projects.

Thanks in advance, Steve
