analogRead() issue

Boards based on the GigaDevices GD32F103 microcontroller
TomaTLAB
Posts: 20
Joined: Thu Oct 29, 2015 8:17 am
Location: Moscow, Russia

analogRead() issue

Postby TomaTLAB » Fri Jan 22, 2016 8:56 pm

Hello, guys!

When I read one analog pin everything looks normally.
But when I try to read pins in sequence like:

Code: Select all

void setup() {
   Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
    for (int i=0; i < 8; i++)
    pinMode(i, INPUT_ANALOG);
delay (5000);
}

void loop() {
    for (int i=0; i < 8; i++)
    {
      Serial.print(analogRead(i), DEC);
      Serial.print(' ');
    }
    Serial.println();
}

I have the strange result (PA0 tied to Vcc, PA7 to GND, others - float) like:

Code: Select all

4095 4095 2962 2171 1745 1515 1321 1248
0 4095 2809 1933 1388 1056 830 720
1 4095 2790 1893 1364 1030 817 684
0 4095 2808 1937 1433 1123 924 794
etc...
And the result doesn't depend neither on quantity of the read pins, nor on the naming (0...7, 16, 17 or PA0...PA7, PB0, PB1)
On STM everything works OK...

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

Re: analogRead() issue

Postby mrburnette » Sat Jan 23, 2016 6:08 pm

@TomaTLAB:
Welcome.

So, I'm going on the "old" Maple Mini documentation by Leaflabs, and providing the following sketch that does work as I would expect:

Code: Select all

/*
  hacked by Ray Burnette to loop through eight analog values A0 through A7
  Board view: http://letsmakerobots.com/files/maplemini2.jpg 
  Quote from old Maple Mini doc by Leaflabs "Maple Mini has an electrically
    isolated analog power plane with its own regulator, and a geometrically
    isolated ground plane, connected to the digital plane by an inductor.
    Its analog input pins, D3 — D11, are laid out to correspond with these
    analog planes, and our measurements indicate that they generally offer
    low noise ADC performance. However, analog performance may vary depending
    upon the activity of the other GPIOs. Consult the Maple Mini hardware
    design files for more details."
*/

int aValue ;
int settlingmS = 5000;

void setup() {
    // Configure the ADC pins
    for (int x =3; x < 12; x++) {
      pinMode(x, INPUT_ANALOG);
    }
  delay(settlingmS);
}

void loop() {
  for ( int analogInPin = 3; analogInPin < 12; analogInPin++)
  {
    // read the analog in value:
    aValue = analogRead(analogInPin);
    // print the results to the serial monitor:
    Serial.print("Analog pin#");
    Serial.print(analogInPin);
    Serial.print("\t = ");
    Serial.println(aValue);
  }
  delay(settlingmS);
}


/*  Sample console output:

Analog pin#3    = 2009
Analog pin#4    = 2061
Analog pin#5    = 2077
Analog pin#6    = 2536
Analog pin#7    = 2678
Analog pin#8    = 2681
Analog pin#9    = 2697
Analog pin#10   = 2135
Analog pin#11   = 1984
*/





The internal chip routing "fabric" permits the alias of digital D3 and analog D3 based upon the pin mode. I can no longer find the document from leaflabs online, but it does appear they are rearranging old archives and it may be available in the near future.
This link from Google does not resolve at this time.

From this link, you will see this information:
/* Set of all possible pin names; not all boards have all these (note
* that we use the Dx convention since all of the Maple's pins are
* "digital" pins (e.g. can be used with digitalRead() and
* digitalWrite()), but not all of them are connected to ADCs. */
enum {
D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15, D16,
D17, D18, D19, D20, D21, D22, D23, D24, D25, D26, D27, D28, D29, D30, D31,
D32, D33, D34, D35, D36, D37, D38, D39, D40, D41, D42, D43, D44, D45, D46,
D47, D48, D49, D50, D51, D52, D53, D54, D55, D56, D57, D58, D59, D60, D61,
D62, D63, D64, D65, D66, D67, D68, D69, D70, D71, D72, D73, D74, D75, D76,
D77, D78, D79, D80, D81, D82, D83, D84, D85, D86, D87, D88, D89, D90, D91,
D92, D93, D94, D95, D96, D97, D98, D99, D100, D101, D102, D103, D104, D105,
D106, D107, D108, D109, D110, D111, };


I did however repost here some of the pertinent info: http://www.stm32duino.com/viewtopic.php?t=68

Humor me in the future and always use a resistor between Vcc and any analog or digital input ... @ 3.3V and 15mA the value needs to be somewhere around 220 Ohms minimum (I would commonly use 330 or 470 here and many folks use 1K.)


Ray

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

Re: analogRead() issue

Postby RogerClark » Sat Jan 23, 2016 8:42 pm

I didnt get around to replying to the original post, but I wondered if all the pins you used can be used as analog input pins.

Im also not sure if the STM32 can have that many pins simultaneously configured as analog inputs.

The STM32 is a fantastically flexible and powerful device, but some combinations of configurations (in fact many combinations) probably wont work due to internal bus conflicts in the chip.

You probably need to download the programming manual RM0008 from STMs site and look in detail about how this works.

zmemw16
Posts: 1099
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: analogRead() issue

Postby zmemw16 » Sat Jan 23, 2016 8:48 pm

i wonder if a post with the links to the main st f1, f4 & f7 ref and prog manuals downloads would be useful?
6 links?
pulling the docs to be local might or might not be allowed or be too sensible?

srp

hopefully someone with some html experience can tidy this up.
i tried a link, took me to the right place to find out more

i went raiding, searched for each of stmf1, stm32f4 and stm32f7; snaffled the source of the table it gives you from the search.
ok, maybe overkill, losing stm32f100/101/102 etc easy, pls keep 107 as i've got some:D
i'll add it as a zip 4.5k, about 100k uncompressed.

stm32f1x.zip
(4.04 KiB) Downloaded 215 times


stephen
Last edited by zmemw16 on Sat Jan 23, 2016 10:16 pm, edited 1 time in total.

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

Re: analogRead() issue

Postby RogerClark » Sat Jan 23, 2016 8:50 pm

probably need to do a faq thread

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

Re: analogRead() issue

Postby mrburnette » Sat Jan 23, 2016 8:52 pm

zmemw16 wrote:i wonder if a post with the links to the main st f1, f4 & f7 ref and prog manuals downloads would be useful?
6 links?
pulling the docs to be local might or might not be allowed or be too sensible?

srp


For those that are "google challenged", I cannot see that links would hurt anything, but such a thing IMO would not warrant my time to post unless the links were terribly difficult to find (link on a non-indexed site.)

Ray

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

Re: analogRead() issue

Postby mrburnette » Sat Jan 23, 2016 8:52 pm

I guess we could stick my Analog example into the github examples, too. Of all the stuff I did, I failed to do one single analog.

Ray

TomaTLAB
Posts: 20
Joined: Thu Oct 29, 2015 8:17 am
Location: Moscow, Russia

Re: analogRead() issue

Postby TomaTLAB » Sat Jan 23, 2016 11:07 pm

Hmmm... I try it on STM "maple mini clone" and "blue pill" - all works ok.
If I apply some voltage on some analog pin - I can read this voltage on this pin. On numbers of analog pin in sequence...
But on GD if I try sequential read, I get in two first readings same value on analog channel 0 and 1, and then "rolled" readings.
On PA0 read voltage applyed to PA7
On PA1 read voltage applyed to PA0
On PA2 read voltage applyed to PA1
etc...

And I spent some time to deal with pin-mapping, numbering and naming and I understand a difference between "maple mini", "blue/red pill" and others, I hope :)
Last edited by TomaTLAB on Sat Jan 23, 2016 11:14 pm, edited 1 time in total.

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

Re: analogRead() issue

Postby RogerClark » Sat Jan 23, 2016 11:14 pm

Sorry..

Are you using a GD32 or STM32 ?

TomaTLAB
Posts: 20
Joined: Thu Oct 29, 2015 8:17 am
Location: Moscow, Russia

Re: analogRead() issue

Postby TomaTLAB » Sat Jan 23, 2016 11:17 pm

That's just the point that everything works on STM, and on "GD" - doesn't.
I have some "Zoo" of boards :)


Return to “GD32F103 boards”

Who is online

Users browsing this forum: No registered users and 1 guest