nrf5340dk SPI communication with BMI270

Hello, I am trying to communicate with a Bosch BMI 270 device(datasheet) using the nrf5340dk. I macgyvered something together from the bmi270 file in the zephyr/sensor folder and an example I found for SPI communication with the nrf5340dk.

Overlay file:

&gpio0 {
	status = "okay";
};


&spi1 {
	status = "okay";
	bmi270@0 {
		compatible = "bosch,bmi270";
		reg = <0>;
		spi-max-frequency = <DT_FREQ_M(10)>;
		label = "BMI270";
	};

	pinctrl-0 = <&spi1_default>;
	pinctrl-names = "default";
};

&pinctrl {
	spi1_default: spi1_default {
		group1 {
			psels = <NRF_PSEL(SPIM_SCK, 0, 17)>,
			        <NRF_PSEL(SPIM_MOSI, 0, 15)>,
			        <NRF_PSEL(SPIM_MISO, 0, 16)>,
			        <NRF_PSEL(SPIS_CSN, 0, 18)>;
		};

	};
};

Project config:

CONFIG_I2C=n
CONFIG_SPI=y
CONFIG_GPIO=y

CONFIG_SENSOR=y
CONFIG_BMI270=y

CONFIG_STDOUT_CONSOLE=y
CONFIG_RTT_CONSOLE=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_LOG_BACKEND_RTT=y
CONFIG_UART_CONSOLE=n

Where it gets stuck in main.c(device_get_binding returns NULL, same with SPI):

int main(void)
{
	const struct device *bmi270;
	struct sensor_value acc[3], gyr[3];
	struct sensor_value full_scale, sampling_freq, oversampling;

	bmi270 = device_get_binding("BMI270");
	if (!bmi270)
	{
		printk("Gyro: Device not found.\n");
		return 0;
	}
	else
	{
		printk("Gyro: Device found.\n");
	}
}

Parents
  • Hi,

    You could try to change your main.c file. Changes are shown below.

    int main(void)
    {
        const struct device * dev_bmi270;
        dev_bmi270 = DEVICE_DT_GET_ONE(bosch_bmi270);
        if (!device_is_ready(dev_bmi270))
    	{
    		printk("Gyro: Device not found.\n");
    		return 0;
    	}
    	else
    	{
    		printk("Gyro: Device found.\n");
    	}
            return 0;
    }
    

    Best regards,
    Dejan

Reply
  • Hi,

    You could try to change your main.c file. Changes are shown below.

    int main(void)
    {
        const struct device * dev_bmi270;
        dev_bmi270 = DEVICE_DT_GET_ONE(bosch_bmi270);
        if (!device_is_ready(dev_bmi270))
    	{
    		printk("Gyro: Device not found.\n");
    		return 0;
    	}
    	else
    	{
    		printk("Gyro: Device found.\n");
    	}
            return 0;
    }
    

    Best regards,
    Dejan

Children
No Data
Related