Arduino Mega 2560 i2c lowest speed

Hello. Using the wire library you are able to set up your i2c bus speed. I would like to know if this is the only values that can be used and if they are valid for this specific board:

TWBR prescaler Frequency
12 1 400 kHz (the maximum supported frequency)
32 1 200 kHz
72 1 100 kHz (the default)
152 1 50 kHz
78 4 25 kHz
158 4 12.5 kHz

(from Nick's topic).

The second thing that I don't really understand is if this i2c frequency is similar to the uart one (rx tx serial) - for example connecting two devices with different baudrates will 100% fail transmitting or receiving one from / to another.

I'm asking this because I don't use much data on the bus and a low frequency will give me a better square wave signal. But in my system there is an i2c device (pcf8547) on which I have no control to change the frequency. Is it ok to lower the i2c frequency if the pcf8547 has a different default one?

Thanks in advance

I2C is a synchronous bus, UART works Asynchronously as the name suggests.

On an I2C bus the master generates the clock signal and dictates the maximum frequency. But the slave can stretch the low clock pulse if it cannot handle the stream at a higher frequency. This way you get the best from two worlds, sync and async :slight_smile:

I'm afraid I don't fully understand. Could you please send me some reference for a better understanding. Also, what happens for example if you have a communication slave to slave? Who dictates the clock? (thanks for the fast response).

e.g board no1:

  Wire.begin(addr1);
  Wire.setClock(1000L);
  Wire.onReceive(f1);

e.g board no2:

  Wire.begin(addr2);
  Wire.setClock(1000L);
  Wire.onReceive(f2);

Feel free to learn more about I2C :slight_smile:

Only a master can start a communication, slave-slave is not an option. If a device wants to send information, it does so in master mode. If a device wants to receive information, it does so in master mode. The addressed device reacts in slave mode, even if it also could behave as a master.

1 Like

Ok so therefore I can actually set up my speed as low as 1Hz?

If you want to slow down your bus to 1Hz then you can try that. The hardware will impose some hard limits, and the I2C spec imposes some soft limits.

Why would you ever slow down a communication that also would work at higher speed?

I'm having some issues and it might be some of the many i've read on this forum: the length of the wire (about 50cm) the fact that it;s a twisted wire, the pullups not well chosen, the baudrate. Therefore I want to reduce the baud rate, and one by one fix all the problems. Because I only send one byte at a time and my app is not time depended but consistency dependent, I am ready to trade speed for consistency.

Start trying to reduce the bus speed and find out what's really possible.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.