C GPIO
#11
(08-25-2016, 11:17 AM)MarkHaysHarris777 Wrote:
(08-25-2016, 08:24 AM)martind1983 Wrote: One more question. All the pins led out on the board and which are also dedicated to some peripherals I have to first turn off special functionality before using them as normal GPIO?

No, not necessarily.

... as long as the pins (channels) are not actually being used 'now' you can use them for what-ever you want. But, that's a big if.  If a driver is running that uses the channel, you will need to stop and unload the driver... but, you don't necessarily have to edit the dtb|dts in order to do this.

That said, it is best to use GPIO pins that are 'free' first.  On the diagram , the green and then maybe the blue. The main exception right now is the pin(7) GPIO04 which is s-pwm and used for the LCD backlight... because it is on a pwm channel even though you can turn it on and off (if you have the correct base address, or use sysfs) it still doesn't work right, because it is 'very' dim ... and, it has a pwm signal on it.  In this case you must not only edit the dtb|dts, but also unassociate the pin, and you need to stop the driver and unload it (a lot of work, just use another GPIO pin).

Hello Mark

One more question related to my issue with GPIOs. I already tried to access free pin PC4, but with the same faulty result. Below is part of my C code. Check comments. I do not understand what is the numbering of PIOs.

I use this All-winner user's manual

http://dl.linux-sunxi.org/A64/Allwinner%...20v1.0.pdf

I still do not understand why I cannot access PC4 gpio. I alos tried to change for PC6 which also is free of peripherals and the same without any response.


Thanks for your help. Wink


// map memory image to virtual memory for direct writing in the peripherals
    // BASE_ADDR is 0x01C20000
    p_mem = mmap(NULL, page_size * 2, PROT_READ | PROT_WRITE, MAP_SHARED, fd, BASE_ADDR);
    if (p_mem == (void *) -1) {
        perror("mmap");
        exit(EXIT_FAILURE);
    }

    // convert void * to unsigned long *; gpio variable is type unsigned long pointer
    gpio = (volatile unsigned long *) p_mem;

    /*
     * add offset 0x800 to mapped base address to get to PIO registers
     * plus add offset to PC_CFG0_REG 0x48 to PC4 (PI-2 pin 32) as output,
     * &= ~(3 << 17) should set PC4 to output mode as by default pins are disabled (every pin = 0x7)
     * for output to set to log 1, the same I set offset 0x800, plus I add offset to PC_DATA_REG 0x58
     * and set 1 by |= 0x10 for PC4
     */

    *(gpio + GPIO_REG_OFFSET + 0x48) &= ~(3 << 17);
    *(gpio + GPIO_REG_OFFSET + 0x58) |= 0x10;

    while(active) {
        *(gpio + GPIO_REG_OFFSET + 0x58) |= 0x10;
        sleep(2.5);

        *(gpio + GPIO_REG_OFFSET + 0x58) &= 0x00;

        sleep(2.5);
    }

    return 0;
}
  Reply


Messages In This Thread
C GPIO - by igna09 - 06-10-2016, 12:41 PM
RE: C GPIO - by martinayotte - 06-10-2016, 01:52 PM
RE: C GPIO - by igna09 - 06-10-2016, 02:16 PM
RE: C GPIO - by martinayotte - 06-10-2016, 03:10 PM
RE: C GPIO - by martind1983 - 08-24-2016, 09:55 AM
RE: C GPIO - by igna09 - 06-11-2016, 02:51 AM
RE: C GPIO - by martinayotte - 08-25-2016, 07:35 AM
RE: C GPIO - by martind1983 - 08-25-2016, 08:24 AM
RE: C GPIO - by MarkHaysHarris777 - 08-25-2016, 11:17 AM
RE: C GPIO - by martind1983 - 08-29-2016, 01:30 AM
RE: C GPIO - by martind1983 - 08-29-2016, 03:50 AM
RE: C GPIO - by MarkHaysHarris777 - 08-29-2016, 05:25 AM
RE: C GPIO - by martind1983 - 08-31-2016, 03:47 AM
RE: C GPIO - by pfeerick - 08-31-2016, 04:14 AM
RE: C GPIO - by martind1983 - 08-31-2016, 04:36 AM
RE: C GPIO - by MarkHaysHarris777 - 08-29-2016, 05:04 PM
RE: C GPIO - by MarkHaysHarris777 - 08-31-2016, 04:09 AM
RE: C GPIO - by KnReLe - 08-31-2016, 07:27 AM
RE: C GPIO - by martind1983 - 09-01-2016, 05:08 AM
RE: C GPIO - by MarkHaysHarris777 - 09-01-2016, 05:29 AM
RE: C GPIO - by martind1983 - 09-01-2016, 08:04 AM
RE: C GPIO - by KnReLe - 09-01-2016, 08:52 AM
RE: C GPIO - by martind1983 - 09-01-2016, 09:06 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  RPi.GPIO python module for Pine A64/A64+ aquilegia 98 131,765 12-15-2022, 08:40 PM
Last Post: Fadazo
  fm transmitter with gpio weasel18 2 4,836 09-10-2019, 04:28 AM
Last Post: desai_amogh
  How to use dts or other setup to declare gpio pin Interrupt (e.g. a button)? dkebler 1 3,605 06-12-2019, 10:37 AM
Last Post: dkebler
Lightbulb Sample GPIO codes highlighting RPi.GPIO-PineA64 and the PI bus MarkHaysHarris777 6 11,150 06-07-2019, 12:37 AM
Last Post: tllim
Star GPIO, SPI and I2C C++ Lib databit 7 11,230 02-04-2019, 05:45 AM
Last Post: Jeff R
Information Howto: Controlling Pine64 GPIO via the filesystem (sysfs) on linux pfeerick 4 11,862 01-24-2019, 03:36 AM
Last Post: Fifth
  GPIO and SPI SamR1 20 31,658 03-15-2018, 10:32 AM
Last Post: jomoengineer
Question GPIO shockr 7 14,792 03-11-2018, 01:52 AM
Last Post: jomoengineer
  Read GPIO problem shworker 14 21,206 08-17-2017, 01:21 PM
Last Post: martinayotte
  GPIO fiq capability joseph 3 6,105 11-10-2016, 06:07 PM
Last Post: joseph

Forum Jump:


Users browsing this thread: 1 Guest(s)