I2c library for C
This library was created to make communication with I2C devices from C language. Up to know it has work fine for in Raspberry Pi boards (and similar ones!).
Download: File:I2c-driver.tar.gz
Contents
Usage
int i2c_dev_open(struct i2c_dev *dev, int adapter);
int i2c_dev_close(struct i2c_dev *dev);
int i2c_dev_write(struct i2c_dev *dev, uint8_t *buf, int n);
int i2c_dev_read(struct i2c_dev *dev, uint8_t *buf, int n);
int i2c_dev_wrrs(struct i2c_dev *dev, uint8_t *wbuf, int wn, uint8_t *rbuf, int rn);
Set Up I2C device
int i2c_dev_open(struct i2c_dev *dev, int adapter);
Close I2C device
int i2c_dev_close(struct i2c_dev *dev);
Write to device
int i2c_dev_write(struct i2c_dev *dev, uint8_t *buf, int n);
Read from device
int i2c_dev_read(struct i2c_dev *dev, uint8_t *buf, int n);
Combined Write/Read
int i2c_dev_wrrs(struct i2c_dev *dev, uint8_t *wbuf, int wn, uint8_t *rbuf, int rn);
The purpose of this is to allow combined write/read operations to one or more devices without releasing the bus and thus with the guarantee that the operation is not interrupted.
The hardware support for this feature is usually disable in the Rapberry Pi. To activate it execute as root:
echo 1 > /sys/module/i2c_bcm2708/parameters/combined