2
\$\begingroup\$

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?

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

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.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ While many aspects of I2C are pretty clever, multi-master has some limitations. Among other things, if two masters start talking at once, arbitration failure won't be detected unless they try to say different things. Many bytes may be exchanged before that happens, and in some cases it may not happen at all. If two masters both try to send an "increment counter" to a device, each master may perceive (correctly) that the device received an "increment counter" command, but conclude (not necessarily correctly) that the counter will incremented on its behalf. \$\endgroup\$
    – supercat
    Nov 19, 2013 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.