|
Ronny Pau
|
using devctl (DCMD_I2C_SENDRECV)
|
|
Ronny Pau
08/30/2010 12:00 PM
post65024
|
using devctl (DCMD_I2C_SENDRECV)
Hi, I am writing something to try and communicate with an i2c device, particularly, reading register values.
According to the datasheet, the device has 1-byte addresses and 2-byte data. So I have set up the read function as
follows. Can someone tell me if I am doing the right thing? I kept getting error 5 (no error) as a result of the devctl
call.
struct {
i2c_sendrecv_t hdr;
unsigned char bytes[2];
} msg;
msg.hdr.slave.addr = dev->i2c_devaddr;
msg.hdr.slave.fmt = I2C_ADDRFMT_7BIT;
msg.hdr.send_len = 1;
msg.hdr.recv_len = 2;
msg.hdr.stop = 1;
msg.bytes[0] = reg;
if (EOK != (ret = devctl(dev->i2c_fd, DCMD_I2C_SENDRECV, &msg, sizeof(msg), &bytes))) {
fprintf(stderr, "%s: devctl() failed, error = %d - %s\n", MODULE_NAME, ret, strerror(errno));
return -1;
}
*data = msg.bytes[0];
|
|
|
|
|