I'm at a loss here. Any help would be greatly appreciated. I'm attempting to use a Maple leaf board (rev5) as an I2C master that interfaces with an Arduino (any board) acting as an I2C slave. I've swapped out a second Arduino for the Maple and the code seems to work. However, when I use the maple I can only successfully transfer once. By transfer once, I mean that the communication seems to stop after the first successful Wire.endTransmission(). Through troubleshooting here is what I've found so far.
1. When not connected to any device the return value of Wire.endTransmission(); is 0, which according to the maple documentation says the transfer was successful.
2. The maple must be rebooted to make another transfer.
3. rebooting the Arduino does not seem to make a difference.
4. After the first successful transfer from the maple the return value of Wire.endTransmission(); is = 2. That means that the slave is not sending an ACK upon its address being sent.
5. 5V pull ups on the Arduino did not do anything.
The only thing I can think is that there is some difference in the lower level protocol between the maple and the Arduino. Any ideas?
Here's the relevant codes:
Maple Master:
if(z_pos != z_pos_old){
SerialUSB.print(z_pos);
Wire.beginTransmission(5);
byte1 = z_pos & 255;
byte2 = z_pos >> 8;
Wire.send(byte1); // sends one byte
Wire.send(byte2); // sends one byte
rtnval = Wire.endTransmission(); // stop transmitting
SerialUSB.print(" return value = ");
SerialUSB.println(rtnval);
}
Arduino slave
#include <Wire.h>
int byte1, byte2;
void setup()
{
Wire.begin(5); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}
void loop()
{
delay(1000);
Serial.println("waiting");
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
int x = Wire.available();
Serial.print("available: ");
Serial.print(x);
byte1 = Wire.read(); // receive byte as an integer
byte2 = Wire.read();
byte2 = byte2 << 8;
byte2 = byte2 + byte1;
Serial.print (" position: ");
Serial.println(byte2);
x = Wire.available();
Serial.print("available: ");
Serial.print(x);
Wire.begin(5);
}