Use one DS1307 RTC with two Arduinos?

Im planning a clock project, detailed here:

http://arduino.cc/forum/index.php/topic,63928.0.html

Im tthinking that I may need 2 Arduinos to accomplish everything I want to do and wanted to see if it would be possible to use the same DS1307 for both Arduinos (since they will both need to know the time). My gut tells me no, but if not, what is my other option to allow them both have the same time? Use 2 separate DS1307's?

Have them both talk to the DS1307 via I2C - and add 3rd line (busy, with pullup resistor) between the Arduino's, each can test if it is high indicating I2C is not in use by the other, pull it low to indicate I2C is in use - make the time request, release when done. May have to also add Wire.begin & Wire.end and set A4/A5 as inputs to not interfere with the other arduino's use of the lines.

Code Concept:
digitalRead (busy) 
if free (high){
pinMode(busy, OUTPUT)
digitalWrite(busy, LOW)
set busy line low
wire.begin
do the time transfers
wire.end
pinMode(busy, input)
}

Depending on usage frequency, may get the occasional collision where both test for availability at the same time - if occurring too frequently, maybe add something simple like one arduino only does time updates on even seconds, the other on odd seconds.

Or use the line as softserial, one sends a message saying "i want the i2c bus", has to wait for the other to acknowledge before starting I2C transfers. The 2nd then must wait until it gets a message saying "i'm done" before it can send a message requesting the bus. Same concept, switch the pin between Rx & Tx between messages.

Collisions shouldn’t be a problem as the Wire library supports bus arbitration. If the second Arduino attempts to use the bus when the first is in use, Wire.endTransmission() should return a 4 indicating the bus is busy. The only problem you may have is between Wire.endTransmission() and Wire.requestFrom(). Since the Wire library does not support repeated starts, the bus will be released during this time and you could have a conflict. In that case you could check Wire.available() and see if it returns zero (which means no bytes received).

Nice! Thanks guys

wayneft: The only problem you may have is between Wire.endTransmission() and Wire.requestFrom().

This is a deal breaker and it's a shame repeated start is not supported in the wire library as it would be a modest, but very useful enhancement. Unfortunately there is also a hardware "bug" related to multimaster arbitration on the AtMega's that complicate matters further still. More info here:

http://www.robotroom.com/Atmel-AVR-TWI-I2C-Multi-Master-Problem.html

One solution would be to only read time from one Arduino (master) and push time to the other (slave).

BenF:

wayneft: The only problem you may have is between Wire.endTransmission() and Wire.requestFrom().

This is a deal breaker and it's a shame repeated start is not supported in the wire library as it would be a modest, but very useful enhancement. Unfortunately there is also a hardware "bug" related to multimaster arbitration on the AtMega's that complicate matters further still. More info here:

http://www.robotroom.com/Atmel-AVR-TWI-I2C-Multi-Master-Problem.html

One solution would be to only read time from one Arduino (master) and push time to the other (slave).

So your saying the above methods wouldnt work? I was thinking about one reading and relaying it to the other, but was worried that by the time I read the data from the 1st Arduino, sends it to the other, then the 2nd reads it, there will already be a small, but slightly noticeable time delay due to the amount of work already being done by both arduions.

The other option then is to go with the hardware arbitration I discussed, and add tri-state drivers ('244 type for example) on each arduino’s I2C outputs so the lines can be deactivated/released that way and the software can be left alone. Add pullup or pulldown resistor to the clock line so it ends at inactive state when not being driven.

Unfortunately there is also a hardware “bug” related to multimaster arbitration on the AtMega’s that complicate matters further still. More info here:

Atmel AVR TWI I2C Multimaster Issue - Robot Room

The only problem with this article is it doesn’t really apply to what the OP is doing. The example in that article shows him pushing the limits while “technically” adhering to the I2C standard. He’s using a multimaster system communicating between more multimaster AVR’s. Instead of using multiple masters to poll a slave device he is trying to reduce idle time by “telling” one device to send him data instead of “requesting” data from the device.

Forgive me if I’ve got the wrong end of the stick here, however I presume the RTC is using I2C to give time data to the arduino and the second (third, forth and so-on) is also connected via I2C - what is the problem? Surely you just request data from the RTC on both / all I2C connected Arduinos.

D6equj5: Forgive me if I've got the wrong end of the stick here, however I presume the RTC is using I2C to give time data to the arduino and the second (third, forth and so-on) is also connected via I2C - what is the problem? Surely you just request data from the RTC on both / all I2C connected Arduinos.

One would think so but I am finding this not to be the case (hence I found this thread), it seems to hang the Arduinos so the solution might be some hardware arbitration as suggested above. or another RTC that can handle multiple clients on the I2C?