/*****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[2]; 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("**** RAS32T PORT 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] = 0x00; buf[1] = 0x11; if(i2cwrite(buf,2)){ 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); } //PORT 1 WRITE// buf[0] = 0x08; buf[1] = 0x22; if(i2cwrite(buf,2)){ 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); } //PORT 2 WRITE// buf[0] = 0x10; buf[1] = 0x33; if(i2cwrite(buf,2)){ 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); } //PORT 3 WRITE// buf[0] = 0x18; buf[1] = 0x44; if(i2cwrite(buf,2)){ 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; }