Author Topic: No GPIO and ADC?  (Read 7455 times)

Offline lacho.tomov

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
No GPIO and ADC?
« on: May 19, 2015, 04:41:16 pm »
Is it correct that v4 of the board doesn't have gpio and adc pins?

Offline actkk2000

  • Hero Member
  • *****
  • Posts: 572
  • Karma: +2/-11
    • View Profile
Re: No GPIO and ADC?
« Reply #1 on: May 19, 2015, 08:58:58 pm »
According to this it does have an extended pin connector J20:
http://dl.cubieboard.org/model/cc-a80/Hardware/CC-A80-J20-PIN.pdf

Offline lacho.tomov

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: No GPIO and ADC?
« Reply #2 on: May 20, 2015, 01:39:05 am »
Yeah but it says they are only UART and I2C. I wonder if they have other functions as well...

Offline sam

  • Jr. Member
  • **
  • Posts: 73
  • Karma: +2/-0
    • View Profile
Re: No GPIO and ADC?
« Reply #3 on: May 21, 2015, 10:18:45 pm »
Yeah but it says they are only UART and I2C. I wonder if they have other functions as well...

You can use them as GPIO。

Offline lacho.tomov

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: No GPIO and ADC?
« Reply #4 on: June 21, 2015, 12:25:04 pm »
I tried using the UART and I2C pins as GPIO, but it didn't work... this is what I do:

# cd /sys/class/gpio
# echo 5 > export
# cd gpio5
# echo out > direction
# cat value

now it shows value is 0, but the pin outputs 3V
putting 1 in value doesn't change things.

Any idea how to get it to work?
Do I need to somehow disable the UART function first?

Thanks!

Offline sam

  • Jr. Member
  • **
  • Posts: 73
  • Karma: +2/-0
    • View Profile
Re: No GPIO and ADC?
« Reply #5 on: June 22, 2015, 10:29:00 pm »
I tried using the UART and I2C pins as GPIO, but it didn't work... this is what I do:

# cd /sys/class/gpio
# echo 5 > export
# cd gpio5
# echo out > direction
# cat value

now it shows value is 0, but the pin outputs 3V
putting 1 in value doesn't change things.

Any idea how to get it to work?
Do I need to somehow disable the UART function first?

Thanks!

Yes, you must disable the uart function first.

Offline allen

  • Jr. Member
  • **
  • Posts: 68
  • Karma: +0/-0
    • View Profile
Re: No GPIO and ADC?
« Reply #6 on: June 24, 2015, 02:28:42 am »
I tried using the UART and I2C pins as GPIO, but it didn't work... this is what I do:

# cd /sys/class/gpio
# echo 5 > export
# cd gpio5
# echo out > direction
# cat value

now it shows value is 0, but the pin outputs 3V
putting 1 in value doesn't change things.

Any idea how to get it to work?
Do I need to somehow disable the UART function first?

Thanks!

Code: [Select]
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/select.h>
#include <pthread.h>
#include <unistd.h>
#include <sched.h>
#include <errno.h>


#define SW_PORTC_IO_BASE  0x06000800

int main() {
        unsigned int * pc;
        int fd, i;
        char * ptr;
        unsigned int addr_start, addr_offset, PageSize, PageMask, data;

        PageSize = sysconf(_SC_PAGESIZE);
        PageMask = (~(PageSize-1));
        addr_start = SW_PORTC_IO_BASE & PageMask;
        addr_offset = SW_PORTC_IO_BASE & ~PageMask;

        fd = open("/dev/mem", O_RDWR);
        if(fd < 0) {
           perror("Unable to open /dev/mem");
           return(-1);
        }

        pc = mmap(0, PageSize*2, PROT_READ|PROT_WRITE, MAP_SHARED, fd, addr_start);

        if(pc == MAP_FAILED) {
           perror("Unable to mmap file");
           printf("pc:%lx\n", (unsigned long)pc);
           return(-1);
        }
        printf("PageSize:%8.8x\tPageMask:%8.8x\naddr_start:%8.8x\taddr_offset:%8.8x\n",PageSize,PageMask,addr_start,addr_offset);
        printf("pc:%8.8x\n", *(unsigned int *)pc);
        ptr = (char *)pc + addr_offset;

        //the PG12 is UART4-TX in the board ,set it as output port
        data = *(unsigned int *)(ptr+0xdc);
        data &= ~(7<<16);
        data |= 1<<16;
        *(unsigned int *)(ptr+0xdc) = data;

        //set it high level 
        data = *(unsigned int *)(ptr+0xe8);
        data &= 1<<12;
        *(unsigned int *)(ptr+0xe8) = data;

        return 0;
    }

this is a demo to use the gpio

gcc gpio.c -o gpio
./gpio

the UART4-TX will be set high level 

Offline lacho.tomov

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: No GPIO and ADC?
« Reply #7 on: June 25, 2015, 09:48:34 am »
Thanks a lot, I'll try that.

Offline lacho.tomov

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: No GPIO and ADC?
« Reply #8 on: June 26, 2015, 06:52:16 am »
Unfortunately the above code also doesn't work for me. After running it, the PIN is just set to 0...

I tried playing with the .fex file...

One thing I notice is that there is no [gpio_para] section (there is on previous cubieboards).

So this is what I did:
- I commented the [uart4] section to (hopefully) free the pins
- added a [gpio_para] section at the end on .fex file that looks like this:
[gpio-para]
gpio_used = 1
gpio_num = 1
gpio_pin_1 = port:PG12<1><default><default><default>


After running the update script and rebooting, the UART-TX pin is now 1V (it was 3V previously) and I still can't change it through sysfs.

I think I'll give up now :)

Thanks for the help.

Offline allen

  • Jr. Member
  • **
  • Posts: 68
  • Karma: +0/-0
    • View Profile
Re: No GPIO and ADC?
« Reply #9 on: June 28, 2015, 11:14:21 pm »
a80 use pinctrl to manage the pin .but i don't know how to use .
 
« Last Edit: June 28, 2015, 11:23:41 pm by allen »

Offline allen

  • Jr. Member
  • **
  • Posts: 68
  • Karma: +0/-0
    • View Profile
Re: No GPIO and ADC?
« Reply #10 on: June 28, 2015, 11:59:06 pm »
i am sorry .the code have a error .
Code: [Select]
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/select.h>
#include <pthread.h>
#include <unistd.h>
#include <sched.h>
#include <errno.h>


#define SW_PORTC_IO_BASE  0x06000800

int main() {
unsigned int * pc;
int fd, i;
char * ptr;
unsigned int addr_start, addr_offset, PageSize, PageMask, data;

PageSize = sysconf(_SC_PAGESIZE);
PageMask = (~(PageSize-1));
addr_start = SW_PORTC_IO_BASE & PageMask;
addr_offset = SW_PORTC_IO_BASE & ~PageMask;

fd = open("/dev/mem", O_RDWR);
if(fd < 0) {
   perror("Unable to open /dev/mem");
   return(-1);
}

pc = mmap(0, PageSize*2, PROT_READ|PROT_WRITE, MAP_SHARED, fd, addr_start);

if(pc == MAP_FAILED) {
   perror("Unable to mmap file");
   printf("pc:%lx\n", (unsigned long)pc);
   return(-1);
}
printf("PageSize:%8.8x\tPageMask:%8.8x\naddr_start:%8.8x\taddr_offset:%8.8x\n",PageSize,PageMask,addr_start,addr_offset);
printf("pc:%8.8x\n", *(unsigned int *)pc);
ptr = (char *)pc + addr_offset;

//the PG12 is UART4-TX in the board ,set it as output port
data = *(unsigned int *)(ptr+0xdc);
data &= ~(7<<16);                         
data |= 1<<16;                         
*(unsigned int *)(ptr+0xdc) = data;

//set it high level .If set low , data &= 0<<12 replace  data |= 1<<12
data = *(unsigned int *)(ptr+0xe8);
data |= 1<<12;                         
*(unsigned int *)(ptr+0xe8) = data;


return 0;
    }


If set low , data &= 0<<12 replace  data |= 1<<12

Offline lacho.tomov

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: No GPIO and ADC?
« Reply #11 on: June 29, 2015, 03:00:25 pm »
It worked, thanks a lot!

Can you point me to a document that has the memory mappings, registers, etc?
I didn't find them in the datasheet and I googled just this one:
http://linux-sunxi.org/A80/Memory_map

which says the 0x06000800 from your code is the start if "PIO Config registers" but I didn't find a document with the other memory addresses...

Offline allen

  • Jr. Member
  • **
  • Posts: 68
  • Karma: +0/-0
    • View Profile
Re: No GPIO and ADC?
« Reply #12 on: June 29, 2015, 11:05:48 pm »
 you can download the  newest document from https://github.com/allwinner-zh/documents/tree/master/A80 .

Offline lacho.tomov

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: No GPIO and ADC?
« Reply #13 on: June 30, 2015, 02:32:52 am »
Thank you very much!