Hardware Reference
In-Depth Information
The members of this structure are as follows:
addr : Normally this is the 7-bit slave address, unless flag
I2C_M_TEN and function I2C_FUNC_10BIT_ADDR are used. Must
be provided for each message.
flags : Valid flags are listed in Table 12-2 . Flag I2C_M_RD
indicates the operation is a read. Otherwise, a write operation
is assumed when this flag is absent.
buf : The I/O buffer to use for reading/writing this message
component.
len : The number of bytes to read/write in this message
component.
Table 12-2. I2C Capability Flags
Flag
Description
I2C_M_TEN
10-bit slave address used
I2C_M_RD
Read into buffer
I2C_M_NOSTART
Suppress (Re)Start bit
I2C_M_REV_DIR_ADDR
Invert R/W bit
I2C_M_IGNORE_NAK
Treat NAK as ACK
I2C_M_NO_RD_ACK
Read will not have ACK
I2C_M_RECV_LEN
Buffer can hold 32 additional bytes
An actual ioctl(2,I2C_RDWR) call would be coded something like the following.
In this example, a MCP23017 register address of 0x15 is being written out to peripheral
address 0x20, followed by a read of 1 byte:
int fd;
struct i2c_rdwr_ioctl_data msgset;
struct i2c_msg iomsgs[2];
static unsigned char reg_addr[] = {0x15};
unsigned char rbuf[1];
int rc;
iomsgs[0].addr = 0x20; /
MCP23017−A
/
iomsgs[0].flags = 0; /
Write operation.
/
iomsgs[0].buf = reg_addr;
iomsgs[0].len = 1;
 
Search WWH ::




Custom Search