BMI270 interrupts seem not to be usable in nRF Connect SDK v2.2.0 with zephyr

Hi,

I am developing a nrf5340 based board containing the BMI270 IMU device via SPI interface like in the Thingy:53.

Unfortunately I am not able to set the device up for using the data ready interrupt and reacting to the interrupt via the zephyr device driver so far. The device works fine just polling for values regularly, but I need it interrupt driven. Looking at the official zephyr project documentation, the interrupt interface simply does not seem to be implemented for BMI270.

Is there a simple example I could take a look at for implementing an interrupt driven approach using the interrupt lines of the BMI270 that e.g. to send a data ready interrupt (which the device could provide, if configured accordingly) and react by just reading the 16 bit values via SPI? I need the zephyr RTOS for other things in the code, but maybe there is a simple way of implementing the BMI270 interrupt interface without using the BMI270 zephyr driver?

How is the BMI270 interrupt line 1 (that is connected in the schematics) used in the thingy:53 software?

Any help is appreciated!

Regards,

Jens

nRF Connect SDK v2.2.0 on macOS Ventura 13.2.1, Apple M1 Pro
nrf5340 on custom board

Parents
  • Hello again, and thank you for your patience. 

    First of all for some SPI interrupt examples, have a look here

    The cleanest way would probably be to modify the sensor driver, but the easiest would be to add the interrupt pin as an interrupt GPIO, and when triggered add reading the sensor value using sensor_sample_fetch() to a workqueue.

    How is the BMI270 interrupt line 1 (that is connected in the schematics) used in the thingy:53 software?

    Which software are you referring to? I believe it might just be included so that you can use it if you want to, not that we need to use it in one particular use-case.

    Regards,

    Elfving

  • Hi Elfving,

    Thank you very much for your answer. I have thought of using the pins as you suggested before I wrote my post. But I hesitated, because BMI270 will not simply send interrupts, but needs to be configured to do so by setting registers via SPI. I have not tried yet, but I was assuming that I cannot combine the BMI270 driver with the zephyr SPI driver for the same device - or can I?

    As for the Thingy:53 - I was only thinking that you might be using it in some way (or have tried using it), but I did not find any source on the net that uses this BMI270 interrupt line of the nrf5340 and the current device tree file you provide for the sdk does not show any entry for the interrupt (there is one for the first device, but the BMI270 is not set for interrupt in this tree).

    &spi3 {
    compatible = "nordic,nrf-spim";
    status = "okay";
    cs-gpios = <&gpio0 22 GPIO_ACTIVE_LOW>,
    <&gpio1 4 GPIO_ACTIVE_LOW>,
    <&gpio0 24 GPIO_ACTIVE_LOW>;

    pinctrl-0 = <&spi3_default>;
    pinctrl-1 = <&spi3_sleep>;
    pinctrl-names = "default", "sleep";

    adxl362: spi-dev-adxl362@0 {
    compatible = "adi,adxl362";
    spi-max-frequency = <8000000>;
    reg = <0>;
    int1-gpios = <&gpio0 19 0>;
    };

    bmi270: spi-dev-bmi270@1 {
    compatible = "bosch,bmi270";
    status = "disabled";
    spi-max-frequency = <8000000>;
    reg = <1>;
    };

    ...

    That was the reason for my question for a BMI270 example - I thought, maybe there might be something you plan to implement in the next version or you have some unofficial example code I could take a look at...

    Now, what's left of my question is:

    Do I have to abandon the BMI270 driver completely, if I need to use SPI communication to set registers in the device that is not supported by the device's driver, or can I mix drivers (pure SPI with the device specific one) on the same device? How would I configure that in the device tree?

    Thanks for your comments.

    Regards,

    Jens

  • Hi Elfving,
    I took a look at the BMI270 driver code and used that device specific knowledge to write my own little functions to set the needed registers etc.. and I am using the Standard GPIO-interrupt as you suggested. So my code works for now. But still it would be great, if these functions would officially be exposed through the attributes you can set in the sensor driver in some later version of zephyr and the SDK.

    Thanks a lot for your support. I think this ticket can be closed now.

    Regards, Jens

  • Great!

    Glad to hear that it got solved, and I'll forward this request to the relevant people.

    Regards,

    Elfving

  • Hey,

    would it be possible for you to share your solution for interrupt handling with BMI270?

Reply Children
  • In case you don't get a response here MatiM, feel free to open a new ticket for this. We'll be happy to help.

    Regards,

    Elfving

  • Hi MatiM,

    I cannot share the full code with you, but some snippets and the concept, I think. Currently I am running it unter nRF Connect SDK v2.4.0 - and I have not checked, if any new version of the driver now is supporting the interrupts.

    So her are the snippets of my code (from a test version) - with everything referencing my project removed - so there are some includes removed and some short specifics of the code, but I hope it is still a guide helping you along with all related to interrupt processing included...

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    #include <zephyr/kernel.h>
    #include <zephyr/drivers/gpio.h>
    #include <zephyr/drivers/spi.h>
    #include <zephyr/drivers/sensor.h>
    #include "BMI270.h"
    #include "leds_IO_power.h"
    // setup GPIO-PIN for BMI270 interrupts
    #define GPIO_BMI270_INT1 12
    #define GPIO_BMI270_INT2 28
    // setup some structs for BMI270 interrupt callbacks
    static struct gpio_callback BMI270_int1_cb_data;
    static struct gpio_callback BMI270_int2_cb_data;
    // counters increased by the interrupts, decreased by the reaction
    atomic_t BMI270_int1_cnt; // atomic avariables are always initialized to zero
    atomic_t BMI270_int2_cnt; // atomic avariables are always initialized to zero
    // store reference to sensor device
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    The easiest way to use this in a test, would be to call "setup_bmi270" and then "wait_for_drdy" in a loop and "read_bmi270_data". On the HW side you would need to connect the BMI270 interrupts to the defined pins and configure those accordingly and you need to setup "Bosch_bmi270" for use with SPI in the device tree, of course.

    I hope, this is of some help to you.

    Regards,

    Jens

  • Thank you very much :D