Closed jlohmoeller closed 7 years ago
Well, we have three different levels: The Adafruit Library and the underlaying wire Library and last but not least the i2c communication of the sensor. So, debugging means understanding all three of those levels. I had very quick look at the Adafruit Library and the spec of the bosch sensor and then your modified parts. It's hard to tell what is going wrong, especially since I don't have the sensor, so I cannot check i2c timings with the scope. I will have a further look at it, probably next week. ps: When "migrating" from wire Library to brzo_i2c, I would start with having a look at the i2c communication of the sensor and not the actual calls to the wire Library. So, some of the sensors need clock stretching, burst read or .... So, it is this combination of i2c read/writes and the timing which is the crucial thing.
Hmmm, without the i2c device it is hard to tell where the problem is...
The only thing I could think of: According to the datasheet, section 6.2.1 the i2c master should send: START, Slave address, register address, register data, STOP. Now, in your code you are writing register and register data seperately, i.e. with two brzo_i2c_write
calls. The first call brzo_i2c_write(i2c_buffer, 1, false);
will send a STOP at the end. So, the i2c device "sees" this as the end of a write transaction, cf. figure 9 in the datasheet. So, I would combine the writes and thus avoiding the STOP between register address and register data.
I would do brzo_i2c_write(i2c_buffer, 2, false)
Thank you for your answer, brzo_i2c_write(i2c_buffer, 2, false)
did the trick.
I assumed the STOP is sent when transmission is closed :(
I am failing to get this library working with a BME280 Environment Sensor. I moved from the Arduino Wire library to brzo_i2c since the AMS iAQ-Core air quality sensor did not work correctly with the builtin Wire lib. I took the code from Adafruit and changed the parts handling I2C communication.
Original Code:
My adapted version: (except leaving out the SPI stuff and
Wire.begin()
the rest of the code has not changed)I get the following output when requesting the registers holding measured data:
For me it seems like reading works, but the BME280 does not measure and hence does not fill its registers with correct values. According to the datasheet
800000
is the default value. Writing (1) should force measurement and after this the registers should be filled with data. I guess there is something wrong in thewrite8(...)
method.If I change back to wire (by copy-pasting the methods shown above), the BME280 works fine (so there is no hardware fault)...
Maybe an example in the Wiki comparing Arduinos Wire-lib and brzo_i2c would be helpful :)