How exactly do you enable i2c0, i2c1 or i2c3 on the nrf9160 dk?

How do you enable any of the i2c peripherals on the nRF9160 dk boards?

I tried changing the device overlay to the code below:

&i2c0 {

    status = "okay";
    compatible = "nordic,nrf-twim";
    sda-pin = < 12 >;
    scl-pin = < 11 >;
    clock-frequency = <I2C_BITRATE_STANDARD>;
};
But I get this error: static assertion failed: "/soc/peripheral@50000000/i2c@8000 has legacy *-pin properties defined although PINCTRL is enabled"
I've seen older posts which change the pinctrl, which looks like something below:
&pinctrl {
    i2c0_default_alt: i2c0_default_alt {
       group1 {
          psels = <NRF_PSEL(TWIM_SDA, 0, 12)>,
                  <NRF_PSEL(TWIM_SCL, 0, 11)>;
       };
    };
    i2c0_sleep_alt: i2c0_sleep_alt {
       group1 {
          psels = <NRF_PSEL(TWIM_SDA, 0, 12)>,
                  <NRF_PSEL(TWIM_SCL, 0, 11)>;
          low-power-enable;
       };
    };
 };

&i2c0 {
    status = "okay";
    compatible = "nordic,nrf-twim";
    pinctrl-0 = <&i2c0_default_alt>;
    pinctrl-1 = <&i2c0_sleep_alt>;
    clock-frequency = <I2C_BITRATE_STANDARD>;  
};
But this gives me this error: 'PINCTRL_STATE_DT_N_S_soc_S_peripheral_50000000_S_i2c_8000_PINCTRL_IDX_0_UPPER_TOKEN' undeclared here (not in a function); did you mean 'DT_N_S_soc_S_peripheral_50000000_S_i2c_a000_PINCTRL_IDX_0_UPPER_TOKEN'?
I just want to be able to use another i2c port. Does anyone know how to configure this? For reference i2c2 is already enabled, which is what I've been using so far.
  • Hello Jerome, 

    How do you enable any of the i2c peripherals on the nRF9160 dk boards?

    You can check all default configured peripherals in ../<your_application_root/<your_build_folder>/zephyr/zephyr.dts. On the nRF9160 DK, &i2c2 is enabled by default. 

    i2c2: arduino_i2c: i2c@a000 {
    	compatible = "nordic,nrf-twim";
    	#address-cells = < 0x1 >;
    	#size-cells = < 0x0 >;
    	reg = < 0xa000 0x1000 >;
    	clock-frequency = < 0x186a0 >;
    	interrupts = < 0xa 0x1 >;
    	status = "okay";
    	label = "I2C_2";
    	pinctrl-0 = < &i2c2_default >;
    	pinctrl-1 = < &i2c2_sleep >;
    	pinctrl-names = "default", "sleep";
    };

    Due to memory instantiation, you have to disable &uart0 to be able to enable &i2c0 and &spi3 to be able to enable &i2c3 respectively. 

    Additionally, 

    CONFIG_I2C=y

    needs to be set in your prj.conf. 

    Unless you are aware of the fact that you have to switch over to RTT if logging is needed, disabling &uart0 is not recommended from my side. 

    Regards, 

    Markus 

Related