raf1
August 10, 2022, 11:27am
1
I have a successful connection with Wire.h,
Uno as master and Mega as slave.
They both have a common structure, sending and receiving with
CommsStruct txData = {x, y};
Wire.beginTransmission(SLAVE_ADDR);
Wire.write((byte *)&txData, sizeof(txData));
Wire.endTransmission(true);
and
Wire.onReceive(receiveEvent);
Wire.readBytes((byte *)&rxData, sizeof(rxData));
I've noticed some issues when I power my cards a certain order, it doesn't work. Can I use something like
Wire.begin(0);
while (! Serial);
Wire.onReceive(receiveEvent);
In order to wait for a connexion before sending anything ?
while (! Serial); it waits for Serial, is there another method for I2C?
Please, give the example of the data item that you want to send from I2C-Master to I2C-Slave along with the postings of the sketches of both Master and Slave.
The thing is that you must always power up all boards at the same time. Then if you still get the problem include a two second delay at the start the setup function.
1 Like
You can keep roll calling the Slave until Master gets the ACK.
byte busStatus;
do
{
Wire.beginTransmission(slaveAddr); //avoid to use reserved address: 0x00 - 0x07
busStatus = Wire.endTransmission();
}
while(busStatus != 0);
should the slave wait for the master or the master wait for the slave?
BTW: why do you need an UNO as add on to the MEGA. Why not simply put anything on the MEGA?
Or indeed put everything on the MEGA.
If OP would post his sketches, the readers could reproduce the faults and then to devise a possible solution.
system
Closed
February 7, 2023, 1:32pm
8
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.