Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Analog Input (ADC) #92

Open
MajorBreakfast opened this issue Aug 19, 2018 · 4 comments
Open

Analog Input (ADC) #92

MajorBreakfast opened this issue Aug 19, 2018 · 4 comments

Comments

@MajorBreakfast
Copy link

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)
@TheZoq2
Copy link
Contributor

TheZoq2 commented Oct 20, 2018

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

@TeXitoi
Copy link
Collaborator

TeXitoi commented Oct 21, 2018

AFAIK nobody is on it.

@rivertam
Copy link

rivertam commented Dec 30, 2018

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
Copy link
Contributor

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants