i2c speed with wiringPi

Does anyone have experience with i2c on the raspberry pi? I’ve run a test to see how quickly i can process this function:

void PWM::setPWM(int channel, int on, int off)
{
                        wiringPiI2CWriteReg8(fd, LED0_ON_L+4*channel, on & 0xFF);
                        wiringPiI2CWriteReg8(fd, LED0_ON_H+4*channel, on >> 8);
                        wiringPiI2CWriteReg8(fd, LED0_OFF_L+4*channel, off & 0xFF);
                        wiringPiI2CWriteReg8(fd, LED0_OFF_H+4*channel, off >> 8);
                        
}

What i’m finding is that it takes around 2-3ms to send those bytes. Is that expected? It seems slow. Any hints on how to speed this up? The wiringPi documentation suggests using it’s GPIO tool to increase baudrate:

gpio load i2c 1000

but increasing that hasn’t changed anything. any tips would be helpful ( @jvcleave or @joshuajnoble i’m hoping you guys have a hint on this :slight_smile: ). thanks! I’ll post if i find anything.

My only experience was with SPI which was pretty quick

I haven’t tested this but that seems slower than i2c_smbus_access should be, though I don’t know much about what that does internally on the Pi. It’s probably pretty slow to test each of those but I wonder if there’s something in the i2c bus that you have on your Pi? I know there’s two and one is faster than the other.