I'm willing to send 20 bytes at a time to Arduinos via I2C bus. I'm writing a C program (that will become a Daemon) that should achieve this, and thus I downloaded via Git the last wiringPi library, and it is working great when sending one byte of data to the Arduino :
wiringPiI2CWrite(0x77, 0x40);
Sends byte 0x40 to the slave device with address 0x77.
Then it comes to sending more than a byte. The following works great :
wiringPiI2CWriteReg8(0x77, 0x40, 0x01);
Sends bytes 0x40 then 0x01 to the slave device with address 0x77.
wiringPiI2CWriteReg16(0x77, 0x40, 0xFD01);
Sends bytes 0x40 then 0x01 then 0xFD to the slave device with address 0x77.
Now I went into the wiringPi source code, in wiringPiI2C.c, and based on what I saw, added a new function :
static int WriteBigData (int fd, uint8_t* b)
{
union i2c_smbus_data data;
int i;
for(i = 0; i < 19)
data.block[i] = b[i + 1];
return i2c_smbus_access(fd, I2C_SMBUS_WRITE, b[0], 19, &data);
}
Which would result in fact in :
static int WriteBigData (int fd, uint8_t* b)
{
union i2c_smbus_data data;
int i;
for(i = 0; i < 19)
data.block[i] = b[i + 1];
struct i2c_smbus_ioctl_data args ;
args.read_write = I2C_SMBUS_WRITE ;
args.command = b[0] ;
args.size = 19 ;
args.data = data ;
return ioctl (fd, I2C_SMBUS, &args) ;
}
But when executing, Arduino gets nothing. If I change size to 5, Arduino receives 3 bytes (Command + 2 first data bytes), if I change size to 8, Arduino receives 2 bytes (Command + first data byte). If I change size to 10, Arduino receives nothing.
So I'm wondering, may understand that Raspberry Pi's I2C is in fact the SMBus version of I2C ? Are there any limitations ? I also found that SMBus has limitation of 32 data bytes, which should be enough for my 20 bytes ...
Is this a limitation of the Linux (Raspbian) driver for I2C ?
Did anyone manage to send more than 2 data bytes over I2C from a Raspberry Pi ?
(Just to clarify if the detail is needed : I use a Model 1 Raspberry Pi B Rev. 2)