Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BME680 wrong values with shared I2C

    BME680 wrong values with shared I2C

    Jules
    New Poster

    Hi everyone,

    I have a problem with my BME680 returning wrong values. I'll try to explain how it works and hope you can help me to solve it :

     

    On my embedded card, there is a chip (STM32) connected to the BME680 component in order to get humidity/temperature/pressure measures.

    The communication bus is I2C and the BME680 is also sharing its bus with the card's battery, sending % of battery to the CPU everytime it changes.

     

    When BME680 is the only one using the I2C bus (e.g battery info harvest is not activated), BME680 is sending good values to the CPU.

    But the problem appears when the battery and the BME680 cohabit. When they are sharing the I2C bus, BME680 values sent to the CPU are aberrant (for example, -300°C, 0% humidity, 200hPa).

     

    After reading the datasheet, I saw that BME680 needed to send its measures precisely every X seconds (here 3 seconds). Hense I decided to implement a state machine to force the BME680 to send its results every time he has to, and the battery to hold the I2C bus the rest of the time. But it didn't work.

     

    I read few subjects in this forum about BME680 problems but I never saw one acting like this : functionning alone, disfunctionning when it cohabits with another component in the same I2C Bus.

    I don't know if you already encoutered this problem, if you have any ideas or the solution to make it work please let me know.

     

    Thank you for your time.

    Sincerely,

     

    Jules

    3 REPLIES 3

    BSTRobin
    Community Moderator
    Community Moderator

    Hello Jules,

    When there are multiple I2C slaves on the bus, you can use lock to guarantee exclusive access. When the data of bme680 needs to be read, the lock is enabled. When the data of bme680 was read out, then released the lock. Access to another I2C slave was allowed only if the lock is released.

    Hey,

    In my code, I already use HAL library with I2C functionnality. Hense, in the functions I use to write on the I2C bus, the macro  __HAL_UNLOCK(hi2c) and  __HAL_LOCK(hi2c) are used. I tested to implement these macro directly in the code and indeed using the macro locks the I2C bus.

    Unfortunately, locking the process and unlocking it after the read of the I2C bus is already done by HAL I2C library's functions and doesn't work.

    But your answer made me think about something : wouldn't it be efficient to use a semaphore?

    I've already tried to implement it and it still didn't worked. It's like both battery and BME680 never access the bus at the same time but still the BME680 doesn't like to have a friend on the same I2C bus.

    One thing I have to say is BME680 and battery are on the same thread. First, they were separated in 2 threads (still didn't work) but we grouped them to optimize heap memory.

     

    I'm open to new suggestions.

     

    Sincerely,

     

    Jules

    BSTRobin
    Community Moderator
    Community Moderator

    Hello Jules,

    The most important point is the atomic operation of I2C read and write. It must be ensured that only one slave (bme680 and battery) can be read or written at the same time.

    You could run you code, and capture I2C waveform to check if the actual communication is what you expect.

    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