1
votes

So I have 2 PCA9555 (16 channel digital I/O) chips connected to a small embedded device running Linux over i2c. The PCA9555 devices have 7 bit addresses 0100000 and 0100001.

When I power up the board, I run:

# modprobe i2c-i801
# modprobe i2c-dev
# i2cdetect -l
i2c-0  smbus    SMBus I801 adapter at 0500    SMBus adapter
# i2cdump -y -r 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
... (Same for every line)
70: -- -- -- -- -- -- --
# dmesg|tail
i801_smbus 0000:00:1f.3 Transaction timeout
... (For every '--' in i2cdump, one of these errors outputted)
i801_smbus 0000:00:1f.3 Transaction timeout

So then I tried to write a simple program to set all pins on the first PCA9555 chip to output high:

char *file;
unsigned char buf[3];
int addr, fd;

file = "/dev/i2c-0";
addr = 0x20; /* 0100000 */

if((fd = open(file, O_RDWR)) < 0){
  err(1, "open()");
}

if(ioctl(fd, I2C_SLAVE, addr) < 0){ /* also tried I2C_SLAVE_FORCE */
  err(1, "ioctl()");
}

/* Set all digital I/Os to output */
buf[0] = 6;
buf[1] = 0x00;
buf[2] = 0x00;

if(write(fd, buf, 3) != 3){
  err(1, "write() 1");
}

/* Set all outputs high */
buf[0] = 2;
buf[1] = 0xFF;
buf[2] = 0xFF;

if(write(fd, buf, 3) != 3){
  err(1, "write() 2");
}

return 0;

Running this returns:

# ./i2c
./i2c: write() 1: Operation not supported

So I don't really understand what I'm doing wrong. Assuming the hardware is wired correctly where do I go from here?

1
anything in dmesg from the i2c-core?Will Tate
Nope, nothing from i2c-core. Is i2c-core a module? Because I don't see it listed in /lib/modulesKristina

1 Answers

2
votes

The i801 adapter only supports SMBUS transfers, and the Linux i2c core doesn't support arbitrary write calls on SMBUS adapters. You'll need to use i2c_smbus_write_word_data. The kernel documentation doesn't go into detail on this, but that's the reason it recommends using SMBUS commands.