Configure Linux I2C Speed

让人想犯罪 __ 提交于 2019-12-13 15:37:25

问题


I am using I2C on the Snowball board, running at 400KHz by default and would like to reduce this to 100KHz.

I use the api defined in 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);
}

Does anyone know how I would go about changing the speed to standard mode.

Thanks


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/15337799/configure-linux-i2c-speed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!