我不久前开始学习Netduino。现在,我想将其与MS5803 30BAR传感器一起使用。该组件与I2C协议进行通信。我学到了这个协议,但是还不够。
我写了代码介绍。当我进入主代码时,我什么也没做。我的代码如下。
有人可以帮忙吗?我会很高兴的:)
public class Program
{
public static void Main()
{
// Configuration of MS5803 30BA
I2CDevice i2c = new I2CDevice(new I2CDevice.Configuration(0x76>>1, 400));
byte[] read = new byte[1];
I2CDevice.I2CTransaction[] i2cTx = new I2CDevice.I2CTransaction[1];
i2cTx[0] = I2CDevice.CreateReadTransaction(read);
// ???
}
}
好像您缺少I2C.Execute调用。在不了解与之通信的设备的任何信息的情况下,至少会开始传输。
创建读取事务后,尝试添加此行。
i2c.Execute(i2cTX[0],500);
byte[] returnByte = new byte[3];
var readX = new I2CDevice.I2CTransaction[] {I2CDevice.CreateReadTransaction(returnByte) };
int executed = 0;
I2CDevice i2c = new I2CDevice(new I2CDevice.Configuration(0x76, 400));
executed = i2c.Execute(readX, 400);
if (executed == 0)
{
//Debug.Print("Read FAIL!");
}
else
{
//Debug.Print("Read SUCCESS!");
}
//throw new Exception("I2C transaction failed");
//you will need to do some bit shifting with the readX array to get your values.
}
这是有关netMF i2c的出色文档:https ://www.ghielectronics.com/docs/12/i2c
设备数据表:http : //www.amsys-sensor.eu/sheets/amsys.en.ms5803_30ba.pdf
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句