How to use nrf9160 i2c1?

Hi:

How to use nrf9160 i2c1?

nrf9160dk_nrf9160_ns.overlay

&pinctrl {
	i2c2_default: i2c2_default {
		group1 {
			psels = <NRF_PSEL(TWIM_SDA, 0, 13)>,
				<NRF_PSEL(TWIM_SCL, 0, 14)>;
		};
	};

	i2c2_sleep: i2c2_sleep {
		group1 {
			psels = <NRF_PSEL(TWIM_SDA, 0, 13)>,
				<NRF_PSEL(TWIM_SCL, 0, 14)>;
			low-power-enable;
		};
	};
	i2c1_default: i2c1_default {
		group1 {
			psels = <NRF_PSEL(TWIM_SDA, 0, 19)>,
				<NRF_PSEL(TWIM_SCL, 0, 18)>;
		};
	};

	i2c1_sleep: i2c1_sleep {
		group1 {
			psels = <NRF_PSEL(TWIM_SDA, 0, 19)>,
				<NRF_PSEL(TWIM_SCL, 0, 18)>;
			low-power-enable;
		};
	};	
};

I2C1 cannot be used when I configure it like this.But i2c2 can be used.

  • Hello,

    That's because I2C1 is by default disabled on nRF9160, while I2C2 is enabled by default.

    If you search for i2c1 in ncs/zephyr/dts/arm/nordic/nrf9160_common.dtsi you will find the following snippet:

    i2c1: i2c@9000 {
    	/*
    	 * This i2c node can be either TWIM or TWIS, for the user to pick:
    	 * compatible = "nordic,nrf-twim" or
    	 *              "nordic,nrf-twis".
    	 */
    	compatible = "nordic,nrf-twim";
    	#address-cells = <1>;
    	#size-cells = <0>;
    	reg = <0x9000 0x1000>;
    	clock-frequency = <I2C_BITRATE_STANDARD>;
    	interrupts = <9 NRF_DEFAULT_IRQ_PRIORITY>;
    	status = "disabled";
    };

    Where it says status = "disabled";

    To enable it you have to add the following to your overlay file:

    &i2c1 {
        status = "okay";
    };

    Best regards,

    Michal

Related