When I read one analog pin everything looks normally.
But when I try to read pins in sequence like:
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();
}
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:
/*
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
*/
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.
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 350 times
6 links?
pulling the docs to be local might or might not be allowed or be too sensible?
srp
Ray
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
Are you using a GD32 or STM32 ?
I have some “Zoo” of boards

I have some “Zoo” of boards

GD are supposed to be compatible with STM32 but I have not verified all the functionality
There are definitely some differences, but I wasnt aware of any ADC related things.
It could be the hardware of the board thats the issue, can you post a link to your board
Any digital read/write works correctly and readings one analog channel too. It’s analog MUX issue, IMO.
Can anybody check my sketch on GD to be convinced, what it is not a single failure on my chip?
BTW. There is a separate thread on the forum for the GD32 as it does appear to have some differences with the STM32
I have not managed to get SPI working, when I connected it to an ILI9341 display.
But it could just be a wiring problem.
BTW. AFIK, only 4 people on this forum have a GD32 board, including me and you.
I’m glad i just had a wiring fault.
I’ve been trying to upload to my GD32 board, but it looks like my new PC which is a rather fast core i7 machine is possibly too fast for the bootloader.
I’ll need to work out which pin, if any I assigned as the perpetual bootloader enable pin on GD32
So I’ll need to get back to you when this is working
PS. I don’t even know if I can upload to a Maple mini
The strange thing however is that to read PA0 (pin 0) I have to connect GND to PA7, and pin 1 is PA0 pin 2 is PA1 etc, i.e its all shifted down by own.
I’ve looked in the PIN MAP and the ADC channel number is being defined correctly i.e Channel 0 is PA0, but this is not what the code is reading.
I’ve not tried this on a red pill to see if it has the same effect, or even on a Maple Mini by addressing the pin by its STM32 name i.e PA0
The code that reads the ADC is quite straight forward
adc_reg_map *regs = dev->regs;
adc_set_reg_seqlen(dev, 1);
regs->SQR3 = channel;
regs->CR2 |= ADC_CR2_SWSTART;
while (!(regs->SR & ADC_SR_EOC))
;
return (uint16)(regs->DR & ADC_DR_DATA);
I’ll also try to do some experiments.
It’s meanwhile not strongly important for me yet. But I think that this issue needs to be cleared up somehow, IMO.
I played with modbus library which was provided by André Sarmento, writing down a value from analog inputs to the modbus registers in cycle.
And all works perfecly on Arduino Mini & Due, STM32 maple mini & blue pill boards with arduinoish code style, but with GD board I get this “surprize”
I like arduinoish style for the portability and uniformity of code.
I have an idea to build several sensors and actuators for a little home automation, like it becomes in the industrial distributed systems. On a various platforms, depending on load.
Unfortunately have anither strange problem on my GD32. The USB reset is not working on my new PC.
I tried by old Core i5 PC and the GD32 resets the USB bus, but on the new Core i7 machine ( Skylake chipset) it does not reset the USB.
I tried various pull up resistors on PA12, including 1.5, 1k and 2k, but it didn’t make any difference.
I tried a generic STM32F103V board, which has a 1.5k pull-up on USB, on my new machine, and it worked OK.
I think perhaps the GD32 does not pull PA12 low for long enough. I will need to rebuild the bootloader with a longer delay and try it again