Hi Sliex

On Sat, Dec 3, 2011 at 10:22 AM, silex <mertoztoprak@gmail.com> wrote:
Hello,

I have Gumstix Overo, with 2.6.35 kernel on it.. I need to achieve
communication with Sparkfun IMU3000 Accelerometer&Gyro. I had spent so much
hours on it, but i could not succeed on using "ioctl" function, i need your
help.
I can open i2c-3 port without any problem. But, after running (ioctl(fh,
I2C_SLAVE,GYRO_W) function ,as i used at the below, i get this error:
"ioctl: Invalid Argument"
I have realized that, if i write 7 bits of data to  the address of slave
device, i dont get any errors. But all of my r/w slave address bits are 8
bit, so how can i use ioctl without problem??

Here is the code;

#include <stdint.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/i2c-dev.h>
#include <linux/i2c.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>

//addresses of imu
#define GYRO_W 0xD0
#define GYRO_R 0XD1
#define ACC_W 0xA6
#define ACC_R 0xA7

The problem with your ioctl is that you're not using the correct address.

In the i2c protocol, the address is the upper 7 bits of the first byte, and the low bit is the read/write bit. You're providing the entire byte rather than just the address.

A byte of 0xD0 corresponds to an address of 0x68. The ioctl checks that the address you're passing in fits in 7 bits which is why it was failing.

--
Dave Hylands
Shuswap, BC, Canada
http://www.davehylands.com