SHT31 readout on nRF5340 using the Zephyr Sample

Hi everyone,

I am trying to get the Zephyr SHT31 sample running on a nRF7002-DK (nrf5340), but I only get "Device SHT3XD is not ready".

I ran a debug session, and it is failing due to zephyr/kernel/device.c::z_device_is_ready funcition returning false.

somehow the dev->state->initialized = true, but dev->state->init_res = 5 (needs to be 0 for the function to return true).

My guess is that I need to fix my device overlay file - below is the device overlay file I am using:

&i2c1 {
	sht3xd@44 {
		compatible = "sensirion,sht3xd";
		reg = <0x44>;
		label = "SHT3XD";
	};
};

Thanks!

Makoto

Parents Reply
  • Hi Sigurd,

    Thank you for your help.

    Yes, I have enabled I2C in prj.conf. Below is my prj.conf:

    CONFIG_STDOUT_CONSOLE=y
    CONFIG_I2C=y
    CONFIG_SENSOR=y
    CONFIG_CBPRINTF_FP_SUPPORT=y

    I've tried with status = "okay"; added to the overlay file:

    &i2c1 {
    	sht3xd@44 {
    		compatible = "sensirion,sht3xd";
    		status = "okay";
    		reg = <0x44>;
    		label = "SHT3XD";
    	};
    };

    But I still get the same problem in device.c (line 103): dev->state->init_res = 5

    FYI the same hardware setup works (I get both temperature and humidity readouts) with nRF52840DK.

    Also I am using the code from here:

    https://github.com/zephyrproject-rtos/zephyr/blob/main/samples/sensor/sht3xd/README.rst

    In the above documentation, I see an entry:

    "Depending on the baseboard used, the SDA and SCL lines require Pull-Up resistors."

    Would I need pull-up resistors when working with nRF7002DK board (nRF52840DK works with the same setup)?

    Thanks,

    Makoto

Children
  • Hi,

    It is the i2c1 which needs to be enabled:

    &i2c1 {
    	status = "okay";
    	sht3xd@44 {
    		compatible = "sensirion,sht3xd";
    		reg = <0x44>;
    		label = "SHT3XD";
    	};
    };

    By the way, is there a reason to why you use i2c1 instead of i2c0?

    makoto.inoue said:
    Would I need pull-up resistors when working with nRF7002DK board (nRF52840DK works with the same setup)?

    As long as the nRF7002DK does not have pull-ups on the Development Kit on the pins you use, you need those, yes.
    And I do not believe it has. To verify this, you can check its hardware files.

  • Hi Sigurd,

    I've tried the suggested edits/configuration, but it still does not work.

    The reason I'm using i2c1 instead of i2c0 is because the Arduino pin layout for SCL and SDA are mapped to:

    SCL -> P1.03

    SDA-> P1.02

    of the nRF5340. I have wired my SHT31-D board's SCL and SDA to those pins. Hence I thought it needed to use port1 instead of port 0, so i2c1 instead of i2c0. Maybe this is configurable/flexible and I don't have to insist on using i2c1.

    Does an i2c current drive level differ on nRF5340 than nRF52840? I remember in when interfacing a particular kind of a touch LCD with nRF52840, I needed to increase the SPI's current drive level (needed an extra GPIO configuration). Maybe something similar is required for nRF5340 when interfacing older i2c devices...?

    Also note that I checked the SHT31-D board, and it has pull-up resisters for both SCL and SDA, so that is taken care.

  • Hi,

    The nRF5340 is not pin-locked. You can use any pins you want for I2C, but see pin assignements for some notes.
    To change pins used for either i2c0 or i2c1, see Pin Control.

    The i2c0 and i2c1 both should work though. But if it builds fine for i2c0 for you, maybe no need to figure out why i2c1 does not work?

    makoto.inoue said:
    Does an i2c current drive level differ on nRF5340 than nRF52840? I remember in when interfacing a particular kind of a touch LCD with nRF52840, I needed to increase the SPI's current drive level (needed an extra GPIO configuration). Maybe something similar is required for nRF5340 when interfacing older i2c devices...?

    For drive current, see GPIO electrical specification.

  • Hi Sigurd,

    I have not gotten the i2c0 that builds yet (not with nrf7002dk_nrf5340_cpuapp board). When I try to change from i2c1 to i2c0 it starts showing me a red squiggly underline in nRF Connect for VS code stating it needs more parameters to be configured (ex. "pinctrl-0 is requried"). It is not important to me whether I use i2c0 or i2c1, I'm just looking for a configuration that works.

    From what I can tell, GPIO output current levels are same for both nRF52840 and nRF5340. Since I can get the example working for nRF52840, I think that there is no need for extra GPIO setup for nRF5340.  

  • makoto.inoue said:
    When I try to change from i2c1 to i2c0 it starts showing me a red squiggly underline in nRF Connect for VS code stating it needs more parameters to be configured (ex. "pinctrl-0 is requried").

    This is because the i2c1 dts definition has pinctrl, while i2c0 has not yet been defined for the nRF5340DK cpuapp.
    Still, just keep on using i2c1 if that is the default, we should be able to make that one work.

    Maybe some of your pins are used by another resource, and this is why the i2c1 will not work?
    You can check this either by looking at build/zephyr/zephyr.dts or by using the VS Code visual dts editor:

Related