1

I start learning Netduino short time ago. At now, I want to use it with MS5803 30BAR sensor. This Components communicate with I2C Protocol. I learned this protocol a little bit but not enough.

I wrote introducing of code. When I came main code, I did not do anything. My code is below.

Can anybody help about this matter? I will be so pleased :)

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);


        // ???
    }
}
Berk Altun
  • 27
  • 2
  • 8

1 Answers1

1

It looks like you're missing the I2C.Execute call. Without knowing anything about the device you're communicating with this will at least start the transmission.

Try to add this line after you create the read transaction.

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.

    }

Here an excellent document on netMF i2c: https://www.ghielectronics.com/docs/12/i2c

The device data sheet: http://www.amsys-sensor.eu/sheets/amsys.en.ms5803_30ba.pdf

GisMofx
  • 982
  • 9
  • 27
  • Thank you for your answer in advance @gismofx.I tried this solution in my project. I added "i2c.Execute(i2cTX[0],500);" line and added "if (execute_value == 0){} else{}" block diagram. My project always returns zero value at if-else block diagram and I can not communicate with Netduino Plus 2. in your opinion, what would be the problem ? – Berk Altun Feb 23 '16 at 15:58
  • 1
    @BerkAltun There are many things that can be wrong. Did you connect your device correctly? Are you using pull up resistors on the I2C bus? Are you using the correct I2c address?(the spec sheet says there are two possible addresses. Also, it looks like when you do a read transaction that you need 3 bytes returned. I've revised my answer slightly – GisMofx Feb 23 '16 at 17:01
  • I am very thankful to you for your searching and spending time. I tried lots of solution coupled with your suggestion and solution. My device connected correctly and I tested it with pull up circuit that embedded on. at Now, I think that I can use wrong i2c address. Maybe I can define wrongly device configuration. In addition this, I made a blink test with Netduino for to understand how it works. Blink Test worked successfully but this is not... :/ – Berk Altun Feb 24 '16 at 11:37
  • 1
    @BerkAltun Do you have an i2c/logic sniffer? You can monitor the SDA/SCL lines. if your neutrino sends out the address and you don't get a response, it's probably something with your device setup. Also, you may want to try to port an arduino driver as well. – GisMofx Feb 24 '16 at 19:55