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

  • Hi Rod,

    Thank your for the update, I'm glad to hear that it finally works now! Although, it would have been nice to understand why i2c0 did not work.

    The build should have triggered an error at compile if another peripheral  with a shared ID such as spi0 had been enabled. The peripheral also seems to get initialized correctly when I run it here. I will make sure to update this ticket if I figure out what may have caused this.

    Vidar

  • Hi Vidar,

    Yes, I am also not 100% convinced that this was the actual fix, it could be a coincidence. Previously, I had used !2C0. I will put it back to I2C0 and see if it still works.

    Since posting my "fix", i have tried to get the BME680 sensor to work and the CFB display, both peripherals I have previously had working, also fail with !2C errors. I think there is someone more fundamental  going on here.    

    Can you open this ticket up again?


    Rod

  • Hi Rod,

    The ticket is open now, so we can continue here.

    Are you able to check the TWIM0/1 registers like shown in my previous comment to see if there are any differences when you change from instance 1 to 0?

    It is also worth checking if the GPIO configuration for the SDA and SCL pin matches this : Master mode pin configuration.  

    Vidar

    Edit: In case you don't have external pull-ups on the SDA/SCL lines, please add the 'bias-pull-up' property to your overlay (ref. https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/build/dts/api/bindings/pinctrl/nordic,nrf-pinctrl.html#grandchild-node-properties)

    &pinctrl {
    
    	i2c0_default_alt: i2c0_default_alt {
    		group2 {
    			psels = <NRF_PSEL(TWIM_SDA, 0, 17)>, <NRF_PSEL(TWIM_SCL, 0, 20)>;
    			bias-pull-up;
    		};
    	};
    
    	i2c0_default_sleep: i2c0_default_sleep {
    		group3 {
    			psels = <NRF_PSEL(TWIM_SDA, 0, 17)>, <NRF_PSEL(TWIM_SCL, 0, 20)>;
    			low-power-enable;
    		};
    	};
    };

    Also, I don't think I have asked you earlier, but what board do you build for, is it the '52840dk_nrf52840'?

  • Hi Vidar,

    I will check the registers later when i get a chance. I do have external pull ups, this is a board that has been working previously. My board is a nrf52840dongle_nrf52840.

    Rod

Related