Hardware Reference
In-Depth Information
iomsgs[1].addr = iomsgs[0].addr; /* Same MCP23017-A */
iomsgs[1].flags = I2C_M_RD; /
Read operation
/
iomsgs[1].buf = rbuf;
iomsgs[1].len = 1;
msgset.msgs = iomsgs;
msgset.nmsgs = 2;
rc = ioctl(fd,I2C_RDWR,&msgset);
if ( rc < 0 ) {
perror("ioctl (2, I2C_RDWR)");
The example shown defines iomsgs[0] as a write of 1 byte, containing a register
number. The entry iomsgs[1] describes a read of 1 byte from the peripheral. These two
messages are performed in one ioctl(2) transaction. The flags member of iomsgs[x]
determines whether the operation is a read ( I2C_M_RD ) or a write (0).
Note
Don't confuse the peripheral's internal register with the peripheral's I2C address.
Each of the iomsgs[x].addr members must contain a valid I2C peripheral address.
Each message can potentially address a different peripheral, though there are no
examples of this in this topic. The ioctl(2) will return an error with the first message
failure. For this reason, you may not always want to combine multiple messages in one
ioctl(2) call, especially when different devices are involved.
The returned value, when successful, is the number of struct i2c_msg messages
successfully performed.
 
 
Search WWH ::




Custom Search