Hello comunity,
i´m trying to control CMOS camera via I2C.
Execute command returned 1, but value of read buffer is 0 always (for example I2C.Read(0x02) ). Same for write action, execute code is o.k., but read return 0 together.
This is datasheet from my camera: http://www.pvelectronic.eu/out/media/tcm8240md_e150405_rev13.pdf
This is code I2C:
public class Camera
{
private static I2CDevice.Configuration I2CConfig;
private static I2CDevice I2C;
public Camera(byte address, int clockRateKHz)
{
I2CConfig = new I2CDevice.Configuration(address, clockRateKHz);
I2C = new I2CDevice(I2CConfig);
}
public void Write(byte address, byte data)
{
byte[] buffer = new byte[2];
buffer[0] = address;
buffer[1] = data;
var xActions = new I2CDevice.I2CTransaction[1];
xActions[0] = I2CDevice.CreateWriteTransaction(buffer);
if (I2C.Execute(xActions, 1000) == 0)
{
Debug.Print("Failed to perform I2C transaction");
}
else
{
Debug.Print("Success write");
}
Thread.Sleep(1000); // Mandatory after each Write transaction !!!
}
public byte Read(byte address)
{
byte[] RegisterValue = new byte[1];
I2CDevice.I2CTransaction[] xActions = new I2CDevice.I2CTransaction[2];
xActions[0] = I2CDevice.CreateWriteTransaction(new byte[] { address });
Thread.Sleep(1000); // Mandatory after each Write transaction !!!
xActions[1] = I2CDevice.CreateReadTransaction(RegisterValue);
int result = 0;
if ((result = I2C.Execute(xActions, 1000)) == 0)
{
Debug.Print("Failed to perform I2C transaction");
}
else
{
Debug.Print("Success read: " + RegisterValue[0].ToString() + " Result: " + result);
}
return RegisterValue[0];
}
}