2

I would like to change i2c bus frequency in order to allow for slightly longer cables.

I am using python-smbus package and it does work very well, however, I am unable to find how to set the bus frequency.

I have looked through the docs but was unable to find anything even remotely related to setting bus parameters.

Is that anything that could be done in python or do I need something lower level?

I am using Raspberry PI, which is an ARM architecture.

4 Answers 4

3

On the Raspberry Pi with the latest Jessie image, you can use this to check the current I2C frequency:
sudo cat /sys/module/i2c_bcm2708/parameters/baudrate.

To change the frequency, you can add/change this parameter:

dtparam=i2c_baudrate=50000

(replace 50000 with the desired frequency) in:

/boot/config.txt

and reboot to change the frequency.

1
  • 1
    With Jessie on a RPi3, there is no /sys/module/i2c_bcm2708/parameters/baudrate, only /sys/module/i2c_bcm2835/parameters/debug.
    – davidA
    Dec 2, 2017 at 7:16
0

You'll have to do something at a lower level. Typically this stuff is setup by the board file in the kernel. I didn't see anything specifically being done with the i2c, other than allocating the resources, so it's likely just using the default clock divisor. If you look on page 28 of the datasheet, you'll see that the default is 0x5dc. You'll need to setup that register with a different value (probably bigger) to cope with the longer cables.

0

I have now spent some significant amount of time researching all the options. It turns out that there are indeed low lever registers as specified in the other post, however, the Raspberry-Pi's driver resets their value on its every use, making any modification to them pretty much useless. The solution is to either write a custom i2c driver or simply wait for an updated version.

Some lower-level information could be found in byval forum.

0

For anyone still interested:

It is not enough to set a higher bus speed. The I2C protocol changes if not the lowest, 100kHz is used. The slave address must be sent twice: first to inform the slave of the higher speed transaction, then for the slave to be able to receive in that higher speed.

The SMBUS protocol has a fixed bus frequency of 100kHz.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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