How can I set a non-standard speed for the I2C bus using the Zephyr?

Hi,

Using the Zephyr how can I set a TWI module clock frequency different from the standard speeds?

With nRF SDK I was able to do this by setting "frequency = 0x00290000UL".

void ext_twi_init(void)
{
    ret_code_t err_code;

    const nrf_drv_twi_config_t twi_config = {
       .scl                = EXT_SCL_PIN,
       .sda                = EXT_SDA_PIN,
       .frequency          = 0x00290000UL,      // = 10Kbit/s. <------------
       .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
       .clear_bus_init     = false
    };

    err_code = nrf_drv_twi_init(&m_ext_twi, &twi_config, NULL, NULL);
    APP_ERROR_CHECK(err_code);

    nrf_drv_twi_enable(&m_ext_twi);
}

Using the Zephyr instead I only have the following speeds defined in the i2c.h file:

#define I2C_BITRATE_STANDARD	100000	/* 100 Kbit/s */
#define I2C_BITRATE_FAST	400000	/* 400 Kbit/s */
#define I2C_BITRATE_FAST_PLUS	1000000 /* 1 Mbit/s */
#define I2C_BITRATE_HIGH	3400000	/* 3.4 Mbit/s */
#define I2C_BITRATE_ULTRA	5000000 /* 5 Mbit/s */

If I define a new speed in the i2c.h file, for example:

#define I2C_BITRATE_10KHZ 10000

&i2c0 {
	status = "okay";
	pinctrl-0 = <&i2c0_default>;
	pinctrl-names = "default";
	clock-frequency = <I2C_BITRATE_10KHZ>;
};

It gives me the following error:

static assertion failed: "Wrong I2C 0 frequency setting in dts"

Can anyone help me define a non-standard speed?

Thank you.

Related