3
\$\begingroup\$

I want to connect multiple ATmega328P chips to an I2C bus. Each unit is configured as slave but can send/broadcast messages as master too.

I have this currently working with Arduino Nano units and this works fine.

To reduce cost and more importantly space, I want to replace the Arduino Nano's with ATmega328P chips.

Now, my question is, do I need external crystals for these ATmega328P chips for this multi-master configuration?

I know I2C is not time-critical such as RS232 because the slave follows the clock-line of the master (right?).

The only concern I have is: will collision detection work properly if two ATmega units without crystal start transmitting data at the same moment?

\$\endgroup\$
2
  • 3
    \$\begingroup\$ Even if each chip had a crystal, you would still have to assume that they're asynchronous with respect to each other. The only way to achieve synchronous operation would be to feed them all the same clock from a shared crystal or oscillator. \$\endgroup\$
    – Dave Tweed
    Commented Feb 22, 2018 at 13:32
  • \$\begingroup\$ @DaveTweed you are right :-) \$\endgroup\$
    – mvermand
    Commented Feb 22, 2018 at 13:34

1 Answer 1

4
\$\begingroup\$

Multiple IIC devices do not need synchronized clocks. IIC is itself a synchronous protocol. During any one message, the master controls the SCL (clock) line. As long as the master lets the clock dwell long enough at each level for the slaves to have time to properly interpret SDA, there will be no problem.

So no, you don't need crystal-accuracy clocks for IIC communication.

\$\endgroup\$
5
  • \$\begingroup\$ If the master is running at xtal speed and the slaves are running off the internal oscillator, will they be able to keep up with the entire data packet transfer speed though? Presumably it will slow down the whole shebang too. \$\endgroup\$
    – Trevor_G
    Commented Feb 22, 2018 at 13:28
  • 1
    \$\begingroup\$ Note that the specific question is about collision detection in multi-master operation, which is asynchronous, and requires extra effort to implement correctly. \$\endgroup\$
    – Dave Tweed
    Commented Feb 22, 2018 at 13:36
  • \$\begingroup\$ @DaveTweed (based on your remark on my original question) since there is never a guarantee that two masters are clock-synced, shouldn't this be handled/built-in in the I2C protocol? I mean, I2C should be able to detect this even when clocks of two masters are out of sync. \$\endgroup\$
    – mvermand
    Commented Feb 22, 2018 at 13:42
  • \$\begingroup\$ @mvermand you really need to read up on the spec sheet of the device to see how it really handles I2C. Their particular implementation of the standard may or may not match your requirements when running off the internal oscillator. \$\endgroup\$
    – Trevor_G
    Commented Feb 22, 2018 at 13:47
  • 3
    \$\begingroup\$ I don't know the details for the ATmega328 specifically, but many microcontroller I2C implementations -- hardware OR software (bit-banging) -- do not include full support for multi-master operation with collision detection. Hence, the remark about "extra effort". \$\endgroup\$
    – Dave Tweed
    Commented Feb 22, 2018 at 13:53

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