Page 1 of 1

Reading 16bit BME280 using I2C

Posted: Thu Mar 16, 2017 2:06 pm
by preetam
Hi,

I am trying to read 16bit from register on BME280 using esp idf i2c api's

till now i did the following

Code: Select all

uint8_t coe11,coe21;
uint8_t* coe1=&coe11;
uint8_t* coe2=&coe21;

	int cmd = i2c_cmd_link_create();
        i2c_master_start(cmd);
        i2c_master_write_byte(cmd, BME280_ADDRESS << 1 | WRITE_BIT, ACK_CHECK_EN);
	i2c_master_write_byte(cmd, BME280_ADDRESS << 1 | WRITE_BIT, ACK_CHECK_EN);
	i2c_master_write_byte(cmd, BME280_REGISTER_DIG_T1 , ACK_CHECK_EN);
	i2c_master_stop(cmd);
	ret = i2c_master_cmd_begin(i2c_num, cmd, 1000 / portTICK_RATE_MS);
	
	i2c_cmd_link_delete(cmd);
	    if (ret == ESP_FAIL) {
        return ret;
    }
    vTaskDelay(30 / portTICK_RATE_MS);
	cmd = i2c_cmd_link_create();
	i2c_master_start(cmd);
	i2c_master_write_byte(cmd, BME280_ADDRESS << 1 | READ_BIT, ACK_CHECK_EN);

	i2c_master_read_byte(cmd, coe1, ACK_VAL);
	i2c_master_read_byte(cmd, coe2, ACK_VAL);
	i2c_master_stop(cmd);
	
	ret = i2c_master_cmd_begin(i2c_num, cmd, 1000 / portTICK_RATE_MS);
    i2c_cmd_link_delete(cmd);
	printf("status: %02x\n", coe11);
	printf("status: %02x\n", coe21);

i am getting 00 for both coe11 and coe21

could anyone let me know how to read 16bit from BME280

Re: Reading 16bit BME280 using I2C

Posted: Thu Mar 16, 2017 2:46 pm
by kolban
A quick read of the BME280 data sheet claims that it is compatible with the BMP280 which is compatible with the BMP180. Here is a video on using the BPM180 ...

https://www.youtube.com/watch?v=LpVuxEXq9ko

with some sample fragment code here ...

https://github.com/nkolban/esp32-snippe ... 20pressure

Do you have a $10 logic analyzer? My strongest recommendation if you don't have one is to get one. Without actually being able to "see" what is happening on the I2C or SPI bus, there isn't much to say.

Re: Reading 16bit BME280 using I2C

Posted: Thu Mar 16, 2017 2:56 pm
by preetam
Thank you for the reply.
will surely check on this and also on logic analyzer.

Regards
Paul

Re: Reading 16bit BME280 using I2C

Posted: Sat Mar 18, 2017 6:25 pm
by onehorse
I use the Arduino IDE but have no trouble reading the BME280 with the ESP32:

https://github.com/kriswiner/ESP32/blob ... TSleep.ino

Re: Reading 16bit BME280 using I2C

Posted: Sat Mar 18, 2017 7:20 pm
by Hans Dorn
The arduino libraries are always a good starting point to have a look at a working implementation :)

https://github.com/espressif/arduino-es ... -hal-i2c.c

Cheers