0

I just got myself a STM32F103C8 Blue pill board. I am having funny behaviour with the analog readings. It behaves as if the unit was 10bits and not 12 bits.

I uploaded the very trivial Arduino code below. Just to read the analog input A0.

void setup() {
  Serial.begin(38400);
}
void loop() {
  Serial.println(analogRead(A0));
  delay(1000);
}

If I connect pin A0 to the 3.3v I get this output below.

1022
1022
1023
1022
1022
etc...

If I connect to a 1.5V source the above values becomes around 500.

It all behaves as if it was 10bits really which I fail to understand. Any ideas why?

2 Answers 2

2

If you run Arduino code on it, maybe it makes sense to have 10-bit ADC readings on this platform too like on all other Arduino platforms. Unless you configure the libraries to return full 12 bit, if even possible.

This is more an Arduino platform question though.

1

Adding the following line in the setup() section solves the problem.

analogReadResolution(12)
1
  • 2
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Oct 16, 2022 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.