User's Manual
MiraBoxUser Guide –page23 / 27
structi2c_rdwr_ioctl_datae2prom_data;
fd=open("/dev/i2c‐0",O_RDWR);/*/dev/i2c‐0isregisteredtothesystem*/
if(fd<0)
{
perror("openerror");
}
e2prom_data.nmsgs=2;
e2prom_data.msgs=(structi2c_msg*)malloc(e2prom_data.nmsgs*sizeof(structi2c_msg));
if(!e2prom_data.msgs)
{
perror("mallocerror");
exit(1);
}
ioctl(fd,I2C_TIMEOUT,1);/*timeout*/
ioctl(fd,I2C_RETRIES,2);/*retriestimes*/
/***writedatatoe2prom**/
e2prom_data.nmsgs=1;
(e2prom_data.msgs[0]).len=2;
(e2prom_data.msgs[0]).addr=0x25;//e2promdeviceaddress
(e2prom_data.msgs[0]).flags=0;//write
(e2prom_data.msgs[0]).buf=(unsignedchar*)malloc(2);
/***********controltheGPIOOP‐0**************************************/
(e2prom_data.msgs[0]).buf[0]=0x18;//e2promwriteaddress
(e2prom_data.msgs[0]).buf[1]=0x0;//thedatatowrite
ret=ioctl(fd,I2C_RDWR,(unsignedlong)&e2prom_data);
if(ret<0)
{
perror("ioctlerror2");
}
/***********controltheGPIOOP‐1**************************************/
(e2prom_data.msgs[0]).buf[0]=0x19;//e2promwriteaddress
(e2prom_data.msgs[0]).buf[1]=0x0;//thedatatowrite
ret=ioctl(fd,I2C_RDWR,(unsignedlong)&e2prom_data);
if(ret<0)
{
perror("ioctlerror2");
}