Help connecting I2C temperature sensor to nRF9160DK

Hi Nordic Team

I have been successfully using the nRF52840DK to create various Bluetooth sensors, including a thermometer sensor.

I bought a nRF9160DK with the intent to create an IoT thermometer sensor using NB-IoT.

I am having trouble getting the nRF9160 to recognise/find the attached SHT31 sensor. I have used this exact same sensor with the 52840 Dev Kit without any issues, so I thought connecting it to the 9160DK should be simple...

I have tried a number of different approaches but I can't seem to get this working. Could you please have a look and let me know if I am doing anything wrong with the setup or connecting the sensor to the 9160DK?

I created a very basic app (attached) which I think should include all the elements to get this sensor identified and connected. The app compiles but the output is always "Could not get SHT3XD device".

I have tested the sensor on another board (not a 9160DK) and it is working. 

The sensor datasheet says it can operate from 2.5v to 5.5v so I tried switching between 1.8v and 3v using SW9 on the 9160DK with no change.

There is definitely voltage going to the sensor. I even tested the wires and they are all fine. Not sure what else to look for.

Overlay file:

&pinctrl {

    i2c1_default: i2c1_default {
        group1 {
            psels = <NRF_PSEL(TWIM_SDA, 0, 30)>,
                <NRF_PSEL(TWIM_SCL, 0, 31)>;
        };
    };

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

&i2c0 {
    compatible = "nordic,nrf-twim";
    status = "disabled";    
};

&i2c1 {
    compatible = "nordic,nrf-twim";
    status = "okay";
    pinctrl-0 = <&i2c1_default>;
    pinctrl-1 = <&i2c1_sleep>;
    clock-frequency = <I2C_BITRATE_FAST>;
    pinctrl-names = "default", "sleep";
    SHT3XD: sht3xd@44 {
        compatible = "sensirion,sht3xd";
        reg = <0x44>;
        label = "SHT3XD";
        alert-gpios = <&gpio0 10 GPIO_ACTIVE_HIGH>;    
    };
};

prj.conf file:

CONFIG_STDOUT_CONSOLE=y

CONFIG_SENSOR=y
CONFIG_SHT3XD=y
CONFIG_GPIO=y

CONFIG_I2C=y
CONFIG_I2C_NRFX=y
main.c
#include <zephyr.h>

#include <device.h>
#include <drivers/sensor.h>
#include <drivers/gpio.h>
#include <stdio.h>

void main(void)
{
    printk("Starting ST_T1_LR...\n");
   
    const struct device *thermometer_dev;
    struct sensor_value temp, hum;  
    double temperature, humidity;

    thermometer_dev = device_get_binding("SHT3XD");

    if (thermometer_dev == NULL) {
        printf("Could not get SHT3XD device\n");        
    }
    else{
        printk("Thermometer Ready\n");
    }  

    printk("starting loop\n");

    while (true) {

        k_sleep(K_MSEC(1000));

        printk("looping...\n");
       
    }
}

Any help would be very much apprecaited.

Regards

Garysht31.zip

  • Hi Achim

    Thanks so much for your input. I very much appreciate it!

    In my haste in testing Naeem's feedback and updated overlay file, I completely forgot to set SW9 to 3.3v.

    Once I changed it to the correct voltage, the thermometer is now being correctly detected using Naeem's version of the Overlay and moving the location of the overlay from a /board folder directly to the root project folder.

      I would still like to understand how your changes have fixed my problem. What specifically was I doing wrong?

  • Hi Gary, 

    Yes, you are right that several interfaces share the same base address, and that's why we have to turn them off.

    TWI (M/S), SPI (M/S), and UARTE interfaces share same register base addresses. 

    When I complied with your overlay, I got the error that only one of these interfaces could be enabled (snapshot attached below). So, I went to the compiled DTS, and looked for enabled ("okay") devices, and those which were having same reg. So, I updated the overlay file to disable those interfaces.

    So basically, we need to disable uart1 that is conflicting with our required interface.

    &uart1 {
    	compatible = "nordic,nrf-uarte";
    	status = "disabled";
    };

    Just addition of this code in overlay should suffice. 

    (Previously I disabled 3 ports, but you just need UART1 to be disabled).

    Regards,

    Naeem

Related