Bosch Sensortec Community

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

    BME680 with STM32F103C8

    Community Moderator

    Re: BME680 with STM32F103C8

    I don't have access to the documentation of your I2C library, but you may want to check how the implementation of I2C_Send7bitAddress() handles the slave address alignement.

    The BME680 in I2C mode expects the Save Address to be left aligned, with the LSB as R/W bit:

    bme680_i2c_read_protocol.JPG

    Here is an example of chip ID read I2C transaction (note that in the Analyzer Settings, Address Display is set to "7-bit, address bits only"):

    bme680_i2c_chip_id_read.JPG

    With your library, you may need to manually shift the slave address, e.g.:

     

    I2C_Send7bitAddress(I2C1, (dev_addr << 1), I2C_Direction_Transmitter); // Send slave address for write
    //[...]
    I2C_Send7bitAddress(I2C1, (dev_addr << 1), I2C_Direction_Receiver); // Send slave address for read

     

    Community Moderator
    Community Moderator

    Re: BME680 with STM32F103C8

    In your screenshot, the initial state of the SCL line is not correct, the start condition is not shown.

    Also the BME680 address is 0x76, but that is a 7-bit address. If you change your logic analyzer display settings, you would see that the i2c address that you are currently trying to access is 0x3B.

    The combination of these 2 issues, make it look like the BME680 is not answering. I believe the root cause of your issue is a misconfiguration of the i2c master.
    Highlighted
    Member

    Re: BME680 with STM32F103C8

    Thanks guys, I already found where problem was. It is slave address as you wrote. Yesterday, after posting screenshot from LA, I tried to set  gas_sensor.dev_id = 0xEC and  I recieved ack from BME. And now I see your answers for the same thing. In my code I am using  STM32F10x_StdPeriph_Lib_V3.5.0, and in library  I2C_Send7bitAddress realized in such way:

    /**
      * @brief  Transmits the address byte to select the slave device.
      * @param  I2Cx: where x can be 1 or 2 to select the I2C peripheral.
      * @param  Address: specifies the slave address which will be transmitted
      * @param  I2C_Direction: specifies whether the I2C device will be a
      *   Transmitter or a Receiver. This parameter can be one of the following values
      *     @arg I2C_Direction_Transmitter: Transmitter mode
      *     @arg I2C_Direction_Receiver: Receiver mode
      * @retval None.
      */
    void I2C_Send7bitAddress(I2C_TypeDef* I2Cx, uint8_t Address, uint8_t I2C_Direction)
    {
      /* Check the parameters */
      assert_param(IS_I2C_ALL_PERIPH(I2Cx));
      assert_param(IS_I2C_DIRECTION(I2C_Direction));
      /* Test on the direction to set/reset the read/write bit */
      if (I2C_Direction != I2C_Direction_Transmitter)
      {
        /* Set the address bit0 for read */
        Address |= OAR1_ADD0_Set; // Address |= 0x0001
      }
      else
      {
        /* Reset the address bit0 for write */
        Address &= OAR1_ADD0_Reset; // Address &= 0xFFFE
      }
      /* Send the address */
      I2Cx->DR = Address;
    }

    Now I am  put in this function 0xEC address for writing to and 0xED for reading from BME.  

    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