以上时序摘自镁光的一款camera sensor.
1写模式:
首先开始信号,主机发送从机地址(0-7位)/写(第8位),等待从机发送ACK信号,应答之后发送word16位的消息为sensor寄存器地址,分八位传输中间有ACK信号。同理接着发送16位value对应刚才寄存器地址。(见下面源码)
static int mt9t013_i2c_write_w(unsigned short saddr,
unsigned short waddr, unsigned short wdata)
{
int rc = -EIO;
unsigned char buf[4];
memset(buf, 0, sizeof(buf));
buf[0] = (waddr & 0xFF00) >> 8;
buf[1] = (waddr & 0x00FF);
buf[2] = (wdata & 0xFF00) >> 8;
buf[3] = (wdata & 0x00FF);
rc = mt9t013_i2c_txdata(saddr, buf, 4);
if (rc < 0)
pr_err("i2c_write_w failed, addr = 0x%x, val = 0x%x!\n",
waddr, wdata);
return rc;
}
2读模式:
和写模式一样 先addr后data.见上图。