Im trying to make a simpel project reading the sensor BME280 over SPI.
I can´t get any activity on the SPI pins when i check with my logic analyzer.
I´m using nrf9160-DK v 0.9.0 SDK v 1.7.1
# Copyright (c) 2020, Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 config LOG default y config LOG_PRINTK default y config SENSOR_LOG_LEVEL default 4 # Enable SPI and I2C support by default so that the sample works with # the device connected either way. These defaults can be overridden if # needed. config SPI default y config I2C default y source "Kconfig.zephyr"
Kconfig
CONFIG_SPI=y CONFIG_I2C=n CONFIG_SENSOR=y CONFIG_BME280=y
prj.conf
/* Example configuration of a BME280 device on an Arduino SPI bus. */
&spi3 {
status = "okay";
sck-pin = <10>;
mosi-pin = <11>;
miso-pin = <12>;
cs-gpios = <&gpio0 13 GPIO_ACTIVE_LOW>;
bme280@0 {
compatible = "bosch,bme280";
reg = <0x00>;
//reg = <0x76>;
spi-max-frequency = <4000000>;
label = "BME280";
};
};
&uart3 {
status = "disabled";
};
nrf9160dk_nrf9160_ns.overlay
/*
* Copyright (c) 2012-2014 Wind River Systems, Inc.
* Copyright (c) 2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>
#include <device.h>
#include <devicetree.h>
#include <drivers/sensor.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));
}
}
main.c