Bosch Sensortec Community

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

    BMA400 API Driver missing handle of dummy byte

    BMA400 API Driver missing handle of dummy byte

    cyril_praz
    New Poster

    If we look the picture below we can see that the last sample retrieved from the FIFO is not  read completely.

    BMA400_fifo_issue.PNG

     

    I have investigated and see that for the function bma400_get_regs the number of dummy byte is added to the actual number of byte we want to read:

     

     

    int8_t bma400_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint8_t len, const struct bma400_dev *dev)
    {
        int8_t rslt;
        uint16_t index;
        uint16_t temp_len = len + dev->dummy_byte;
        uint8_t temp_buff[temp_len];
    
    ...
    
            /* Read the data from the reg_addr */
            rslt = dev->read(dev->dev_id, reg_addr, temp_buff, temp_len);
    ...
    }

     

     

    but this is not done into the function read_fifo:

     

     

    static int8_t read_fifo(const struct bma400_fifo_data *fifo, const struct bma400_dev *dev)
    {
        int8_t rslt;
        uint8_t reg_data;
        uint8_t fifo_addr = BMA400_FIFO_DATA_ADDR;
    
       ...
                rslt = dev->read(dev->dev_id, fifo_addr, fifo->data, fifo->length);
       ...
    }
    int8_t bma400_get_fifo_data(struct bma400_fifo_data *fifo, const struct bma400_dev *dev)
    {
        int8_t rslt;
        uint8_t data;
        uint16_t fifo_byte_cnt = 0;
        uint16_t user_fifo_len = 0;
    
        ...
            /* Reading the FIFO length */
            rslt = get_fifo_length(&fifo_byte_cnt, dev);
            if (rslt == BMA400_OK)
            {
                   ...
                    user_fifo_len = fifo->length;
                    if (fifo->length > fifo_byte_cnt)
                    {
                        /* Handling case where user requests
                         * more data than available in FIFO
                         */
                        fifo->length = fifo_byte_cnt;
                    }
                    ...
                    rslt = read_fifo(fifo, dev);
           }
           ...
    }

     

     

    by adding the number of dummy bytes into fifo_byte_cnt the problem was fixed.

     

    This issue is present on the commit: https://github.com/BoschSensortec/BMA400-API/commit/f87f5ec1b91db7a9f7fb55e777d2a3d8ab99d7db

     

    4 REPLIES 4

    FAE_CA1
    Community Moderator
    Community Moderator

    Hi,

    Thank you for your feedback. We will investigate the BMA400 Driver on the Github. If it is true that the first dummy byte is missing when reading FIFO data through SPI interface, then we will get back to you.

    Thanks.

    Hello,

    Do you have any news?

    Best regards,

    Cyril Praz

    zgg
    Long-established Member

    Hello

    Just to check a couple of things to better help you.

    1) what is the ODR used for the issue concerned?

    2) are you using i2c/spi to talk to the sensor?

    3) did you enable fifo_time_en in FIFO_CONFIG0 (register 0x26), when reading FIFO, it's suggested to enable fifo_time_en bit so that you get the sensortime frame which is an indication the sensor fifo is completely read out

    The FIFO is automatically filled even during the time when you are reading out the samples from it, so it could be possible that: if the reading out is on the verge of a new sample arrival, after the read out, the FIFO is not drained compeletely, this is usually the case when: the system is very busy, and read out of the FIFO is delayed long after latest sample is available, or if the ODR is high and a very slow bus is used(e.g.: 100khz I2C), so to address this kind of tricky timing issue (from the host), the driver tries to overread a bit.

    ``

    if ((fifo->fifo_time_enable == BMA400_ENABLE) &&
    (fifo_byte_cnt + BMA400_FIFO_BYTES_OVERREAD <= user_fifo_len))
    {
    /* Handling sensor time availability*/
    fifo->length = fifo->length + BMA400_FIFO_BYTES_OVERREAD;
    }

    ``

    BMA400_FIFO_BYTES_OVERREAD is currently defined as 25, please note that it's a number with tradeoff between traffic size and changes of improving the issue, if this number is very big, then you can almost guarrantee that everytime you can drain the fifo completely, but the overhead on the bus traffic is higher, vice versa.

    and the number 25 has already covered the dummy byte.

     

    but this overread only is applied when the fifo_time_en bit is set.

     

    Hope this helps.

     

     

    FAE_CA1
    Community Moderator
    Community Moderator

    Hi Cyril Praz,

    Is the issue resolved? If yes, then please click "Accept as Solution" button to close this case.

    Thanks.

    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