05-14-2019 05:16 PM
We are using STM32F091 controller .Used BSEC_1.4.7.2_Generic_Release_20190122\algo\bin\Normal_version\gcc\Cortex_M0 library.
config and previous state are not saved in volatile memory ,we were just returing 0 in the return statement of that function.
We are getting the following readings .
Temp: 32 Humi: 100 Press: 91679 IAQ: 0 GAS:0
Temp: 32 Humi: 100 Press: 91679 IAQ: 0 GAS:0
Temp: 32 Humi: 100 Press: 91681 IAQ: 0 GAS:0
Temp: 32 Humi: 100 Press: 91681 IAQ: 0 GAS:0
Temp: 32 Humi: 100 Press: 91683 IAQ: 0 GAS:0
Temp: 32 Humi: 100 Press: 91683 IAQ: 0 GAS:0
Temp: 32 Humi: 100 Press: 91684 IAQ: 0 GAS:0
05-14-2019 05:42 PM
Hello,
I faced a 'similar ' problem but with esp8266. The problem was on my side and was on the way I coded the i2c read and write functions.
I was using some i2c functions which was working for bme280 and reused them for bme680 thinking they will work, but they don't.
So my advice would be to check that you read and write data through i2c as specified by Bosch for BME680.
05-15-2019 08:01 AM - edited 05-15-2019 08:10 AM
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;
}
05-15-2019 09:21 AM - edited 05-15-2019 09:40 AM
Ok, but you should check exactly what functions HAL_I2C_Mem_Read() et HAL_I2C_Mem_Write() are doing...
And yes, you are right I2C functions for bme280 and bme680 are identical.
I guess I did something wrong in coding these functions for bme280 and despite it was anyway working but not anymore when using bme680. And I think my error came from the bme280 data sheet where multiple writes are coded like:
slave address, reg address, reg data, reg address, reg data, reg address, reg data, ...
But you should implement:
slave address, reg address, reg data, reg data, reg data, ...
Hope it helps...