[Fixed] analogRead results for BluePill and MapleMini

Please post bugs and enhancements for the STM core here
Post Reply
danieleff
Posts: 318
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

[Fixed] analogRead results for BluePill and MapleMini

Post by danieleff » Sat Dec 17, 2016 8:13 am

This code:

Code: Select all

void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
  Serial.println(analogRead(PIN));
  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
  delay(1000);
}
Gives the following results for different PIN values:

Board: MapleMini
Program crashes: 0, 1, 2, 3, 9, 16, 17, 18, 19, 25
"0" on serial: the rest of the pins
Expected: analog value on serial for pins 3..11; "0" for the rest of the pins

Board: BluePill
Program crashes: PA3, PA4, PA5, PA6, PA10, PB3, PB4, PB5, PB6, PB10
Incorrect analog value on serial: PA0 reads the PB0 pin
Correct analog value on serial: PB0
"0" on serial: rest of the pins
Expected: analog value on serial for pins PA0..PA7,PB0; "0" for the rest of the pins

The reason for these is multiple:
  • wrong pins are considered to read: https://github.com/stm32duino/Arduino_C ... /issues/28
  • crashes: analogread and PWM pins are in the same g_analog_config array, and trying to analogread from a PWM pin will get you a adcInstance=NULL -> crash
  • array out of bounds for g_anInputPinConfigured. its size is 7, but in analogRead the apin variable has values of 0..15
  • * EDIT: The following ADC pins are missing from g_analog_config: PA2, PA3, PA6, PA7(!), PB1
Last edited by danieleff on Mon Jan 16, 2017 1:01 pm, edited 1 time in total.

User avatar
mrburnette
Posts: 1794
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: analogRead results for BluePill and MapleMini

Post by mrburnette » Mon Dec 19, 2016 1:04 am

Then, as in the example program, set the chosen pin’s pin mode to INPUT_ANALOG by calling pinMode(<your_pin>, INPUT_ANALOG). You will usually do this in your setup() function. Now you can use analogRead() to perform an ADC reading.
Examples are available for most basic capabilities; always try an example first.
http://docs.leaflabs.com/docs.leaflabs.com/index.html

Ray

User avatar
Rick Kimball
Posts: 941
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: analogRead results for BluePill and MapleMini

Post by Rick Kimball » Mon Dec 19, 2016 2:06 am

mrburnette wrote: Examples are available for most basic capabilities; always try an example first.
http://docs.leaflabs.com/docs.leaflabs.com/index.html

Ray
I think this question is about the ST core not the maple core.

I took the first stab at getting the bluepill to work with the ST core. I quickly determined that Wi6labs didn't care about non nucleo boards. This observation based on the code and their forum responses. I've stopped looking at the ST official port. Unless some one has fixed up the pin map code, I think this post is still valid.

viewtopic.php?f=48&t=1407&start=10#p18075

When I did the first port I didn't see a quick way to add more pins without breaking the analog feature, so I broke it, mainly to get a feel for the code.

btw: all the posts in that thread are a good read to understanding the issues with using the ST core with our boards.
-rick
-rick

User avatar
RogerClark
Posts: 6369
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: analogRead results for BluePill and MapleMini

Post by RogerClark » Mon Dec 19, 2016 2:46 am

I mentioned to Frederic @ STM, that I though that the STM Core was written only for the Nucleo, and he has said that it was not STM's intention.

However, (in my reply to Frederic), I referenced the various things including things like hard coding of pins deep in the code (for I2C), large RAM usage etc.

So I presume that this has been a misunderstanding between STM and Wi6Labs about what STM wanted them to create.

Either way this doesn't help us, make the STM core work on anything other than Nucleo boards.

User avatar
mrburnette
Posts: 1794
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: analogRead results for BluePill and MapleMini

Post by mrburnette » Mon Dec 19, 2016 3:30 am


Ray
I think this question is about the ST core not the maple core.
<...>
-rick
Yes, Rick, I missed the "STM core:" in the forum link. I wish the alternate cores were in a separate forum instead of just a separate header section ... But, my bad.



Ray

User avatar
RogerClark
Posts: 6369
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: analogRead results for BluePill and MapleMini

Post by RogerClark » Mon Dec 19, 2016 7:22 am

mrburnette wrote: Yes, Rick, I missed the "STM core:" in the forum link. I wish the alternate cores were in a separate forum instead of just a separate header section ... But, my bad.
Ray
I've separated as much as I can, i.e this is in a separate section.

User avatar
mrburnette
Posts: 1794
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: analogRead results for BluePill and MapleMini

Post by mrburnette » Mon Dec 19, 2016 3:57 pm

RogerClark wrote:
mrburnette wrote: Yes, Rick, I missed the "STM core:" in the forum link. I wish the alternate cores were in a separate forum instead of just a separate header section ... But, my bad.
Ray
I've separated as much as I can, i.e this is in a separate section.
Yes, Roger ... But it is not old-fart separated; that is, I have to put on my glasses to read the small type in the upper-left:
Board indexBootloaders and CoresSTM core: Bugs and enhancements

On the other hand, the subject line is in BIG font and can be read without glasses and I can respond without glasses:
analogRead results for BluePill and MapleMini

It's not your fault I'm half blind; my personal problem. It's just that the forum sections are not well displayed; thus, when one pulls down from the Quick links menu "Active topics" it is very easy to get lost when the reader is 95% of the way to lost anyway.

Ray

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests