Bosch Sensortec Community

    Showing results for 
    Search instead for 
    Did you mean: 

    BMI270 reading of fifo data via SPI working in zephyr

    BMI270 reading of fifo data via SPI working in zephyr



    I am developing a custom board with nrf5340 SoC (nrfConnect SDK/zephyr) communicating with BMI270 via 8 MHz SPI. From BMI270 side I only need the high quality data, no detection algo or anything else.

    The only thing I cannot get to work so far is reading the content of the FIFO.

    The entire firmware works without FIFO already (interrupts, data readout, readout and configuration of all registers) - so, if I would not sometimes loose a frame (due to a variation in timing within my algo), I would not really need the FIFO to work but stay completely synchronous. Since the BMI270 implementation in zephyr is kind of rudimentary not fulfilling all my needs, I am directly reading and writing registers (single byte or multibyte) using the lower level functionality given in the zephyr driver source (see below).

    Now I am at the point, that I can setup FIFO mode: I have headerless dataframes of 12 byte (acc and gyr), so the FIFO length nicely goes up in steps of 12... when the FIFO is full, interrupt 2 is triggered fine and the length stays the same from then on.

    BUT: no matter when and with how many bytes I try to read the FIFO data gegister - I get strange results that seem to have nothing to do with the sensor data... but I do not get any error.

    => I have seen, that there are some variants of the configuration file (I am using the "basic" version, implemented in the zephyr driver so far).

    Is the version I use made for FIFO use? It looks like there is a different one used at least in some (but seemingly not all) BMI270 samples published by BST.

    => Is there a "low level" sample for reading from the FIFO Data register via SPI using e.g. the Bosch Sensortech code in bmi270_spi.c

    static int bmi270_reg_read_spi(const union bmi270_bus *bus, uint8_t start, uint8_t *data, uint16_t len)

    The method implemented there is what I use successfully for all other register reads so far...

    => Is the method for reading Data from the FIFO data register different from other registers?

    Thank you very much for any help on this!


    3 REPLIES 3

    Community Moderator
    Community Moderator

    Hi mshape,

    Thanks for your inquiry.

    All configuration files of BMI270 support FIFO, the way to read FIFO data is same. Reading FIFO data is different from reading register RAW data. You can read register RAW data at any time, but for reading FIFO data, you must ensure that the FIFO data is read periodically to prevent it from becoming full. For example, if you set a 100 Hz ODR with 12 bytes of headless FIFO data, then every 10ms, The length of the FIFO will increase by 12 bytes, which is one frame of data. If the FIFO data has not been read, The length of the FIFO will increase at a rate of 12 bytes per 10ms until it reaches a length of 2KB.
    This is official example of BMI270 that you can refer to them and migrate them to your platform.

    Dear BSTRobin,

    thank you very mch for your reply. I am aware, that I can only read data, when it is available, and that I see wether data is in the FIFO by reading the length register - which I can perfectly do (I  can get FIFO full interrupts and everything else I need to react).The only thing not working is using the standard register read function to retrieve this data from the FIFO-Data register. I assume something needs to be changed in the structures passed to the bmi270_reg_read_spi function.

    It would be of great help, if you would be able to provide the parameters necessary to read 12 bytes of data with this function (in case data is available, of course).

    I assume that something has to be arranged within the  bmi270_bus parameter (union/structure) so that I can really read 12 bytes from this register. 

    So far I can read 12 consecutive registers in one call to that function with normal registers without problem (eg. the data registers of the sensor channels) and receive the data as expected in the uint8_t *data buffer while calling the function with the FIFO-Data register in parameter start, I get 12 bytes into the buffer (and no error), but the data shows no relationship to any sensor data read from the Data registers...

    I do not understand, why this is so - could there be a diffence "below" the level of this function, that needs to be parameterized differently?

    I will try to look at the sample you suggested, but I have tried to understand the sources of some other samples before writing my request ... and found out, that on the level of the samples I need to dive into the driver API sources ... and there I have trouble to fully understand the inner structure of the code of the zephyr driver. Unfortunately all samples using FIFO so far were using COINES at one point. There is no FIFO-API-read-function in the zephyr driver of BMI270 as far as I have found out so far.

    Thanks again for any further clues.

    Regards, mshape

    Hi BSTRobin,

    I finally understood the problem - it lies within the zephyr driver for BMI270 - actually directly in the function bmi270_reg_read_spi. This function does not use the burst read functionality of the sensor, but emulates a burst read by reading single registers in a loop with INCREASING address very inefficiently. Therefore it cannot be used for a single register read of multiple sequential bytes. It can very easily changed to burst read - I just was interpreting the rather (unnecessarily?) complex way it was implemented to be necessary. I stll do not understand, why it has been implemented in this way in the zephyr driver, but after my changes for my implementation it works now.

    => so: source of problem understood and solution implemented => high speed and works fine now!