Reading 16bit BME280 using I2C

preetam
Posts: 49
Joined: Thu Jan 26, 2017 2:31 pm
Location: Germany

Reading 16bit BME280 using I2C

Postby preetam » Thu Mar 16, 2017 2:06 pm

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

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Reading 16bit BME280 using I2C

Postby kolban » Thu Mar 16, 2017 2:46 pm

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.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

preetam
Posts: 49
Joined: Thu Jan 26, 2017 2:31 pm
Location: Germany

Re: Reading 16bit BME280 using I2C

Postby preetam » Thu Mar 16, 2017 2:56 pm

Thank you for the reply.
will surely check on this and also on logic analyzer.

Regards
Paul

onehorse
Posts: 70
Joined: Mon Feb 15, 2016 1:35 am

Re: Reading 16bit BME280 using I2C

Postby onehorse » Sat Mar 18, 2017 6:25 pm

I use the Arduino IDE but have no trouble reading the BME280 with the ESP32:

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

Hans Dorn
Posts: 62
Joined: Tue Feb 21, 2017 2:21 am

Re: Reading 16bit BME280 using I2C

Postby Hans Dorn » Sat Mar 18, 2017 7:20 pm

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

Who is online

Users browsing this forum: Baidu [Spider] and 121 guests