Design, Build, Test, Iterate

Faster I2C on the Arduino

The Arduino I2C library is configured, by default, to 100 kHz frequency I2C. We can increase this to the more modern 400 kHz by changing TWI_FREQ in the Arduino I2C library from 100000L to 400000L.

It used to take around 1500 microseconds each for my Seeeduino Mega to read six bytes off the accelerometer and gyro. I cut that down to around 1000 microseconds each with this change. (But that’s still too long for my liking!)



3 Comments

  1. [...] is too slow. I was able to increase the frequency to 185 Hz by spreading out the telemetry loop and increasing the I2C clock frequency from 100 kHz to 400 kHz, but the faster control loop isn’t going to be any good if the ESCs [...]

  2. [...] it takes the microcontroller about 2 milliseconds in total to read the gyro and accelerometer. I have complained before that this is too slow. I have also noticed in the past that communication would stop randomly, [...]

  3. [...] and the internal pull-up resistor of the ATmega was probably good enough for that speed. However, I modified the code to run I2C at 400 kHz and did not realize I had to make hardware modifications, as [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>