Electronic – arduino – Multiple masters for i2c device

arduinoatmegaattinyi2crtc

I have a DS1307 RTC chip that I want to interface with multiple masters.
One, an ATMega chip, will only ever really need to pull time data from the chip and the other (probably just an ATTiny) will be there solely for the purpose of receiving wireless time updates and updating the time on the RTC. I realize that I could just build in this wireless update functionality to the ATMega chip, but I'm trying to work on a modular RTC board that, as far as the ATMega is concerned, is exactly the same as any other similar RTC like the DS1307 or the DS3231 (Chronodot).

Question is, can I just wire it all to the same two i2c bus lines and communicate with the RTC from BOTH chips? If so, do I need to do anything to ensure that both are not trying at the same time? I assume that, since i2c already supports multiple slave devices that this should generally be handled for me. But, in general, should this work. I'm ok with the ATMega trying to get the time and having to wait if the RTC is being updated. Which would be rare anyways, maybe every hour at most.

Thoughts?

Best Answer

You are correct. Multimaster must be handled by you. i2c Multi-Master description. The Main thing for a proper multimaster system is that it understands arbitration logic, and can tell when the system is busy. The first is more difficult than the latter. To tell when the system is busy, each multi-master must be able to check for a start condition, and wait for a stop condition before trying to use the bus. Arbitration logic is for situations where both masters might try to take over the bus at the same time.

But there are other ways to do it, outside of the i2c standard. You can use an extra pin each of the masters, and make a simple busy signal standard.

Check if Busy pin is On.

If Off, set a status variable to On and Busy pin to On, then talk to the rtc. When done, set variable and pin to Off.

If On, check if status variable is On (Did "I" set status variable to On?). If no, loop until busy pin is Off.