Changing the I2C bus rate on the BeagleBone Black

We noticed that our controller spent most of its time waiting on the IMU for values. The MPU6050 with the DMP code is capable of filling up its FIFO buffer at the rate of 200Hz. While such a high-speed might not be required for us, we were only doing around 40Hz.

One value every 25ms was unacceptable. Making the MPU6050 increase the rate at which it fills the buffer is simple. All you need to do is decrease the inv_set_fifo_rate parameter, which is the last value here. For example, if it is 0x05, then the rate is 200Hz / 5 = 40Hz, which was our original rate. Increasing the rate only caused the buffer to overflow quickly.

The issue was that the values were not being read off the buffer fast enough. It was not the controller program’s fault though. It was capable of way more than 40Hz. The speed of the I2C bus itself was to blame. The I2C bus clock frequency was set to 100KHz, so we decided to amp it up to 400KHz.

Here’s what we did (according to this post):

  1. Decompile the am335x-boneblack.dtb file with: dtc -I dtb -O dts -o am335x-boneblack.dts /boot/am335x-boneblack.dtb
  2. Edit the source file. Look for I2C definitions with a clock-frequency parameter. 0x61A80 is 400KHz and 0x186A0 is 100KHz. Change the second I2C (the one with clock-frequency of 100KHz) to 0x61a80.
  3. Recompile the source file with: dtc -I dts -O dtb -o am335x-boneblack.dtb am335x-boneblack.dts
  4. Make sure you have the proper file at /boot/dtbs/<kernel version>/am335x-boneblack.dtb (wrong extensions here won’t let your BBB boot).
  5. Reboot
  6. Check dmesg to verify that the I2C bus is now running at 400KHz.

With that change, we were able to run the MPU6050 with a FIFO rate of 100Hz (0x02).

After the change, the buffer always maintained about 1 packet ready in the buffer every loop and did not overflow.

For reference, we are using the console-only version of Debian Jessie with the 3.8 Linux kernel.

Leave a comment