stm32f103xx-hal icon indicating copy to clipboard operation
stm32f103xx-hal copied to clipboard

Analog Input (ADC)

Open MajorBreakfast opened this issue 6 years ago • 4 comments

The stm32f103xx chips have built-in analog-to-digital converters which aren't supported ATM by stm32f103xx-hal. I'd be nice if there was support because they're often useful.

I did some digging and this is how I gather it works:

  • Set configuration register (CRL or CRH) to input + analog.
  • Read the value like in Arduino's adc_read function (blocks thread until value has been read)

MajorBreakfast avatar Aug 19 '18 15:08 MajorBreakfast

I'll try implementing this unless someone else is already doing it

TheZoq2 avatar Oct 20 '18 20:10 TheZoq2

AFAIK nobody is on it.

TeXitoi avatar Oct 21 '18 08:10 TeXitoi

Sorry to dredge up this question, but I'm extremely new to all of this (including embedded development generally).

Does this mean there's on way to read floating point numbers on, for example, PA0? I'm trying to read a piezo sensor input to recreate something like this: https://www.arduino.cc/en/tutorial/knock

If it's not possible using this library, is it possible using any library for the blue pill?

Thanks so much!

edit: My apologies, I see this is currently underway in #114. I'm actually finding success using this PR for now. I suspect it will be merged soon because it seems to be working flawlessly for me, but I am not doing anything remotely complicated.

rivertam avatar Dec 30 '18 06:12 rivertam

The result of the ADC conversion is an integer from 0 to 4095, which corresponds to the input voltage from 0 to ~3.3 V. You can convert this value to the value you need, using constants from the datasheet of your sensor.

burrbull avatar Dec 30 '18 10:12 burrbull