1

我不久前开始学习 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);


        // ???
    }
}
4

1 回答 1

1

看起来您缺少 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

于 2016-02-19T20:54:43.213 回答