japaric / stm32f103xx-hal

HAL for the STM32F103xx family of microcontrollers
Apache License 2.0
116 stars 40 forks source link

Analog Input (ADC) #92

Open MajorBreakfast opened 6 years ago

MajorBreakfast commented 6 years ago

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:

TheZoq2 commented 5 years ago

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

TeXitoi commented 5 years ago

AFAIK nobody is on it.

rivertam commented 5 years ago

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.

burrbull commented 5 years ago

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.