#include #include #include #include #include #include #define I2C_BUS "/dev/i2c-3" int I2C_Write(int address, int value) { struct i2c_smbus_ioctl_data argswrite; argswrite.read_write = I2C_SMBUS_WRITE; argswrite.size = I2C_SMBUS_BYTE; argswrite.data = NULL; argswrite.command = value; int device = open(I2C_BUS, O_RDWR); if (device == -1) return device; ioctl(device, I2C_SLAVE, address); ioctl(device, I2C_SMBUS, &argswrite); close(device); } int I2C_Read(int address) { union i2c_smbus_data data; struct i2c_smbus_ioctl_data argsread; argsread.read_write = I2C_SMBUS_READ; argsread.size = I2C_SMBUS_BYTE; argsread.data = &data; argsread.command = 0; int device = open(I2C_BUS, O_RDWR); if (device == -1) return device; ioctl(device, I2C_SLAVE, address); ioctl(device, I2C_SMBUS, &argsread); close(device); return data.byte; }