[問題] 請教 i2c 的連續讀取
請教一下在 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)
→
12/02 18:45, , 1F
12/02 18:45, 1F
推
12/03 09:50, , 2F
12/03 09:50, 2F
→
12/05 09:26, , 3F
12/05 09:26, 3F
LinuxDev 近期熱門文章
PTT數位生活區 即時熱門文章