analogRead() issue

Boards based on the GigaDevices GD32F103 microcontroller
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 11:45 pm

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


My understanding is that the GD devices were fully compatible, but there may be some digital/analog internal routing that is manifesting an issue. I do not have the devices here, but Arduino pinmap fixes are rather straight-forward unless something else is going on too. That being said, I remember that the 1284 took forever to get correct.

The master GD file, pins_arduino.h is here if you want to take off on your own. The sub-forum for the GD32F1 is here.


Ray

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

Re: analogRead() issue

Postby RogerClark » Sun Jan 24, 2016 12:01 am

Umm

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

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

Re: analogRead() issue

Postby TomaTLAB » Sun Jan 24, 2016 11:44 am

My GD32 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?

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

Re: analogRead() issue

Postby RogerClark » Sun Jan 24, 2016 9:23 pm

I will try to run your sketch this evening.

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.

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

Re: analogRead() issue

Postby TomaTLAB » Mon Jan 25, 2016 7:58 am

RogerClark wrote:I will try to run your sketch this evening.

Hi, Roger! And what is in result? Just for curiosity? :)

RogerClark wrote:I have not managed to get SPI working, when I connected it to an ILI9341 display.
But it could just be a wiring problem.

I try GD with ENC28J60 lib - it's work.

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

Re: analogRead() issue

Postby RogerClark » Mon Jan 25, 2016 10:26 pm

Thanks for testing SPI

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 :-(

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

Re: analogRead() issue

Postby RogerClark » Tue Jan 26, 2016 3:22 am

I tried the sketch on the GD32 and I tried pulling each pin to GND, individually and it was fine.

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

Code: Select all

 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.e it puts the channel number in register SQR3 and it doesn't appear to be masked or shifted etc


Anyway, I've just managed to locate the GD32 programming manual from here

http://qd2.cache.baidupcs.com/file/a4d6 ... llid=0.1.1

And I can't see ant difference between the STM32 register layout and the GD32 layout.


So I'm not sure why I'm seeing the PIN shifted along by one

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

Re: analogRead() issue

Postby TomaTLAB » Tue Jan 26, 2016 1:37 pm

Thanx, Roger!
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.

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

Re: analogRead() issue

Postby RogerClark » Tue Jan 26, 2016 7:54 pm

Hi TomaTLab

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


Return to “GD32F103 boards”

Who is online

Users browsing this forum: No registered users and 1 guest