注意:需打开设备/dev/i2c-1权限,否则会碰到Pemission Denied错误。从源码根目录下,进入system/core/rootdir目录,打开ueventd.rc 添加一行:/dev/i2c-x x为对应的总线编号
fd =open("/dev/i2c-0", O_RDWR);
读写方式打开设备 i2c-x 0为对应的总线号
*buf = (unsigned char)((register_address >> 8) & 0xf);
*(buf + 1) = (unsigned char)(register_address >> 0 & 0xf);
msg.addr= ucDevAddr;
msg.addr=0x96;
//msg.flags = 0;
msg.len= 2 | ((size & 0x1F) << 8);
msg.buf= (unsigned char *)buf;
msg.ext_flag = I2C_WR_FLAG | I2C_RS_FLAG;
ioctl_data.nmsgs= 1;
ioctl_data.msgs= &msg;
上面填充完数据之后,调用ioctl接口发送数据
ioctl(fd, I2C_RDWR, &ioctl_data);