I have posted an extension to the I2CDevice class that permits the use of different devices : http://www.fezzer.com/project/180/i2c-execute-extension/
Use is quite simple : you declare as many “Configuration” as you wish and you use them in the new Execute() method.
ConfigLCD = new I2CDevice.Configuration((ushort)(0xC6 >> 1), 91); // LCD device
ConfigEEprom = new I2CDevice.Configuration((ushort)(0xA0 >> 1), 400); // EEprom device
I2C = new I2CDevice(ConfigLCD); // Start with the LCD config by default
I2CDevice.I2CTransaction[] ActionsLCD = new I2CDevice.I2CTransaction[1]; // Create transaction
ActionsLCD[0] = I2CDevice.CreateWriteTransaction(new byte[2] { 0, (byte)19 }); // Backlight ON
I2C.Execute(ConfigLCD,ActionsLCD, 1000); // Note the use of the extension, here
EEprom_Write(10,231); // Write value 231 at address 10
Debug.Print("Read : " + EEprom_Read(10).ToString()); // Now read it back
ActionsLCD[0] = I2CDevice.CreateWriteTransaction(new byte[2] { 0, (byte)20 }); // Turn off LCD backlight
I2C.Execute(ActionsLCD, 1000); // Note the use of the original method, here. Possible since the I2C was created with the same configuration
public static void EEprom_Write(int Address, byte data) // EEprom write method
{
var xActions = new I2CDevice.I2CTransaction[1];
xActions[0] = I2CDevice.CreateWriteTransaction(new byte[] { (byte)(Address >> 8), (byte)(Address & 0xFF), data });
I2C.Execute(ConfigEEprom,xActions, 1000); // Using extension method
Thread.Sleep(5); // Mandatory after each Write transaction !!!
}
public static byte EEprom_Read(int Address) // EEprom Read method
{
var Data = new byte[1];
var xActions = new I2CDevice.I2CTransaction[1];
xActions[0] = I2CDevice.CreateWriteTransaction(new byte[] { (byte)(Address >> 8), (byte)(Address & 0xFF) });
Thread.Sleep(5); // Mandatory after each Write transaction !!!
I2C.Execute(ConfigEEprom, xActions, 1000); // Using extension method
xActions[0] = I2CDevice.CreateReadTransaction(Data);
I2C.Execute(ConfigEEprom, xActions, 1000); // Using extension method
return Data[0];
}
I hope you will find it useful.