2011-03-02 11:26:57     i2c-dev.h Issues

Document created by Aaronwu Employee on Aug 26, 2013
Version 1Show Document
  • View in full screen mode

2011-03-02 11:26:57     i2c-dev.h Issues

Nathan V (CANADA)

Message: 98599   

 

Okay,

 

I've been trying for days to get i2c-dev working properly. I have everything I need according to instructions, but for some reason I keep getting errors at ioctl.

 

//CODE

    //TEST BEGIN

    int file;

 

    //Open i2c dev

    if(file = open( "/dev/i2c-0", O_RDWR )<0)

    {

        enabled = -1;

        printf("Unable to open file /dev/i2c-0.\n");

    }

    else

    {

        printf("Opened file /dev/i2c-0.\n");

        enabled = 1;

    }

 

    printf("File is %d\n",file);

 

    if( ioctl( file, I2C_SLAVE, 0x4b ) < 0 )

 

    {

        printf("Error opening file: %s\n", strerror( errno ) );

        printf("Open chip %d FAILED file %d\n", 0x4b, file);

    }

    else

    {

        printf("Open chip %d Succeeded file %d\n",0x4b, file);

    }

 

//CODE END

 

At the level of ioctl(file, i2C_SLAVE,address) I get the following error: "Error opening file: Invalid argument". So I'm successfully opening /dev/i2c-0 but I can't do a ioctl to the specific chip address. I've already verified the chip address using i2cdetect, and I've also verified that I can read/write with the other i2ctools suite.

What am I missing?

I am including the i2c-dev.h file from the the i2c-tools package. I just put it in my src directory and I #include "i2c-dev.h" as my final include in my .cpp file. All the defines and functions are configuring correctly, so I imagine it's included right. But I wonder if I need to compile the i2c-dev.h file separately or in a different way than my other code?

I am compiling with -O2 as I understand that's somehow required. Not sure if there needs to be anything else special in my make file since everything is building correctly without errors.

QuoteReplyEditDelete

 

 

2011-03-02 11:47:20     i2c-dev.h Issues

Michael Hennerich (GERMANY)

Message: 98600    Take a look at the uclinux-dist/user/blkfin-test/ppifcd-test application.

You can find some tested example code using /dev/i2c.

 

-Michael

QuoteReplyEditDelete

 

 

2011-03-02 21:40:05     Re: i2c-dev.h Issues

Mike Frysinger (UNITED STATES)

Message: 98606   

 

run it through strace and post the output

Attachments

    Outcomes