performancelinux-kerneli2c

Configure Linux I2C Speed


I am using I2C on the Snowball board, running at 400KHz by default.

I use the api defined in <linux/i2c.h> and configure as follows

m_fd = open(m_filename.c_str(), O_RDWR);

if (ioctl(m_fd, I2C_SLAVE_FORCE, m_addr) < 0) 
{
    throw I2cError(DeviceConfigFail);
}

How can I change the speed to standard mode (reduce clock rate to 100KHz)?


Solution

  • You can change the I2C SCL frequency in your driver's 'struct i2c_gpio_platform_data'.

        static struct i2c_gpio_platform_data xyz_i2c_gpio_data = {
        .sda_pin = GPIO_XYZ_SDA,
        .scl_pin = GPIO_XYZ_SCL,
        .udelay = 5, //@udelay: signal toggle delay. SCL frequency is (500 / udelay) kHz
        ....
    };
    

    Changing 'udelay' changes your 'xyz' i2c device's clock frequency.