2 Replies Latest reply on May 27, 2016 12:13 PM by TroyW

    I2C not working on galileo gen2

    Nilesh.kadivar

      Hi,

       

      I have installed windriver linux in intel galileo gen2 board. I am able to get /dev/i2c-0 but can't able to get any I2C related command(i.e i2cdetect, i2cdump, etc...).

      Also I have made one sample code as below. which gives error in read and write operation with return value -1. Please give me solution.

       

      /---------------------------------------------------------------------------------------------------------------------------

      #include <stdio.h>

      #include <stdlib.h>

      #include <string.h>     // string function definitions

      #include <sys/types.h>

      #include <sys/stat.h>

      #include <sys/ioctl.h>

      #include <linux/i2c-dev.h>

      #include <linux/i2c.h>

      #include <errno.h>

      #include <fcntl.h>

      #include <unistd.h>

      #include <termios.h>

      #include "LLAPIExport.h"

       

       

      #define I2C_ADDR 0x48

       

      int main (void) {

        char buffer[1];

        int fd;

       

       

        fd = open("/dev/i2c-0", O_RDWR);

       

       

        if (fd < 0)

        {

        printf("Port Open Failed....\n");

        return 1;

        }

        else

        {

        printf("Port Open successfully....\n");

        }

       

       

        if (ioctl(fd, I2C_SLAVE, I2C_ADDR) < 0)

        {

        printf("IOCTL open error....\n");

        return 1;

        }

       

       

        buffer[0]=0x00;

              int byteWritten = write(fd, buffer, 1);

        printf("Write byteWritten..%d..\n", byteWritten);

        if(byteWritten != 1)

        {

        printf("Write Fail....\n");

        }

       

        if(read(fd, buffer, 1) != 1)

        {

        printf("Read Fail....\n");

        }

        else

        {

        printf("0x%02X\n", buffer[0]);

        }

        close(fd);

        return 0;

      }

       

      /---------------------------------------------------------------------------------------------------------------------------



      Thanks in advance.