This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Can't connect to BME280 sensor - i2c_nrfx_twim: Error 195952641 occurred for message 0

Hi,

I am trying to run the Zephyr BME280 sensor sample application (using nRF9160 DK) in NCS1.3.1, but get the below error:

SPM: NS image at 0xc000
SPM: NS MSP at 0x20020b50
SPM: NS reset vector at 0xdafd
SPM: prepare to jump to Non-Secure image.
[00:00:00.000,000] <dbg> BME280.bme280_init: initializing BME280
[00:00:00.000,091] <err> i2c_nrfx_twim: Error 195952641 occurred for message 0
[00:00:00.000,122] <dbg> BME280.bme280_chip_init: ID read failed: -5
[00:00:00.000,122] <dbg> BME280.bme280_init: BME280 failed
*** Booting Zephyr OS build v2.3.0-rc1-ncs2  ***
No device "BME280" found; did initialization fail?

My prj.conf is as follows:

CONFIG_SENSOR=y
CONFIG_BME280=y
CONFIG_I2C=y
CONFIG_I2C_1=y

And board overlay nrf9160dk_nrf9160ns.overlay is as follows:

&i2c1 {
  compatible = "nordic,nrf-twim";
	status = "okay";
	sda-pin = <30>;
	scl-pin = <31>;
  clock-frequency = <I2C_BITRATE_FAST>;

	bme280@77 {
		compatible = "bosch,bme280";
		reg = <0x77>;
		label = "BME280";
	};
};

&uart1 {
    status = "disabled";
};

I power the sensor using the DK's VDD.

I am however able to get things working with the exact same configuration when I deploy the sample to the nRF5340 PDK, replacing the overlay filename with nrf5340pdk_nrf5340_cpuapp.overlay.

Could someone kindly help? I cannot figure why I can't get the sample to work on the nRF9160 DK.

Parents
  • Hi Murphree,

    The error 195952641 is printed from this line:

    https://github.com/NordicPlayground/fw-nrfconnect-zephyr/blob/master/drivers/i2c/i2c_nrfx_twim.c#L80

     

    And corresponds to this error (address NACK):

    https://github.com/NordicPlayground/fw-nrfconnect-hal_nordic/blob/master/nrfx/drivers/nrfx_errors.h#L68

     

    How often do you sample the sensor, and how often do you see NACK errors?
    Have you tried scoping the analog signal to see if there's any issues with the voltage levels?

  • Hi Martin,

    Thanks for picking this up. I am completely unable to get the sensor working with the nRF9160 DK, the code (extract included below) fails on initialisation. What's weird is that the exact same code and configuration works when using the nRF5340 PDK.

    	struct device *dev = device_get_binding(BME280_LABEL);
    
    	if (dev == NULL) {
    		printk("No device \"%s\" found; did initialization fail?\n", BME280_LABEL);
    		return;
    	} else {
    		printk("Found device \"%s\"\n", BME280_LABEL);
    	}
    
    	while (1) {
    		struct sensor_value temp, press, humidity;
    
    		sensor_sample_fetch(dev);
    		sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temp);
    		sensor_channel_get(dev, SENSOR_CHAN_PRESS, &press);
    		sensor_channel_get(dev, SENSOR_CHAN_HUMIDITY, &humidity);
    
    		printk("temp: %d.%06d; press: %d.%06d; humidity: %d.%06d\n",
    		      temp.val1, temp.val2, press.val1, press.val2,
    		      humidity.val1, humidity.val2);
    
    		k_sleep(K_MSEC(1000));
    	}

    It appears the failure is happening during initialisation. I checked the supply voltages to the sensor (TI's Sensors BoosterPack), and the levels are as expected: 1.8V when powered from the DK's VDD, and 3.3V when powered from an external source.

    Could it be that I am missing additional config that is specific to the nRF9160 DK. Strangely, I think I remember getting it to work a couple of months ago, but can't make sense of why it's failing now. Only thing I can think of is that I was using an earlier version of NCS.

Reply
  • Hi Martin,

    Thanks for picking this up. I am completely unable to get the sensor working with the nRF9160 DK, the code (extract included below) fails on initialisation. What's weird is that the exact same code and configuration works when using the nRF5340 PDK.

    	struct device *dev = device_get_binding(BME280_LABEL);
    
    	if (dev == NULL) {
    		printk("No device \"%s\" found; did initialization fail?\n", BME280_LABEL);
    		return;
    	} else {
    		printk("Found device \"%s\"\n", BME280_LABEL);
    	}
    
    	while (1) {
    		struct sensor_value temp, press, humidity;
    
    		sensor_sample_fetch(dev);
    		sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temp);
    		sensor_channel_get(dev, SENSOR_CHAN_PRESS, &press);
    		sensor_channel_get(dev, SENSOR_CHAN_HUMIDITY, &humidity);
    
    		printk("temp: %d.%06d; press: %d.%06d; humidity: %d.%06d\n",
    		      temp.val1, temp.val2, press.val1, press.val2,
    		      humidity.val1, humidity.val2);
    
    		k_sleep(K_MSEC(1000));
    	}

    It appears the failure is happening during initialisation. I checked the supply voltages to the sensor (TI's Sensors BoosterPack), and the levels are as expected: 1.8V when powered from the DK's VDD, and 3.3V when powered from an external source.

    Could it be that I am missing additional config that is specific to the nRF9160 DK. Strangely, I think I remember getting it to work a couple of months ago, but can't make sense of why it's failing now. Only thing I can think of is that I was using an earlier version of NCS.

Children
Related