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

nRF9160 with BME280 sensor

I am trying to test a BME280  sensor on the nRF9160. I followed the steps where I created a folder (board) and added the nrf9160_pca10090.overlay and add couple of line in the prj.conf. I am building with build -b nrf9160_pca10090ns(non-secure). I get an error while building. I didnt connect the sensor but the code should build without the sensor am I wrong ?

same error with segger

In file included from /home/ahmed/v1.2.0/zephyr/drivers/sensor/bme280/bme280.c:24:0:
3> /home/ahmed/v1.2.0/zephyr/drivers/sensor/bme280/bme280.h:114:2: error: #error "BME280 device type not specified"
3> /home/ahmed/v1.2.0/zephyr/drivers/sensor/bme280/bme280.c:370:22: warning: unused variable 'data' [-Wunused-variable]
3> In file included from ../../../../include/drivers/sensor.h:23:0,
3>                  from /home/ahmed/v1.2.0/zephyr/drivers/sensor/bme280/bme280.c:11:
3> /home/ahmed/v1.2.0/zephyr/drivers/sensor/bme280/bme280.c:398:29: error: 'DT_INST_0_BOSCH_BME280_LABEL' undeclared here (not in a function); did you mean 'DT_INST_0_SOC_NV_FLASH_LABEL'?
3> ../../../../include/device.h:106:11: note: in definition of macro 'DEVICE_AND_API_INIT'
4> Compiling 'nrf_cc310_platform_mutex_zephyr.c'
5> Compiling 'nrf_cc310_platform_abort_zephyr.c'
8> Compiling 'sys_clock_init.c'
Build failed

I will add the codes form the files as well to make it easier.

&i2c2 {
    status = "ok";
    sda-pin = <12>;
    scl-pin = <11>;
    
    bme280@76 {
        compatible = "bosch,bme280";
        reg = <0x76>;
        label = "BME280";
    };
};
Overlay

CONFIG_STDOUT_CONSOLE=y
CONFIG_I2C=y
CONFIG_SENSOR=y
CONFIG_BME280=y
CONFIG_I2C_2=y
prj.conf

# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.13.1)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(bme280)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
CMake

/*
 * Copyright (c) 2012-2014 Wind River Systems, Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

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

void main(void)
{
	struct device *dev = device_get_binding("BME280");

	if (dev == NULL) {
		printk("Could not get BME280 device\n");
		return;
	}

	printk("dev %p name %s\n", dev, dev->config->name);

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

Parents Reply
  • "Could not get BME280 device" is usually caused by failure to read the hardware ID from the device in the driver's initialization. Did you get any usueful information from the added logging? Note that CONFIG_LOG=y needs to be set to enable logging system, though there should have been some warnings during compilation if it wasn't on. Hopefully the logs can shed some light on what goes wrong.

    In the BME280 datasheet rev 1.6, there's a figuer on page 39 that might be useful to confirm that the hardware setup is correct for I2C operation, especially the CSB and SDO connections. I'd use the default address if there's not an important reason to do otherwise to reduce what can go wrong.

    If you're using nRF91 DK, please be aware that it is operating by default at 1.8 V. You can se SW11 next to the power switch to confirm the setting. V_DDIO needs to match the setting, and I'd typically set V_DD to the same. CSB and SDO should be set with GND or V_DDIO.

    Regards,

    Jan Tore

Children
No Data
Related