I need help with I2C

I’ve never worked with I2C before, so this is probably something very basic and stupid, but I can’t figure out what I’m doing wrong.

I’m running this code on my FEZ Panda:

public static void Main()
{
    //-- SENDER --

    //create I2C object
    I2CDevice.Configuration con = new I2CDevice.Configuration(0x38, 400);
    I2CDevice MyI2C = new I2CDevice(con);

    //create transactions
    I2CDevice.I2CTransaction[] xActions = new I2CDevice.I2CTransaction[1];

    // create write buffer (we need one byte)
    byte[] RegisterNum = new byte[1] { 2 };
    xActions[0] = I2CDevice.CreateWriteTransaction(RegisterNum);

    while (true)
    {
        // Now we access the I2C bus and timeout in one second 
        // if no response
        MyI2C.Execute(xActions, 1000);
        Debug.Print("Sending: " + RegisterNum[0].ToString());
        Thread.Sleep(1000);
    }
}

I’m running this code on my FEZ Domino:

public static void Main()
{
    //-- RECEIVER --

    //create I2C object
    I2CDevice.Configuration con = new I2CDevice.Configuration(0x38, 400);
    I2CDevice MyI2C = new I2CDevice(con);

    //create transactions
    I2CDevice.I2CTransaction[] xActions = new I2CDevice.I2CTransaction[1];

    // create read buffer to read the register
    byte[] RegisterValue = new byte[1];
    xActions[0] = I2CDevice.CreateReadTransaction(RegisterValue);

    while (true)
    {
        // Now we access the I2C bus and timeout in one second 
        // if no response
        MyI2C.Execute(xActions, 1000);
        Debug.Print("Received: " + RegisterValue[0].ToString());
        Thread.Sleep(1000);
    }
}

Panda says it’s sending twos, Domino says it’s receiving zeroes.

Here are my wiring:
Panda Domino
A4 A4
A5 A5
GND GND

I also have a 1.2K pullup to 3.3V on A4 and A5.
Could someone point out my mistake? Thanks!

I2C work on mater to slave(s) and not master to master. You can NOT connect 2 FEZes using I2C because both are bus masters

[quote]You can NOT connect 2 FEZes using I2C because both are bus masters
[/quote]
Sames goes for SPI, right? That leaves UART, the software I2C you posted in another thread… maybe CAN?

I knew it was something simple. Thanks Gus.

Wire library on Arduino supports both master and slave.
[url]http://arduino.cc/en/Reference/WireBegin[/url]

What prevents FEZ from doing the same?

Hari, look here: [url]http://www.tinyclr.com/forum/1/1647/[/url]

Why not use uart to connect 2 devices

Indeed, thats what I did and it works perfectly. If you want I will post the code I used to accomplish UART communication between a Panda and a Cobra.

Even better, a project showing how can someone make interaction between 2 FEZes :smiley:

I’m on it Gus