Hi,
U can go through Linux  Documentation for i2c
Plain I2C communication
-----------------------
        int i2c_master_send(struct i2c_client *client, const char *buf,
                            int count);
        int i2c_master_recv(struct i2c_client *client, char *buf, int
count);
These routines read and write some bytes from/to a client. The client
contains the i2c address, so you do not have to include it. The second
parameter contains the bytes to read/write, the third the number of bytes
to read/write (must be less than the length of the buffer.) Returned is
the actual number of bytes read/written.
        int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msg,
                         int num);
This is if u r doing from kernel.


If u want to communicate to a i2c device from user space

I2C device files are character device files with major device number
89 and a minor device number corresponding to the number assigned as
explained above. They should be called "i2c-%d" (i2c-0, i2c-1, ...,

i2c-10, ...). All 256 minor device numbers are reserved for i2c.

Usually, i2c devices are controlled by a kernel driver. But it is also
possible to access all devices on an adapter from userspace, through
the /dev interface. You need to load module i2c-dev for this.

Each registered i2c adapter gets a number, counting from 0. You can
examine /sys/class/i2c-dev/ to see what number corresponds to which
adapter.



int file = open(/dev/i2c-0, O_RDWR);

When you have opened the device, you must specify with what device
address you want to communicate:



        int addr = 0x40; /* The I2C address */



              ioctl(file, I2C_SLAVE, addr)

Then u can communicate with the device



Regards,

Kavitha










On Tue, Oct 12, 2010 at 5:42 PM, shootingatshadow <whydevelopma...@gmail.com
> wrote:

> I am a bit new to Linux device drivers, been doing some research and
> trying things out. (Read Linux Device Drivers Book, digging around
> forums)
>
> So I have found at i2c address 0x38 a chip which I would like to talk
> to. There is already a driver in place for that chip. I have the spec
> sheet in hand for that chip as well. However, the device shows up
> under /proc/bus and in the devices file. How can I access this device
> and send it information? My only other experience is opening a file
> under /dev/DEVICE and read and write bytes to it, any suggestions
> would be greatly appreciated.
>
> --
> unsubscribe: 
> android-porting+unsubscr...@googlegroups.com<android-porting%2bunsubscr...@googlegroups.com>
> website: http://groups.google.com/group/android-porting
>

-- 
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: http://groups.google.com/group/android-porting

Reply via email to