LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 03-02-2011, 10:37 AM   #1
napier
LQ Newbie
 
Registered: Mar 2011
Posts: 1

Rep: Reputation: 0
i2c-dev.h Issues


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. I'm using OpenWRT on a atheros platform. Everything is compiling properly without error but I am getting ioctl errors out the wazoo.

//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.
 
Old 03-24-2011, 12:20 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,955
Blog Entries: 13

Rep: Reputation: 4986Reputation: 4986Reputation: 4986Reputation: 4986Reputation: 4986Reputation: 4986Reputation: 4986Reputation: 4986Reputation: 4986Reputation: 4986Reputation: 4986
Read ioctl(2) manpage, not to say that this is your problem:

Note
In order to use this call, one needs an open file descriptor. Often the open(2) call has unwanted side effects, that can be avoided under Linux by giving it the O_NONBLOCK flag.

Try the O_NONBLOCK and further, change the output to include the errno value

%d:%s\n", errno, strerror(errno));

Then you'll see the actual number and can correlate that from errno.h to the return value; such as EBADF, EINVAL, etc; which are also noted in the manpage for ioctl.

You say you have examples that work, if that code is available, look at it and copy it. Or search for I2C Linux source code examples.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Issues with /dev/pts & /dev/shm, when LFS boots zer0signal Linux From Scratch 2 12-21-2010 07:14 AM
Unable to open the device /dev/i2c-0 avyadavnitw Linux - Embedded & Single-board computer 3 06-29-2009 03:31 AM
Help! Problems with i2c-dev. No more /dev/i2c-* em1l Fedora 0 10-28-2005 05:48 AM
missing /dev/i2c nodes puremourning Linux - Software 0 02-23-2005 09:10 PM
Unknown symbols in i2c-dev Zoombie Linux - Hardware 0 06-28-2004 02:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 02:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration