This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

NCS 1.9.99: How to set sda and scl pins for I2C

With an earlier version of NCS  I could set the sda and scl pins using an overlay file:

boards/nrf52840dk_nrf52840.overlay:

&i2c0 {
    status = "okay";
    compatible = "nordic,nrf-twim";
    sda-pin = < 45 >;
    scl-pin = < 47 >;
    sht3xd@45 {
		compatible = "sensirion,sht3xd";
		reg = <0x45>;
		label = "SHT3XD";
		alert-gpios = <&gpio1 10 GPIO_ACTIVE_HIGH>;
	};
};

With NCS 1.9.99 I get this error:

In file included from /home/k/ncs1999/zephyr/include/zephyr/toolchain.h:50,
                 from /home/k/ncs1999/zephyr/include/zephyr/init.h:10,
                 from /home/k/ncs1999/zephyr/include/zephyr/device.h:29,
                 from /home/k/ncs1999/zephyr/include/zephyr/drivers/i2c.h:23,
                 from /home/k/ncs1999/zephyr/drivers/i2c/i2c_nrfx_twim.c:8:
/home/k/ncs1999/zephyr/include/zephyr/toolchain/gcc.h:77:36: error: static assertion failed: "/soc/i2c@40003000 has legacy *-pin properties defined although PINCTRL is enabled"
   77 | #define BUILD_ASSERT(EXPR, MSG...) _Static_assert(EXPR, "" MSG)
      |                                    ^~~~~~~~~~~~~~
/home/k/ncs1999/zephyr/soc/arm/nordic_nrf/common/./soc_nrf_common.h:229:2: note: in expansion of macro 'BUILD_ASSERT'
  229 |  BUILD_ASSERT(!IS_ENABLED(CONFIG_PINCTRL) ||   \
      |  ^~~~~~~~~~~~
/home/k/ncs1999/zephyr/drivers/i2c/i2c_nrfx_twim.c:396:2: note: in expansion of macro 'NRF_DT_CHECK_PIN_ASSIGNMENTS'
  396 |  NRF_DT_CHECK_PIN_ASSIGNMENTS(I2C(idx), 1, scl_pin, sda_pin);        \
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/k/ncs1999/zephyr/drivers/i2c/i2c_nrfx_twim.c:448:1: note: in expansion of macro 'I2C_NRFX_TWIM_DEVICE'
  448 | I2C_NRFX_TWIM_DEVICE(0);
      | ^~~~~~~~~~~~~~~~~~~~
ninja: build stopped: subcommand failed.

How do I change the sda and scl pin assignments using NCS 1.9.99?

Thanks,

Jan Erik

Parents
  • Thanks,  Øivind.  I followed your suggestion of putting the pinctrl-* fields outside of the sht3xd block.  I also needed to specify the pin numbers using the new convention instead of the old. In the old system port 1, pin 13  was pin 45 and port 1, pin 15 was pin 47 (pin was specified as pin number plus 0 for port 0 or plus 32 for port 1). Under pinctrl, the port and pin are separated so port 1, pin 13 should be specified as <NRF_PSEL(TWIM_SDA, 1, 13)>  not  <NRF_PSEL(TWIM_SDA, 0, 45)>.  You know all this, I'm just elaborating for someone else who might stumble upon this thread.

    The v1.9.99 SHT3XD sample now builds and runs correctly for me on the nrf52840dk with my target pins.

    I added nrf52840dk_nrf52840.overlay to the boards directory:

    &pinctrl {
       i2c0_default_alt: i2c0_default_alt {
          group1 {
             psels = <NRF_PSEL(TWIM_SDA, 1, 13)>,
                     <NRF_PSEL(TWIM_SCL, 1, 15)>;
          };
       };
       i2c0_sleep_alt: i2c0_sleep_alt {
          group1 {
             psels = <NRF_PSEL(TWIM_SDA, 1, 13)>,
                     <NRF_PSEL(TWIM_SCL, 1, 15)>;
             low-power-enable;
          };
       };
    };
    
    &i2c0 {
        pinctrl-0 = <&i2c0_default_alt>;
        pinctrl-1 = <&i2c0_sleep_alt>;
        pinctrl-names = "default", "sleep";
    	sht3xd: sht3xd@45 {
            status = "okay";
    		compatible = "sensirion,sht3xd";
    		reg = <0x45>;
    		label = "SHT3XD";
    		alert-gpios = <&gpio1 10 GPIO_ACTIVE_HIGH>;
    	};
    };
    

    I also made two changes to the main.c file:

    14d13
    < #define SHT3XD DT_NODELABEL(sht3xd)
    29c28
    < 	const struct device *dev = DEVICE_DT_GET(SHT3XD);
    ---
    > 	const struct device *dev = device_get_binding("SHT3XD");

Reply
  • Thanks,  Øivind.  I followed your suggestion of putting the pinctrl-* fields outside of the sht3xd block.  I also needed to specify the pin numbers using the new convention instead of the old. In the old system port 1, pin 13  was pin 45 and port 1, pin 15 was pin 47 (pin was specified as pin number plus 0 for port 0 or plus 32 for port 1). Under pinctrl, the port and pin are separated so port 1, pin 13 should be specified as <NRF_PSEL(TWIM_SDA, 1, 13)>  not  <NRF_PSEL(TWIM_SDA, 0, 45)>.  You know all this, I'm just elaborating for someone else who might stumble upon this thread.

    The v1.9.99 SHT3XD sample now builds and runs correctly for me on the nrf52840dk with my target pins.

    I added nrf52840dk_nrf52840.overlay to the boards directory:

    &pinctrl {
       i2c0_default_alt: i2c0_default_alt {
          group1 {
             psels = <NRF_PSEL(TWIM_SDA, 1, 13)>,
                     <NRF_PSEL(TWIM_SCL, 1, 15)>;
          };
       };
       i2c0_sleep_alt: i2c0_sleep_alt {
          group1 {
             psels = <NRF_PSEL(TWIM_SDA, 1, 13)>,
                     <NRF_PSEL(TWIM_SCL, 1, 15)>;
             low-power-enable;
          };
       };
    };
    
    &i2c0 {
        pinctrl-0 = <&i2c0_default_alt>;
        pinctrl-1 = <&i2c0_sleep_alt>;
        pinctrl-names = "default", "sleep";
    	sht3xd: sht3xd@45 {
            status = "okay";
    		compatible = "sensirion,sht3xd";
    		reg = <0x45>;
    		label = "SHT3XD";
    		alert-gpios = <&gpio1 10 GPIO_ACTIVE_HIGH>;
    	};
    };
    

    I also made two changes to the main.c file:

    14d13
    < #define SHT3XD DT_NODELABEL(sht3xd)
    29c28
    < 	const struct device *dev = DEVICE_DT_GET(SHT3XD);
    ---
    > 	const struct device *dev = device_get_binding("SHT3XD");

Children
No Data
Related