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,

    Do you still get the warning that the 'DT_HAS_BOSCH_BME280_ENABLED' dependency is missing? I tried now to build the sample for 'nrf52840dk_nrf52840' with the overlay you posted, but it appears to be working as expected for me.

    Generated zephyr.dts from nrf52840dk_nrf52840 build with overlay

    CONFIG_DT_HAS_BOSCH_BME280_ENABLED enabled in .config

    RodWatt said:
    Weirdly, its picking up arduino_i2c?

     This comes from the board file. Dev kits following the arduino form factor will typically define interfaces such as arduino_i2c, arduino_spi, etc to let the application know what i2c or SPI interface to select when connecting the board to arduino type shields. It's like a tag/label to help the program select the correct interface.

    Have you tried with the original bme280 sample as well?

  • Hi Vidar,

    I can see that CONFIG_DT_HAS_BOSCH_BME280_ENABLED is enabled in .config

    However, when I look at my config file, it says its set to n in build

    Yes, I have tried the original code, same error.

    Rod

  • Hi Rod,

    Thanks for confirming that CONFIG_DT_HAS_BOSCH_BME280_ENABLED is defined in .config. But do you still see this warning in your build log:

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

    ?

    It says CONFIG_BME280 is set to =n because CONFIG_DT_HAS_BOSCH_BME280_ENABLED is not selected.

    Vidar

  • Hi Vidar,

    No I dont see that error any more, just this one

    Error: Device "BME280" is not ready; check the driver initialization logs for errors.
    [00:00:00.753,021] <err> i2c_nrfx_twim: Error on I2C line occurred for message 0

    Rod

  • 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

Related