This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

bmi160 zephyr sensor driver + nrf5340

Hi,

I have problem to use bmi160 library with nrf5340 in spi connection.

I use the example application zephyr/samples/sensor/adxl372 and change the sensor to bmi160 ( with zephyr driver).

device_is_ready(dev) is always not ready. Can some one help me debug why the device (bmi160) isn't initialized?  

my nrf5340dk_nrf5340_cpuapp.overlay config

&spi2 {
	cs-gpios = <&gpio0 11 GPIO_ACTIVE_LOW>;
	bmi160@76 {
		compatible = "bosch,bmi160";
		reg = <0x76>;
		spi-max-frequency = <8000000>;
		label = "BMI160";
		int-gpios = <&gpio0 20 0>;
	};
};

prj.conf 

CONFIG_STDOUT_CONSOLE=y
CONFIG_LOG=y
CONFIG_SPI=y
CONFIG_SENSOR=y
CONFIG_BMI160=y
CONFIG_BMI160_TRIGGER_OWN_THREAD=y
CONFIG_SENSOR_LOG_LEVEL_WRN=y
CONFIG_CBPRINTF_FP_SUPPORT=y
 

snippet in main.c 

void main(void)
{
	struct sensor_value accel[3];
	double mag;
	int i;
	char meter[200];

	const struct device *dev = DEVICE_DT_GET_ANY(bosch_bmi160);//

	if (!device_is_ready(dev)) {
		printf("Device %s is not ready\n", dev->name);
		return;
	}

In zephyr/drivers/sensor/bmi160/bmi160.c  line 985 

#define BMI160_DEVICE_INIT(inst)					\
	DEVICE_DT_INST_DEFINE(inst, bmi160_init, NULL,			\
			      &bmi160_data_##inst, &bmi160_cfg_##inst,	\
			      POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,	\
			      &bmi160_api);

The device is registered. This  is by far I can look into zephyr, however I don't have proper way to debug the zephyr system where a lots of function were formulated in macro.

Parents
  • Hi,

    The first thing I notice is that your overlay needs a few changes. I found another case where an overlay was specified for BMI160. I am not sure whether they got it right, however, it might provide you with a few hints :https://devzone.nordicsemi.com/f/nordic-q-a/73433/bmi160-sample-on-custom-nrf9160

    You will need to specify the pins for the SPI interface. Also you do not need the address '76'. Also replace '76' with '0'.

    I will take a closer look next week.

    BR

    Håkon

  • Hi, I forget to mention that I use nrf5340dk board. In that case, SPI2 pin is defined in the nrf5340_cpuapp_common.dts file. 

    I changed 76 to 0 but it doesn't make any difference. 

    One thing I recognized from the  example you provided, CONFIG_SPI_1=y is presented in prj.conf, which is not configured in my setup.

    However, when I add CONFIG_SPI_2=y to my prj.conf(I use SPI2), which gives  

    "warning: attempt to assign the value 'y' to the undefined symbol SPI_2"    and   "error: Aborting due to Kconfig warnings"

    (I use visual studio to compile instead of segger, I don't know if it gives different result) 

    Please help!

Reply
  • Hi, I forget to mention that I use nrf5340dk board. In that case, SPI2 pin is defined in the nrf5340_cpuapp_common.dts file. 

    I changed 76 to 0 but it doesn't make any difference. 

    One thing I recognized from the  example you provided, CONFIG_SPI_1=y is presented in prj.conf, which is not configured in my setup.

    However, when I add CONFIG_SPI_2=y to my prj.conf(I use SPI2), which gives  

    "warning: attempt to assign the value 'y' to the undefined symbol SPI_2"    and   "error: Aborting due to Kconfig warnings"

    (I use visual studio to compile instead of segger, I don't know if it gives different result) 

    Please help!

Children
No Data
Related