Sorry, you need to enable JavaScript to visit this website.

Only first access to GPIO seems to work.

Solved
3 posts / 0 new
Tkafafi's picture
Tkafafi
Junior(0)
Only first access to GPIO seems to work.

Hi,

When I access GPIO from C code, only the first access goes through. Further access are basically ignored. I need to close the value file and reopen to do another access. 
Everything works fine I I echo value from shell, thou
gh. So I'm not sure what is the problem ?
 
Below is the working C code after modyfing it to close and reopen after every access:

#include <stdio.h>

 

int main()
{
 FILE *gp;
    int i;
    printf("Open file\n");
    gp = fopen("/sys/class/gpio/gpio939/value", "w");
    for ( i =0; i < 10; i++) {
       fputs("0", gp);

fclose(gp);

gp = fopen("/sys/class/gpio/gpio939/value", "w");
       fputs("1", gp);
fclose(gp);

gp = fopen("/sys/class/gpio/gpio939/value", "w");
    }

    printf("Close File\n");
    fclose(gp);
    printf("Done\n");
    return 0;
}

fletch's picture
fletch
Moderator(17)
I'm not sure exactly what the
Tkafafi's picture
Tkafafi
Junior(0)
seems this is expected behavior.

ok seems this behavior is expected, according to info provided at: https://falsinsoft.blogspot.ca/2012/11/access-gpio-from-linux-user-space...