BME680 sensor
Posted: 23 Jul 2023, 16:53
Hi,
I am trying to get the chip ID of the BME680 sensor on my NuMaker_IoT_M487 board using the hardwired I2C interface.
I have tried both 7bit & 8bit addressing in a simple I2C C++ example. I cannot read the ID properly. I only get 0x00.
What am I doing wrong, please?
Code snippet:
#include "mbed.h"
I2C i2c(I2C_SDA , I2C_SCL );
// Set to BME680 sensor I2C address
const int addr7bit = 0x76; // 7 bit I2C address
const int addr8bit = 0x76 << 1; // 8bit I2C address
int main() {
char cmd=0;
char result=0;
while (1) {
cmd = 0xD0;
i2c.write(addr7bit, &cmd, 1);
i2c.read (addr7bit, &result, 1);
printf("BME68X_CHIP_ID 7bit = %hhx\n", result);
wait_us(500000);
cmd = 0xD0; //CHIP_ID
i2c.write(addr8bit, &cmd, 1);
i2c.read (addr8bit, &result, 1);
printf("BME68X_CHIP_ID 8bit = %hhx\n", result);
wait_us(500000);
}
}
I am trying to get the chip ID of the BME680 sensor on my NuMaker_IoT_M487 board using the hardwired I2C interface.
I have tried both 7bit & 8bit addressing in a simple I2C C++ example. I cannot read the ID properly. I only get 0x00.
What am I doing wrong, please?
Code snippet:
#include "mbed.h"
I2C i2c(I2C_SDA , I2C_SCL );
// Set to BME680 sensor I2C address
const int addr7bit = 0x76; // 7 bit I2C address
const int addr8bit = 0x76 << 1; // 8bit I2C address
int main() {
char cmd=0;
char result=0;
while (1) {
cmd = 0xD0;
i2c.write(addr7bit, &cmd, 1);
i2c.read (addr7bit, &result, 1);
printf("BME68X_CHIP_ID 7bit = %hhx\n", result);
wait_us(500000);
cmd = 0xD0; //CHIP_ID
i2c.write(addr8bit, &cmd, 1);
i2c.read (addr8bit, &result, 1);
printf("BME68X_CHIP_ID 8bit = %hhx\n", result);
wait_us(500000);
}
}