Software I2C, How do I know it's working?

I have this code

        public static void Main() {
            Debug.Print("Bytes Free: " + Debug.GC(true));
            SoftwareI2CBus _i2c = new SoftwareI2CBus((Cpu.Pin)FEZCerbuino.Pin.Gadgeteer.Socket3.Pin7, (Cpu.Pin)FEZCerbuino.Pin.Gadgeteer.Socket3.Pin9);
            byte[] _out = new byte[] { 0x2 };
            byte[] _in = new byte[4];
            int _numWrite, _numRead;
            while (true) {
                _i2c.WriteRead(0x48, _out, 0, _out.Length, _in, 0, _in.Length, out _numWrite, out _numRead);


And I am trying to communicate with this device [url][/url]. I keep getting back 128,0,255,255 in my IN byte array. What does that 128 mean?

Should be in Datasheet. Did you check there?

I did; however i can’t make heads or tails of it. So much for that.

The data is correct if I am reading the datasheet correctly and you are requesting register 2.

You are requesting the Lo_thresh register contents and this sends back 2 bytes. You are asking for 4 so the last 2 will be HIGH on the bus, hence the 255, 255.

The 128 in the first byte signifies bit 7 is set and when you combine the 2 bytes into 1, you get 0x8000 which is the default for this register.

From the datasheet on page 20

Lo_thresh default = 8000h.

Try reading the Hi_thresh and you should get 0x7FFF instead.

This will confirm that the I2C is working fine. You are then ready to rock and roll with the reading of ADC etc.


So it was correct. Rats.

Well experience is a good teacher. Thanks Much!