user-1: I'm using I2C and the Arduino Library (Wire) to communicate between two Arduinos, and my code isn't working. It's supposed to read in an int from the slave, write a value to the slave, then read back that value. I'm expecting "0 4", but i keep getting "0 0". Does this mean that the slave isn't registering the write?
Master code:
#include <Wire.h>

void setup()
{
  Wire.begin();        
  Serial.begin(9600);  
  ffsis();
}

void ffsis()
{ 
  //request i
  Wire.requestFrom(2, 1);   
  int i = Wire.read(); 
  Serial.print(i); 

  //send n seed
  Wire.beginTransmission(2); 
  Wire.write(12);               
  Wire.endTransmission();   

  Serial.print(" ");

  //request n
  Wire.requestFrom(2, 1); 
  int n = Wire.read();
  Serial.print(n);
}

void loop()
{
  delay(100);
}

Slave code:
#include <Wire.h>

void setup()
{
  Wire.begin(2);                
  Wire.onRequest(requestEvents);
  Wire.onReceive(receiveEvents);
}

void loop(){}

int n = 0;

void requestEvents()
{
  Wire.write(n);
}

void receiveEvents(int howMany)
{  
  int n = wire.read();
}


user10794: 
int n = wire.read();

"Wire" should be capitalized.
Amplifying on Ken's reply, you have two variables called "n", and the global one should be declared volatile. Also, I2C deals in bytes, not ints, so preferably do this:
#include <Wire.h>

void setup()
{
  Wire.begin(2);                
  Wire.onRequest(requestEvents);
  Wire.onReceive(receiveEvents);
}

void loop(){}

volatile byte n = 0;

void requestEvents()
{
  Wire.write(n);
}

void receiveEvents(int howMany)
{  
  n = Wire.read();
}

In addition, the address 2 is a reserved address. 

Address 0 is reserved as a "broadcast" address, addresses 1 to 7 are reserved for other purposes, and addresses 120 to 127 are reserved for future use.

You should choose an address in the range 8 to 119.
Reference

I2C - Two-Wire Peripheral Interface - for Arduino
Official I2C specification


-1: <p>I'm using I2C and the Arduino Library (Wire) to communicate between two Arduinos, and my code isn't working. It's supposed to read in an int from the slave, write a value to the slave, then read back that value. I'm expecting "0 4", but i keep getting "0 0". Does this mean that the slave isn't registering the write?</p>

<p>Master code:</p>

<pre class="lang-cpp prettyprint-override"><code>#include &lt;Wire.h&gt;

void setup()
{
  Wire.begin();        
  Serial.begin(9600);  
  ffsis();
}

void ffsis()
{ 
  //request i
  Wire.requestFrom(2, 1);   
  int i = Wire.read(); 
  Serial.print(i); 

  //send n seed
  Wire.beginTransmission(2); 
  Wire.write(12);               
  Wire.endTransmission();   

  Serial.print(" ");

  //request n
  Wire.requestFrom(2, 1); 
  int n = Wire.read();
  Serial.print(n);
}

void loop()
{
  delay(100);
}
</code></pre>

<p>Slave code:</p>

<pre class="lang-cpp prettyprint-override"><code>#include &lt;Wire.h&gt;

void setup()
{
  Wire.begin(2);                
  Wire.onRequest(requestEvents);
  Wire.onReceive(receiveEvents);
}

void loop(){}

int n = 0;

void requestEvents()
{
  Wire.write(n);
}

void receiveEvents(int howMany)
{  
  int n = wire.read();
}
</code></pre>
 10794: <blockquote>
  <p>int n = wire.read();</p>
</blockquote>

<p>"Wire" should be capitalized.</p>

<p>Amplifying on Ken's reply, you have two variables called "n", <strong>and</strong> the global one should be declared <strong>volatile</strong>. Also, I<sup>2</sup>C deals in bytes, not ints, so preferably do this:</p>

<pre><code>#include &lt;Wire.h&gt;

void setup()
{
  Wire.begin(2);                
  Wire.onRequest(requestEvents);
  Wire.onReceive(receiveEvents);
}

void loop(){}

volatile byte n = 0;

void requestEvents()
{
  Wire.write(n);
}

void receiveEvents(int howMany)
{  
  n = Wire.read();
}
</code></pre>

<p>In addition, the address 2 is a <em>reserved address</em>. </p>

<blockquote>
  <p>Address 0 is reserved as a "broadcast" address, addresses 1 to 7 are reserved for other purposes, and addresses 120 to 127 are reserved for future use.</p>
</blockquote>

<p>You should choose an address in the range 8 to 119.</p>

<h3>Reference</h3>

<ul>
<li><a href="http://www.gammon.com.au/i2c" rel="nofollow">I2C - Two-Wire Peripheral Interface - for Arduino</a></li>
<li><a href="http://www.nxp.com/documents/user_manual/UM10204.pdf" rel="nofollow">Official I2C specification</a></li>
</ul>
