Hi Ochrin, Thank you for reply. But both BME280 and BME680 I2C frames are same. I have used the following function for I2C read and write .Please let me know if any changes to be made in this. /*! * @brief Write operation in either I2C or SPI * * param[in] dev_addr I2C or SPI device address * param[in] reg_addr register address * param[in] reg_data_ptr pointer to the data to be written * param[in] data_len number of bytes to be written * * @return result of the bus communication function */ int8_t bus_write(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data_ptr, uint16_t data_len) { int8_t rslt=0; // ... // Please insert system specific function to write to the bus where BME680 is connected // ... HAL_StatusTypeDef status = HAL_OK; rslt = 0; while (HAL_I2C_IsDeviceReady(&hi2c1, (uint8_t)(dev_addr<<1), 3, 100) != HAL_OK) {} status = HAL_I2C_Mem_Write(&hi2c1, // i2c handle (uint8_t)(dev_addr<<1), // i2c address, left aligned (uint8_t)reg_addr, // register address I2C_MEMADD_SIZE_8BIT, // bme680 uses 8bit register addresses (uint8_t*)(®_data_ptr), // write returned data to reg_data data_len, // write how many bytes 100); // timeout if (status != HAL_OK) { // The BME680 API calls for 0 return value as a success, and -1 returned as failure rslt = (-1); } return rslt; } /*! * @brief Read operation in either I2C or SPI * * param[in] dev_addr I2C or SPI device address * param[in] reg_addr register address * param[out] reg_data_ptr pointer to the memory to be used to store the read data * param[in] data_len number of bytes to be read * * @return result of the bus communication function */ int8_t bus_read(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data_ptr, uint16_t data_len) { int8_t rslt=0; HAL_StatusTypeDef status = HAL_OK; rslt = 0; uint8_t array[28] = {0}; uint8_t stringpos = 0; array[0] = reg_addr; while (HAL_I2C_IsDeviceReady(&hi2c1, (uint16_t)(dev_addr<<1), 3, 100) != HAL_OK) {} status = HAL_I2C_Mem_Read(&hi2c1, // i2c handle (uint8_t)(dev_addr<<1), // i2c address, left aligned (uint8_t)reg_addr, // register address I2C_MEMADD_SIZE_8BIT, // bme680 uses 8bit register addresses (uint8_t*)(&array), // write returned data to this variable data_len, // how many bytes to expect returned 100); // timeout if (status != HAL_OK) { // The BME680 API calls for 0 return value as a success, and -1 returned as failure rslt = (-1); } for (stringpos = 0; stringpos < data_len; stringpos++) { *(reg_data_ptr + stringpos) = array[stringpos]; } return rslt; }
... View more