2009-05-04 11:05:26     reaing from simple-gpio

2009-05-04 11:05:26     reaing from simple-gpio

Tom Proost (BELGIUM)

Message: 73573   

Hello all,

Hardware: BF537

uClinux: 2008R1.5

I'm working on a spi-controller project, I'm using I/O-expanders (mcp23s08), these produce an interrupt signal when inputs change.

The interrupt line is directly connected to GPIO_27.

I'm measuring voltages:

with spi-controller connected: gpio_27  -> 4,97V      

spi-controller disconnected: gpio_27 -> 0 V

I'm reading values using simple-gpio driver:

with spi-controller connected: gpio_27  -> read value: 49   

spi-controller disconnected: gpio_27 -> read value: 49

My (simple) code, based on simple-gpio-game.c:

btw, simple-gpio-game.c differs from simple-gpio-test.c in coding style and functions used: open <-> fopen, is there a real difference?

/* open gpio -> connected with interrupt-line from mcp23s08_1 */

   

   //gp1 = open("gpio27", "r+");      //use second option, difference?

    gp1 = open("gpio27", O_RDWR);

    if (!gp1)

        perror("unable to open specified device GPIO27");

    else {

        printf ("\ngpio27 opened\n"); }

   

    /* set it to input mode */

    if (write(gp1, "I", 1) != 1)

        perror("unable to set to input");

    else {                         // debug purposes

        printf ("set to input\n"); }

    /* read current value*/

    int bit = 0;

    printf ("read value: %i\n", bit);

    if (read(gp1, &bit, 1) != 1)

        perror("unable to read gpio27");

    else {                        

        printf ("read value: %i\n", bit); }

Could anybody give me a hint? Where do I go wrong?

Thanks in advance!

Regards,

Tom

TranslateQuoteReplyEditDelete

2009-05-04 18:41:35     Re: reaing from simple-gpio

Mike Frysinger (UNITED STATES)

Message: 73598   

except you deleted the fsync() call ...

QuoteReplyEditDelete

2009-05-05 06:43:48     Re: reaing from simple-gpio

Tom Proost (BELGIUM)

Message: 73649   

Indeed, sorry for that

Just to make sure (I'm new to this):

fsync() flushes all the data-changes to 'disk', so I can read the correct values later on from the file descriptor.

new code:

/* open gpio -> connected with interrupt-line from mcp23s08_1 */

    int        gp[2]

    gp[0] = open("gpio27", O_RDWR);

    if (!gp[0])

        perror("unable to open specified device GPIO27");

    else {

        printf ("\ngpio27 opened\n"); }

  

    /* set it to input mode */

    if (write(gp[0], "I", 1) != 1)

        perror("unable to set to input");

    else {                         // debug purposes

        printf ("set to input\n"); }

    if( fsync(gp[0]) == -1)

        perror("syncronisation fail");  

    int bit = 0;

    printf ("initialised buffer: %i\n", bit);

    if (read(gp[0], &bit, 1) != 1)

        perror("unable to read gpio27");

    else {             

        printf ("read value: %i\n", bit); }

output:

gpio27 opened

set to input

syncronisation fail: Invalid argument

initialised buffer: 0

read value: 49

Still the same results, sorry if it's a newbie-mistake.

regards

TranslateQuoteReplyEditDelete

2009-05-05 06:59:06     Re: reaing from simple-gpio

Tom Proost (BELGIUM)

Message: 73651   

when I use fsync(fileno(gp)); (int gp;  declared )

The kernel gives a fault:

/* Maybe null pointer? */

(with a lot of adress info etc)

btw, unistd.h is includes as is required for fsync.

TranslateQuoteReplyEditDelete

2009-05-05 07:03:48     Re: reaing from simple-gpio

Mike Frysinger (UNITED STATES)

Message: 73652   

flieno(gp) makes no sense at all.  it operates on a FILE* and returns the backing fd.  if you already have the backing fd, there is no reason whatsoever to use fileno().

  • Created
Was this helpful?

Before You Switch


Switching languages will make ADI Explorer unavailable. Resume your session by switching back to English and reopening ADI Explorer.