#include #include #include #include #include #include #define I2C_SLAVE 0x0703 /* Change slave address */ int i2c; int rc; unsigned int address; unsigned char data[3]; unsigned char result[2]; int main(int argc, char ** argv) { if(argc != 4) { fprintf(stderr, "usage: %s [I2Cdevice_address] [command] [data16bits]",argv[0]); exit(1); } /* address is the first number after the program name */ address = atoi(argv[1]); // i2c slave address data[0] = atoi(argv[2]); // pic command data[1] = atoi(argv[3]); // pic data lsb data[2] = atoi(argv[3])>>8; // pic data msb i2c = open("/dev/i2c-0",O_RDWR); /* open the device dev/i2c-0 */ rc=ioctl(i2c,I2C_SLAVE,address); /* set the i2c chip address */ // write data to pic write(i2c,data,3); //usleep(50); printf("I2Cdev[%d] -> Command=%d, Data_LSB=%d, Data_MSB=%d\n", address, data[0], data[1], data[2]); i2c = close(i2c); return(0); }