Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    BMI270 reading of fifo data via SPI working in zephyr

    BMI270 reading of fifo data via SPI working in zephyr

    mshape
    Member

    Hi,

    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!

    mshape

    3 REPLIES 3

    BSTRobin
    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 https://github.com/boschsensortec/BMI270_SensorAPI 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!

    Thanks,

    mshape

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist