MiraBox User Guide
–page
25
/
29
struct i2c_rdwr_ioctl_data e2prom_data;
fd=open("/dev/i2c-0",O_RDWR);/* /dev/i2c-0 is registered to the system */
if(fd<0)
{
perror("open error");
}
e2prom_data.nmsgs=2;
e2prom_data.msgs=(struct i2c_msg*)malloc(e2prom_data.nmsgs*sizeof(struct i2c_msg));
if(!e2prom_data.msgs)
{
perror("malloc error");
exit(1);
}
ioctl(fd,I2C_TIMEOUT,1);/*timeout */
ioctl(fd,I2C_RETRIES,2);/*retries times*/
/***write data to e2prom**/
e2prom_data.nmsgs=1;
(e2prom_data.msgs[0]).len=2;
(e2prom_data.msgs[0]).addr=0x25;//e2prom device address
(e2prom_data.msgs[0]).flags=0; //write
(e2prom_data.msgs[0]).buf=(unsigned char*)malloc(2);
/*********** control the GPIO OP-0 **************************************/
(e2prom_data.msgs[0]).buf[0]=0x18;// e2prom write address
(e2prom_data.msgs[0]).buf[1]=0x0;//the data to write
ret=ioctl(fd,I2C_RDWR,(unsigned long)&e2prom_data);
if(ret<0)
{
perror("ioctl error2");
}
/*********** control the GPIO OP-1 **************************************/
(e2prom_data.msgs[0]).buf[0]=0x19;// e2prom write address
(e2prom_data.msgs[0]).buf[1]=0x0;//the data to write
ret=ioctl(fd,I2C_RDWR,(unsigned long)&e2prom_data);
if(ret<0)
{
perror("ioctl error2");
}