I am using Petalinux 2015.4 and Zedboard. I am reading a GPIO which is supposed to go from 0 to 1 and in commandline, I can see that it happens. But when I execute it in the code, the value always remain 0 as initial value is 0. My code is as follows:
Question
Saad Zia
Dear Experts
I am using Petalinux 2015.4 and Zedboard. I am reading a GPIO which is supposed to go from 0 to 1 and in commandline, I can see that it happens. But when I execute it in the code, the value always remain 0 as initial value is 0. My code is as follows:
int number=-1;
unsigned char error = 0;
int fd_done;
//Export GPIO
fd_done = open("/sys/class/gpio/export", O_WRONLY);
if(fd_done < 0)
{
#if DEBUG_GPIOBit
printf("ERROR:\tGPIO Export Failed\n\r");
#endif
error=1;
}
write(fd_done,"903",3);
close(fd_done);
//Set GPIO as input
fd_done = open("/sys/class/gpio/gpio903/direction", O_WRONLY);
if(fd_done < 0)
{
#if DEBUG_GPIOBit
printf("ERROR:\tGPIO Direction Failed\n\r");
#endif
error=1;
}
write(fd_done,"in",2);
close(fd_done);
char value;
fd_done = open("/sys/class/gpio/gpio903/value", O_WRONLY);
lseek(fd_done, 0, SEEK_SET);
read(fd_done, &value, 8);
printf("Done Value: \t %d \n",value);
close(fd_done);
fd_done = open("/sys/class/gpio/unexport", O_WRONLY);
write( fd_done,"903",3);
close(fd_done);
return number;
3 answers to this question
Recommended Posts
Archived
This topic is now archived and is closed to further replies.