user1400716
user1400716

Reputation: 1136

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)?

Upvotes: 2

Views: 21312

Answers (2)

Narain
Narain

Reputation: 5451

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.

Upvotes: 1

Keshava GN
Keshava GN

Reputation: 4265

You should change the I2C Frequency in driver source file of the corresponding peripheral (ie: Slave device to which you are communicating through I2C. Example: EEPROM/Camera etc.)

You may find some macro defined in that driver source code... like:

#define EEPROM_I2C_FREQ 400000 //400KHz

Change it to:

#define EEPROM_I2C_FREQ 100000 //100KHz

Only for that corresponding driver, I2C frequency/speed will be changed.

Upvotes: 0

Related Questions