BME280 Not working on v2.1.1

Hi,

I have recently updated to V2.1.1 and I can no longer get my BME280 sensor to work.

I am using the standard code from the samples  directory, 

#include <zephyr/zephyr.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/sensor.h>
#include <stdio.h>

/*
 * Get a device structure from a devicetree node with compatible
 * "bosch,bme280". (If there are multiple, just pick one.)
 */

static const struct device *get_bme280_device(void)
{
	const struct device *dev = DEVICE_DT_GET_ANY(bosch_bme280);

	if (dev == NULL) {
		/* No such node, or the node does not have status "okay". */
		printk("\nError: no device found.\n");
		return NULL;
	}

	if (!device_is_ready(dev)) {
		printk("\nError: Device \"%s\" is not ready; "
		       "check the driver initialization logs for errors.\n",
		       dev->name);
		return NULL;
	}

	printk("Found device \"%s\", getting sensor data\n", dev->name);
	return dev;
}

void main(void)
{
	const struct device *dev = get_bme280_device();

	if (dev == NULL) {
		return;
	}

	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));
	}
}

 
my overlay file is this
&pinctrl {
	uart0_default_alt: uart0_default_alt {
		group0 {
			psels = <NRF_PSEL(UART_TX, 0, 24)>, <NRF_PSEL(UART_RX, 0, 22)>;
		};
	};

	uart0_sleep_alt: uart0_sleep_alt {
		group1 {
			psels = <NRF_PSEL(UART_TX, 0, 24)>, <NRF_PSEL(UART_RX, 0, 22)>;
			low-power-enable;
		};
	};
	i2c0_default_alt: i2c0_default_alt {
		group2 {
			psels = <NRF_PSEL(TWIM_SDA, 0, 17)>, <NRF_PSEL(TWIM_SCL, 0, 20)>;
		};
	};

	i2c0_default_sleep: i2c0_default_sleep {
		group3 {
			psels = <NRF_PSEL(TWIM_SDA, 0, 17)>, <NRF_PSEL(TWIM_SCL, 0, 20)>;
			low-power-enable;
		};
	};
};

&uart0 {
	pinctrl-0 = <&uart0_default_alt>;
	pinctrl-1 = <&uart0_sleep_alt>;	
	pinctrl-names = "default", "sleep";

	compatible = "nordic,nrf-uart";
	current-speed = <115200>;
	status = "okay";
};

&i2c0 {
	status = "okay";
	compatible = "nordic,nrf-twim";
	pinctrl-0 = <&i2c0_default_alt>;
	pinctrl-1 = <&i2c0_default_sleep>;
	pinctrl-names = "default", "sleep";
	clock-frequency = < I2C_BITRATE_STANDARD >;
	bme280@76 {
		compatible = "bosch,bme280";
		reg = <0x76>;
		label = "BME280";
	};
};

my prj file looks like this

CONFIG_PINCTRL=y
CONFIG_ASSERT=y
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_GPIO=y
CONFIG_SERIAL=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_NEWLIB_LIBC=y
CONFIG_CONSOLE_SUBSYS=y
CONFIG_CONSOLE_GETCHAR=y
CONFIG_STDOUT_CONSOLE=y
CONFIG_CONSOLE=y

CONFIG_CPLUSPLUS=y
CONFIG_LOG=y
CONFIG_SHELL=y
CONFIG_REBOOT=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
CONFIG_PRINTK=y
CONFIG_PM_DEVICE=y

CONFIG_I2C=y
CONFIG_I2C_NRFX=y
CONFIG_SENSOR=y
CONFIG_BME280=y
CONFIG_BOOT_BANNER=n

CONFIG_HEAP_MEM_POOL_SIZE=16384

 I am using VS and the line "CONFIG_BME280=y" shows a warning

CONFIG_BME280 was assigned the value y, but got the value n. Missing dependencies:
DT_HAS_BOSCH_BME280_ENABLED

What am I missing?


Rod

Parents Reply Children
  • Hi Rod,

    OK, this is a good step in the right direction. I have only been focusing on the "CONFIG_DT_HAS_BOSCH_BME280_ENABLED not defined" warning until now. The 2nd error which you are seeing now is a runtime error and comes from the driver here: https://github.com/nrfconnect/sdk-zephyr/blob/main/drivers/i2c/i2c_nrfx_twim.c#L171, and it occurs during initialisation of the driver on startup.

    It sounds like you were able to interface with the sensor before you updated to SDK v2.1.1. What version did you use previously? Also, is there anything else that have changed? Pin assignments, etc?

    The best way to troubleshoot this further may be to use a logic analyzer and probe the bus lines, if you have one available.

    Vidar

  • Hi Vidar,

    Sorry, I was mistaken, the "CONFIG_DT_HAS_BOSCH_BME280_ENABLED not defined" is still there.

    I cant recall when this stopped working, I know it worked before the changes to the overlay file.

     Errors when using BME680 Sample Code 

    Since then, the board hasn't changed, the pinout hasn't changed, 

    Rod

  • Hi Rod,

    I notice you are setting the i2c address to 0x77 in the overlay you posted here:  RE: Errors when using BME680 Sample Code and 0x76 in the one you posted here. Could this be the reason? I guess you could also try to use the TWI instead of the TWIM peripheral by changing "compatible" from "compatible = "nordic,nrf-twim"; to compatible = "nordic,nrf-twi";

    Best regards,

    Vidar

  • Hi Vidar,

    Sorry, maybe that was a bad example. The '680 is 0x77, the '280 is 0x76.I have tried both. I have also tried both twi and twin.

    Rod 

  • Hi Vidar,

    I got it working! I think the change was to move to using I2c1. I also actively disabled some other peripherals. For completeness, I have shared my overlay file below. I am using the standard code from the samples.

    Rod

    &pinctrl {
    	uart0_default_alt: uart0_default_alt {
    		group0 {
    			psels = <NRF_PSEL(UART_TX, 0, 24)>, <NRF_PSEL(UART_RX, 0, 22)>;
    		};
    	};
    
    	uart0_sleep_alt: uart0_sleep_alt {
    		group1 {
    			psels = <NRF_PSEL(UART_TX, 0, 24)>, <NRF_PSEL(UART_RX, 0, 22)>;
    			low-power-enable;
    		};
    	};
    
    
    	i2c1_default_alt: i2c1_default_alt {
    		group2 {
    			psels = <NRF_PSEL(TWIM_SDA, 0, 17)>, <NRF_PSEL(TWIM_SCL, 0, 20)>;
    		};
    		
    	};
    
    	i2c1_sleep_alt: i2c1_sleep_alt {
    		group3 {
    			psels = <NRF_PSEL(TWIM_SDA, 0, 17)>, <NRF_PSEL(TWIM_SCL, 0, 20)>;
    			low-power-enable;
    		};
    		
    	};
    };
    
    &uart0 {
    	pinctrl-0 = <&uart0_default_alt>;
    	pinctrl-1 = <&uart0_sleep_alt>;	
    	pinctrl-names = "default", "sleep";
    	compatible = "nordic,nrf-uart";
    	current-speed = <115200>;
    	status = "okay";
    };
    
    &i2c1 {
    	status = "okay";
    	compatible = "nordic,nrf-twim";
    	pinctrl-0 = <&i2c1_default_alt>;
    	pinctrl-1 = <&i2c1_sleep_alt>;
    	pinctrl-names = "default", "sleep";
    	clock-frequency = <I2C_BITRATE_STANDARD>;
    	bme280@76 {
    		compatible = "bosch,bme280";
    		reg = <0x76>;
    		label = "BME280";
    		status = "okay";
    	};
    };
    
    &i2c0 {
    	status = "disabled";
     };
    
     &spi0 {
    	status = "disabled";
     };
    
    &spi1 {
    	status = "disabled";
     };
    
     &gpio0 {
    	status = "disabled";
     };
    
     &gpio1 {
    	status = "disabled";
     };
    
     &usbd {
    	status = "disabled";
     };
    

Related