I2C Question

This is just a question on how I2C works. I have one Arduino as the master, and it runs the main code. But I have a second Arduino that is the slave and has a motor shield. So my question is if lets say in the main code I get to a line that uses a motor function on the slave and I send a command to execute the motor movement on the slave, will the master wait for the slave to finish its loop or will it send the command and just continue along? and if it continues along can I add a command to listen for a reply from the slave before it continues?

Good question, it can be important to know how the Wire library works.

Sending data to Slave:
Wire.beginTransmission : This makes the software ready
Wire.write : Write one or more bytes to the software buffer
Wire.endTransmission : transmit data and wait for acknowledge from slave.

I'm not sure if the asknowledge is for the address only, or if the Wire.endTransmission waits for all the data to be transmitted. I think it waits until all the data has been transmitted.

Reading data from Slave:
Wire.requestFrom : Request data and wait until all the data has been received.

The Wire.requestFrom returns the number of the received bytes.

The Slave doesn't have to wait, it sends or receives all the data in a single call to an interrupt handler
It is not possible to transmit and receive data at the same time. You have to transmit the command, and after that request some data from the Slave.

The Slave should have short interrupt handlers for the I2C data. Often global variables are used that are written or read in those interrupt handlers, and the variables are used in the loop().

Thank you that helps. I will have to play around with it to see how I can set this up.

I am doing exactly this already. The master does not wait for a response. I use a digital out on the slave connected to a digital in on the master to indicate that a slave message is waiting. I also hooked to an led soon can visualize the communication or see if the master or slave has hung up. Periodically the master samples the message waiting line and then calls the read from wire routine. I have set up a message protocol with a integer identifier, and a long parameter so all my messages are fixed length and quite short. It works great.

I have also added a interrupt wire to the SDA and SCL. The Master checks it by polling, so it is not a real interrupt. The interrupt signal is open-collector and a few Slaves can make it low. So the Master has to check those Slaves to see which one has data ready.
I should have made multiple interrupt signals, one for each Slave, but I couldn't change the hardware anymore.