Здравствуйте.
Необходимо организовать обмен данными по 32-ух разрядному GPIO интерфейсу.
GPIO после загрузки linux находится тут "/sys/class/gpio/gpio192/".
Вот код с помощью которого я записываю данные в GPIO 32x:
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#define ERROR printf("-- gpio_write <value> \n-- va1ue = 1 or 0 \n");
int str_to_int(char str[],int len){ //преобразуется строка в число
int a=0,i;
for (i=0;i<len-3;i++){
switch(str[i]){
case '0': a=0;break;
case '1': a=1;break;
default : a=2;
}
}
return(a);
}
int main(int argc, char *argv[])
{
int valuefd, exportfd, directionfd, c;
if((c>1)&&(argc<1)){ERROR;return 0;}
c=str_to_int(argv[1],sizeof(argv[1]));
if(c==2){ERROR;return 0;}
printf("GPIO test running...\n");
// The GPIO has to be exported to be able to see it
// in sysfs
exportfd = open("/sys/class/gpio/export", O_WRONLY);
if (exportfd < 0)
{
printf("Cannot open GPIO to export it\n");
exit(1);
}
write(exportfd, "192", 4); // 192 - номер моего GPIO чипа
close(exportfd);
printf("GPIO exported successfully\n");
// Update the direction of the GPIO to be an output
directionfd = open("/sys/class/gpio/gpio192/direction", O_RDWR);
if (directionfd < 0)
{
printf("Cannot open GPIO direction it\n");
exit(1);
}
write(directionfd, "out", 4); // конфигурирую на выход
close(directionfd);
printf("GPIO direction set as output successfully\n");
// Get the GPIO value ready to be toggled
valuefd = open("/sys/class/gpio/gpio192/value", O_RDWR);
if (valuefd < 0)
{
printf("Cannot open GPIO value\n");
exit(1);
}
printf("GPIO value opened, now toggling...\n");
// toggle the GPIO as fast a possible forever, a control c is needed
// to stop it
if(c==1){
write(valuefd,"1111111111111111111111111111111", 32); // записываю в GPIO 32x еденицы
printf(" GPIO out is high \n");
}
if(c==0){
write(valuefd,"0000000000000000000000000000000", 32); // записываю в GPIO 32x нули
printf(" GPIO out is low \n");
}
close(valuefd);
return 0;
}
Но в результате изменяются значения только на первом разряде 32-ух разрядного GPIO, остальные неменяются.
Что надо зделать чтобы GPIO шина заработала полноценно?