/*****I2C TEST PROGRAM*****/ #include #include #include #include #include #include #include #include #include int fd; //char *i2cdev = "/dev/i2c-0"; char *i2cdev = "/dev/i2c-1"; unsigned char buf[1]; int i2cwrite(char *buf, int len) { if((write(fd, buf, len)) != len){ return(1); } return(0); } int main() { unsigned char SLAVE_ADDRESS = 0x11; //SLAVE_ADDRESS unsigned char rddat; printf("**** I2C ALL WRITE ****\n"); if((fd = open(i2cdev, O_RDWR)) < 0){ printf("Can't open i2c\n"); exit(1); } if(ioctl(fd,I2C_SLAVE, SLAVE_ADDRESS) < 0){ printf("Unable to get bus access to talk to slave\n"); exit(1); } //PORT 0 WRITE// buf[0] = 0xe0; buf[1] = 0x11; buf[2] = 0x22; buf[3] = 0x33; buf[4] = 0x44; if(i2cwrite(buf,5)){ printf("write error SA = %02x\n",SLAVE_ADDRESS); exit(1); } if(ioctl(fd, I2C_SLAVE,SLAVE_ADDRESS) < 0) { printf("Unable to bus access to talk to slave\n"); exit(1); } close(fd); return 0; }