Wire.h with Mega2560 -> Uno Rev 3 problem


is there reason should not able use mega2560 master , uno rev3 slave using wire.h library , example sketches (master_writer on mega2560 , slave_receiver on uno).   wired ....

mega gnd -> uno gnd
mega sda (pin 20) -> uno sda (pin a4)
mega scl (pin 21) -> uno scl (pin a5)

seems hang on endtransmission on master no activity ever on slave

on mega (some serial output added debugging) ....
code: [select]
// wire master writer
// nicholas zambetti <http://www.zambetti.com>

// demonstrates use of wire library
// writes data i2c/twi slave device
// refer "wire slave receiver" example use this

// created 29 march 2006

// example code in public domain.


#include <wire.h>

void setup()
{
 wire.begin(); // join i2c bus (address optional master)
 serial.begin(9600);
}

byte x = 0;

void loop()
{
 serial.println("starting transmission");
 wire.begintransmission(4); // transmit device #4
 serial.println("write value");
 wire.write("x ");        // sends 5 bytes
 wire.write(x);              // sends 1 byte  
 serial.println("end transmission");
 wire.endtransmission();    // stop transmitting
 serial.println("increment value");
 x++;
 serial.println(x);
 delay(500);
}


on uno
code: [select]
// wire slave receiver
// nicholas zambetti <http://www.zambetti.com>

// demonstrates use of wire library
// receives data i2c/twi slave device
// refer "wire master writer" example use this

// created 29 march 2006

// example code in public domain.


#include <wire.h>

void setup()
{
 wire.begin(4);                // join i2c bus address #4
 wire.onreceive(receiveevent); // register event
 serial.begin(9600);  // start serial output
 serial.println("waiting...");
}

void loop()
{
 delay(100);
}

// function executes whenever data received master
// function registered event, see setup()
void receiveevent(int howmany)
{
 while(1 < wire.available()) // loop through last
 {
   char c = wire.read(); // receive byte character
   serial.print(c);         // print character
 }
 int x = wire.read();    // receive byte integer
 serial.println(x);         // print integer
}


i tried , without pullup on uno pins a4 , a5

worked fine me, no pull-up.

code: [select]
x 68
x 69
x 70
x 71
x 72
x 73
x 74
x 75
x 76
x 77
x 78
x 79
x 80
x 81
x 82
x 83
x 84
x 85
x 86
x 87
x 88
x 89
x 90
x 91
x 92
x 93


quote
is there reason should not able use mega2560 master , uno rev3 slave using wire.h library , example sketches (master_writer on mega2560 , slave_receiver on uno).


no, there isn't.

are both boards powered? should see green power led on both of them.


Arduino Forum > Using Arduino > Microcontrollers > Wire.h with Mega2560 -> Uno Rev 3 problem


arduino

Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial