I am attempting to get the BMI270 sample working on an nRF5340DK, using nRF Connect SDK v2.4.2, after successfully build and flash the program to nRF5340DK I got error "Device BMI270 is not ready", how can I solve this problem?
On the hardware side I'm using a BMI270 breakout connecting SDA to P1.02 and SCL to P1.03.
I am using the following config and overlay files:
prj.conf:CONFIG_STDOUT_CONSOLE=y
CONFIG_I2C=y
CONFIG_SENSOR=y
CONFIG_BMI270=y
app.overlay:/*
* Copyright (c) 2021 Bosch Sensortec GmbH
*
* SPDX-License-Identifier: Apache-2.0
*/
&arduino_i2c {
compatible = "nordic,nrf-twim";
zephyr,concat-buf-size = <257>;
status = "okay";
bmi270@68 {
compatible = "bosch,bmi270";
reg = <0x68>;
label = "BMI270";
};
};
main.c (didn't change, just sample code)/*
* Copyright (c) 2021 Bosch Sensortec GmbH
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/drivers/sensor.h>
#include <stdio.h>
int main(void)
{
const struct device *const dev = DEVICE_DT_GET_ONE(bosch_bmi270);
struct sensor_value acc[3], gyr[3];
struct sensor_value full_scale, sampling_freq, oversampling;
if (!device_is_ready(dev)) {
printf("Device %s is not ready\n", dev->name);
return 0;
}
printf("Device %p name is %s\n", dev, dev->name);
/* Setting scale in G, due to loss of precision if the SI unit m/s^2
* is used
*/
full_scale.val1 = 2; /* G */
full_scale.val2 = 0;
sampling_freq.val1 = 100; /* Hz. Performance mode */
sampling_freq.val2 = 0;
oversampling.val1 = 1; /* Normal mode */
oversampling.val2 = 0;
sensor_attr_set(dev, SENSOR_CHAN_ACCEL_XYZ, SENSOR_ATTR_FULL_SCALE,
&full_scale);
sensor_attr_set(dev, SENSOR_CHAN_ACCEL_XYZ, SENSOR_ATTR_OVERSAMPLING,
&oversampling);
/* Set sampling frequency last as this also sets the appropriate
* power mode. If already sampling, change to 0.0Hz before changing
* other attributes
*/
sensor_attr_set(dev, SENSOR_CHAN_ACCEL_XYZ,
SENSOR_ATTR_SAMPLING_FREQUENCY,
&sampling_freq);
/* Setting scale in degrees/s to match the sensor scale */
full_scale.val1 = 500; /* dps */
full_scale.val2 = 0;
sampling_freq.val1 = 100; /* Hz. Performance mode */
sampling_freq.val2 = 0;
oversampling.val1 = 1; /* Normal mode */
oversampling.val2 = 0;
sensor_attr_set(dev, SENSOR_CHAN_GYRO_XYZ, SENSOR_ATTR_FULL_SCALE,
&full_scale);
sensor_attr_set(dev, SENSOR_CHAN_GYRO_XYZ, SENSOR_ATTR_OVERSAMPLING,
&oversampling);
/* Set sampling frequency last as this also sets the appropriate
* power mode. If already sampling, change sampling frequency to
* 0.0Hz before changing other attributes
*/
sensor_attr_set(dev, SENSOR_CHAN_GYRO_XYZ,
SENSOR_ATTR_SAMPLING_FREQUENCY,
&sampling_freq);
while (1) {
/* 10ms period, 100Hz Sampling frequency */
k_sleep(K_MSEC(10));
sensor_sample_fetch(dev);
sensor_channel_get(dev, SENSOR_CHAN_ACCEL_XYZ, acc);
sensor_channel_get(dev, SENSOR_CHAN_GYRO_XYZ, gyr);
printf("AX: %d.%06d; AY: %d.%06d; AZ: %d.%06d; "
"GX: %d.%06d; GY: %d.%06d; GZ: %d.%06d;\n",
acc[0].val1, acc[0].val2,
acc[1].val1, acc[1].val2,
acc[2].val1, acc[2].val2,
gyr[0].val1, gyr[0].val2,
gyr[1].val1, gyr[1].val2,
gyr[2].val1, gyr[2].val2);
}
return 0;
}
gives the output:*** Booting Zephyr OS build v3.3.99-ncs1-2 ***
Device BMI270 is not ready
Any help would be greatly appreciated!