Hi all,
I have been working on a driver for the Silicon Labs Si7005 Digital I2C Humidity & Temperature Sensor and have been getting some odd behaviour.
I'm using a Seeedstudio Grove - Temperature & Humidity Sensor (Si7005 based I2C) which looked like a reasonable alternative to a Grove Temperature & Humidity Sensor Pro (DHT22 based bit bashed) which can be bit problematic on the Netduino platform.
I now have a working driver for the Si7005 but the first time I read from/write to the device it always fails, after that it always works as expected. (I had to get a working driver as I have 30+ of them for a project )
Simplest possible example code below
......
using (I2CDevice device = new I2CDevice(new I2CDevice.Configuration(DeviceId, ClockRateKHz)))
{
// Read the device ID first time
Debug.Print("First read always fails");
byte[] writeBuffer1 = { REG_ID };
byte[] readBuffer1 = new byte[1];
// check that sensor connected
I2CDevice.I2CTransaction[] action1 = new I2CDevice.I2CTransaction[]
{
I2CDevice.CreateWriteTransaction(writeBuffer1),
I2CDevice.CreateReadTransaction(readBuffer1)
};
int length1 = device.Execute(action1, TransactionTimeoutMilliseconds);
Debug.Print("Byte count " + length1.ToString());
foreach (byte Byte in readBuffer1)
{
Debug.Print(Byte.ToString());
}
// Read the device ID a second time
Debug.Print("Second read always works");
byte[] writeBuffer2 = { REG_ID };
byte[] readBuffer2 = new byte[1];
I2CDevice.I2CTransaction[] action2 = new I2CDevice.I2CTransaction[]
{
I2CDevice.CreateWriteTransaction(writeBuffer2),
I2CDevice.CreateReadTransaction(readBuffer2)
};
int length2 = device.Execute(action2, TransactionTimeoutMilliseconds);
Debug.Print("Byte count " + length2.ToString());
foreach (byte Byte in readBuffer2)
{
Debug.Print(Byte.ToString());
}
...............
I have tried strobing the SDA line on startup with
using (OutputPort i2cPort = new OutputPort(Pins.GPIO_PIN_SDA, true))
{
i2cPort.Write(false);
}
But it made no difference.
Does anyone have any suggestions/thoughts?
Thanks
@KiwiBryn
blog.devmobile.co.nz