How do i test an I2C interface…i have my fez cobra 2 connected to a MCP23017 chip using i2c…how do i test this interface. This code is failing…
//create I2C object
//note that the netmf i2cdevice configuration requires a 7-bit address! It set the 8th R/W bit automatically.
I2CDevice.Configuration con =
new I2CDevice.Configuration(0x38, 400);
I2CDevice MyI2C = new I2CDevice(con);
// Create transactions
// We need 2 in this example, we are reading from the device
// First transaction is writing the "read command"
// Second transaction is reading the data
I2CDevice.I2CTransaction[] xActions =
new I2CDevice.I2CTransaction[2];
// create write buffer (we need one byte)
byte[] RegisterNum = new byte[1] { 2 };
xActions[0] = I2CDevice.CreateWriteTransaction(RegisterNum);
// create read buffer to read the register
byte[] RegisterValue = new byte[1];
xActions[1] = I2CDevice.CreateReadTransaction(RegisterValue);
// Now we access the I2C bus using a timeout of one second
// if the execute command returns zero, the transaction failed (this
// is a good check to make sure that you are communicating with the device correctly
// and dont have a wiring issue or other problem with the I2C device)
if (MyI2C.Execute(xActions, 1000) == 0)
{
Debug.Print("Failed to perform I2C transaction"); //reaches here
}
else
{
Debug.Print("Register value: " + RegisterValue[0].ToString());
}
}
}
}