作者weishiang (wei)
看板LinuxDev
标题[问题] 请教 i2c 的连续读取
时间Fri Dec 2 16:50:05 2011
请教一下在 linux 上要如何连续读取 i2c 的资料呢?
目前都只能一次读取 1 byte , my code :
struct i2c_msg msg[2];
struct i2c_rdwr_ioctl_data queue;
uint8_t *buf;
uint8_t *buf2;
buf = (uint8_t*) malloc(sizeof(uint8_t) * 1);
buf[0] = 0x00;
buf2 = (uint8_t*) malloc(sizeof(uint8_t) * 32);
buf[0] = 0xff;//test:
queue.msgs = msg;
queue.nmsgs = 2;
queue.msgs[0].len = (len+1);
queue.msgs[0].addr = DevAddr_list[bus_idx];
queue.msgs[0].flags = 0;
queue.msgs[0].buf = buf; // read address of i2c client
queue.msgs[1].len = len;
queue.msgs[1].addr = DevAddr_list[bus_idx];
queue.msgs[1].flags = I2C_M_RD;
queue.msgs[1].buf = buf2
ret = ioctl(fd, I2C_RDWR, (uint32_t)&queue);
if (ret < 0) {
printf("Error dring I2C_RDWR ioctl with error code: %d\n", ret);
return ret;
}
thank you!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.218.111.194
※ 编辑: weishiang 来自: 61.218.111.194 (12/02 16:57)
1F:→ bluestar8783:为啥不用i2c_master_send/i2c_master_recv??? 12/02 18:45
2F:推 eleghost:他这是ap层的code, 难道len加大不能读更多byte吗? 12/03 09:50
3F:→ weishiang:谢谢eleghost提醒,只查r/w的code忘记看传过来的参数值@@ 12/05 09:26