8

In short, what is the maximum bitrate that can be achieved writing to an I2C bus from a Raspberry Pi? Should it be the theoretical maximum of 100KB/s?

In more detail, I'm writing to an I2C bus from my Pi, sending messages to 10 PWM microcontrollers, each with 16 channels. (The model is Adafruit's PCA9685).

I'd like to be able to update these registers at something like 10-20Hz. Each channel has a 2-byte register, so naively I'd expect that to equate to 16 * 10 * 20 = 3.2KB/s. That's well within the protocol's limit of 100KB/s.

However, when I try to drive these microcontrollers from a Python script running on my Pi, I'm only able to achieve about 2Hz update frequency; I've profiled the code and most of the time spent is in the library that's actually calling out to the /dev/i2c* device.

I'm wondering if there's a hardware or driver restriction that limits the bitrate?

I'm using a 1st generation model B, Raspbian version 2015-02-16.

user7015
  • 183
  • 1
  • 1
  • 3

2 Answers2

8

The I2C clock bps (bits per second) can be set between 125 Mb/s and 3826 b/s (250Mhz core clock with even divider between 2 and 65536). BCM2835 ARM Peripherals pages 28-36.

In practice speeds higher than 30 Mb/s are unlikely to work.

The maximum bps I've heard of is 3.4 Mb/s but I don't remember any evidence being offered.

Bit rates of 400 kb/s (a sort of standard) and 1 Mb/s are common.

If you are not using device tree (unlikely with a recent kernel) then use

sudo modprobe i2c_bcm2708 baudrate=xxx

to set the speed.

With device tree use the following entries in /boot/config.txt

dtparam=i2c1=on
dtparam=i2c_arm_baudrate=xxx

With the Linux kernel SPI driver the limiting thoughput factor is the number of SPI calls you can make per second (roughly 20k). I don't know if the Linux kernel I2C driver has the same problem.

joan
  • 71,852
  • 5
  • 76
  • 108
1

Don't forget that line bitrate is isn't the same as throughput. In addition to the 16 data bits, you have to account for addressing, acknowledgement, and start/stop time on the wire. Conservatively, I'd divide by two for that.

Rob Starling
  • 111
  • 2