Hardware Reference
In-Depth Information
To work with an I2C bus controller, your application must open the driver, made
available at the device node:
int fd;
fd = open("/dev/i2cāˆ’1",O_RDWR);
if ( fd < 0 ) {
perror("Opening /dev/i2cāˆ’1");
Note that the device node (/dev/i2c-1 ) is owned by root, so you'll need elevated
privileges to open it or have your program use setuid(2) .
ioctl(2,I2C_FUNC)
In I2C code, a check is normally performed to make sure that the driver has the right
support. The I2C_FUNC ioctl(2) call allows the calling program to query the I2C
capabilities. The capability flags returned are documented in Table 12-1 .
long funcs;
int rc;
rc = ioctl(fd,I2C_FUNCS,&funcs);
if ( rc < 0 ) {
perror("ioctl(2,I2C_FUNCS)");
abort();
}
/
Check that we have plain I2C support
/
āˆ—
āˆ—
assert(funcs & I2C_FUNC_I2C);
Table 12-1. I2C_FUNC bits
Bit Mask
Description
I2C_FUNC_I2C
Plain I2C is supported (non SMBus)
I2C_FUNC_10BIT_ADDR
Supports 10-bit addresses
I2C_FUNC_PROTOCOL_MANGLING
Supports:
I2C_M_IGNORE_NAK
I2C_M_REV_DIR_ADDR
I2C_M_NOSTART
I2C_M_NO_RD_ACK
The assert() macro used here checks that at least plain I2C support exists.
Otherwise, the program aborts.
 
 
Search WWH ::




Custom Search