Is there any reason that I should not be able to use the Mega2560 as the master and the Uno Rev3 as the slave using the Wire.h library and the example sketches (master_writer on the Mega2560 and slave_receiver on the Uno). They are wired ....
Mega GND -> Uno GND
Mega SDA (pin 20) -> Uno SDA (pin A4)
Mega SCL (pin 21) -> Uno SCL (pin A5)
Seems to hang on endTransmission on the master with no activity ever on the slave
On the Mega (some serial output added for debugging) ....
// Wire Master Writer
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Writes data to an I2C/TWI slave device
// Refer to the "Wire Slave Receiver" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600);
}
byte x = 0;
void loop()
{
Serial.println("starting transmission");
Wire.beginTransmission(4); // transmit to device #4
Serial.println("write value");
Wire.write("x is "); // sends five bytes
Wire.write(x); // sends one byte
Serial.println("end transmission");
Wire.endTransmission(); // stop transmitting
Serial.println("increment value");
x++;
Serial.println(x);
delay(500);
}
On the Uno
// Wire Slave Receiver
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
#include <Wire.h>
void setup()
{
Wire.begin(4); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
Serial.println("waiting...");
}
void loop()
{
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
while(1 < Wire.available()) // loop through all but the last
{
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
}
I tried it with and without a pullup on the Uno pins A4 and A5