This is just to report my progress with getting a master Arduino to send query information to a slave Arduino, which then synchronously returns the specified data.
I'm using a master-slave Arduino pair (along with a real time clock, two 24LC1025 I2C EEPROMs, and a SRF08 range finder as part of a solar/boiler controller in my basement. All of this is networked via RS-232 (not USB, since it doesn't have the range) to my laboratory computer.
A thought occurred to me about the master and slave Atmegas in the solar controller and why I was having such a difficult time making a system allowing the master to synchronously request data from the slave. The documentation of "Wire," the library responsible for I2C communication in Atmegas, is spotty and example-free, and I've been able to find no examples online of anyone sending requests from a master for the return of specific data from a slave. Part of the problem I'd been having was my assumptions about how the Wire.onRequest (http://www.arduino.cc/en/Reference/WireOnRequest) handler works. I'd assumed that this handler could be used to retrieve data sent by the master (since other I2C devices seemed to work this way). But it turns out that this is not the case. To send data to a slave as part of a synchronous request followed by a returned result, the slave can only retrieve the request data using the onReceive (http://www.arduino.cc/en/Reference/WireOnReceive) method. On the slave side, this means that the onReceive handler has to take the data passed to it, process it however it needs to be processed, and put the results into global variables that can then be queried in the onRequest handler.
I stayed up late working on this problem but wasn't having much luck solving it. This morning I got up early and continued to work on it, trying a few things that occurred to me after I'd awaken (but before I'd gotten out bed). But no matter what I did, I couldn't make synchronous communication completely error-free, but I managed to come close by sending three copies of all the data being requested and testing to see if they all matched. Those as frustrated by this problem as I have been are welcome to download my code (http://asecular.com/ran/1103/release02.zip), which includes this master-slave synchronous communication (along with many other things).