pasko-zh / brzo_i2c

Brzo I2C is a fast I2C Implementation written in Assembly for the esp8266
GNU General Public License v3.0
244 stars 47 forks source link

Not working with HTU21 #5

Closed loewexy closed 7 years ago

loewexy commented 8 years ago

I am failing to get your lib to work with the HTU21 Temperature/Humidity sensor. I am not quite shure if this is a problem with the lib or with my code. I always get a return code of 2 when finishing the transaction.

#include "brzo_i2c.h"

unsigned char buf[10];

void setup() {

  Serial.begin(115200);

  Serial.println("Beginning application");

  brzo_i2c_setup(4,5,20000);

  brzo_i2c_start_transaction(0x80, 100);
  buf[0] = 0xE7;
  brzo_i2c_write(&buf[0], 1, true);
  brzo_i2c_read(&buf[1], 1, false);
  unsigned char returnCode = brzo_i2c_end_transaction();

  Serial.println(returnCode, HEX);
  Serial.println(buf[1], HEX);
}
pasko-zh commented 8 years ago

My first impression is the following: According to the datasheet, the HTU21 has a fixed i2c address of 0x40: "... I²C header consist of a 7-bit I²C device address 0x40 ..." You can also find it in the adafruit library.

But you are trying to talk to a slave at address 0x80 in brzo_i2c_start_transaction(0x80, 100). You should use brzo_i2c_start_transaction(0x40, 100) instead. Note that brzo_i2c_start_transaction takes the 7-bit slave address, you don't have to shift left the address by yourself, the library takes care of that.

Please let me know, if you were able to read out the User register of your HTU21. paško

loewexy commented 8 years ago

I should have mentioned that I tried both adresses 0x40 and 0x80 in fact I also built a loop cycling through all integers from 0 to 255 with no success.

pasko-zh commented 8 years ago

I assume your hardware setup (pullups etc) is fine and the HTU21 works with the adafruit (wire) library, right? Currently I don't have an HTU21, so I cannot check. And I will be away from tomorrow on (holidays without IoT ;) but when I return, I will check.

loewexy commented 8 years ago

The hardwaresetup should be correct. The Wire Libary did not work correct for me. I viewed the Signals on a scope and there were only two pulses. On on SDA one on SDL but it was no valid I2C. This is the reason I searched for another libary.

pasko-zh commented 8 years ago

brzo i2c is working with HTU21:

I've added an HTU21 example. It outputs the temperature (without CRC checking) every 5 seconds. I had a couple of issues with adafruit's breakout board, please read the readme.

Please note that the current version 1.00 of brzo i2c supports only clock stretching up to 5 msec. I will enhance this to support longer timouts, see issue.. Therefore, get_temp_hold_master(float *t) will lead to brzo error 8, since HTU21 needs up to 50 msec. But I've already changed this in my local version, and I can confirm it is working.

EDIT: Version 1.01 released, supports longer timeouts now.