7

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.

  • Just a comment, I'm pretty sure you should be able to get a greater bitrate through SPI. Also, the microcontroller should be the limiter on the I2C... not the raspberry pi. – user9702 Apr 8 '15 at 5:53
  • You should try strace on that; if you are using the smbus library this may be stretching the bounds of what it is intended for (what you are doing sounds more like it would require a kernel driver of its own, or something that bypasses the kernel via mmap, such as the wiringPi stuff). The generic smbus library would be making a system call for every write. – goldilocks Apr 8 '15 at 9:32
  • 1
    The I2C bus rate is specified in bits per second (bps). The default Pi I2C speed is 100kbps NOT 100kBps. – joan Apr 8 '15 at 9:44
6

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.

  • 2
    I've not seen so much I2c devices that are capable of handling speeds of 1Mbps... 400kHz, though, is more common... The fastest speed currently specified is "ultra fast mode", being 5Mbps. But that's only uni-directional. 3.4Mbps, known as high speed mode, is still bidirectional. See this link: nxp.com/documents/user_manual/UM10204.pdf – GeertVc Apr 10 '15 at 6:06
  • 1
    A useful link. I seem to remember that the real speed killer is the time taken for the lines to rise to logic 1 through the pull-up resistor. – joan Apr 10 '15 at 7:58
  • 1
    Yes, you're right. The pull-up resistors in combination with the capacity of the lines are in fact the limiting factor. – GeertVc Apr 11 '15 at 15:06
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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