[問題] 請教 i2c 的連續讀取

看板LinuxDev作者 (wei)時間14年前 (2011/12/02 16:50), 編輯推噓1(102)
留言3則, 3人參與, 最新討論串1/1
請教一下在 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
為啥不用i2c_master_send/i2c_master_recv???
12/02 18:45, 1F

12/03 09:50, , 2F
他這是ap層的code, 難道len加大不能讀更多byte嗎?
12/03 09:50, 2F

12/05 09:26, , 3F
謝謝eleghost提醒,只查r/w的code忘記看傳過來的參數值@@
12/05 09:26, 3F
文章代碼(AID): #1Es950d2 (LinuxDev)
文章代碼(AID): #1Es950d2 (LinuxDev)