看板 LinuxDev 關於我們 聯絡資訊
請教一下在 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)
bluestar8783:為啥不用i2c_master_send/i2c_master_recv??? 12/02 18:45
eleghost:他這是ap層的code, 難道len加大不能讀更多byte嗎? 12/03 09:50
weishiang:謝謝eleghost提醒,只查r/w的code忘記看傳過來的參數值@@ 12/05 09:26