Giter VIP home page Giter VIP logo

Comments (8)

muenznej avatar muenznej commented on July 23, 2024

Its not working! i get zero readings, but the speed seems to be correct 😄

from brzo_i2c.

muenznej avatar muenznej commented on July 23, 2024

Hmm, i changed the code now in various ways, but nothing helped :(

Maybe i give some information about the hardware i use:

  • I am using a cheapo NodeMcu v2 from an infamous store.
  • I am using the arduino 1.8.5 IDE
    image
  • As far as i can see there are 10k Pull-Ups on both SCL and SDA for the INA219 breakoutboard, that might also be an issue. Nevertheless, its working fine up to 400k with the normal wire.h based libraries.

from brzo_i2c.

pasko-zh avatar pasko-zh commented on July 23, 2024

Hi Jürgen!

Glad to hear that you like my library 😸

Let's find the issue here...

So, it seems your wiring is correct and the sensor works with the wire library.

Looking at the hardware side:

  1. The breakout board has 10K pull-ups, as you already mentioned, and they far too big for higher speeds, see my comments for the HTU21 breakout board. Use additional pull-ups with lower values, can be as low as 1.5 kOhm.

  2. I had a look at the datasheet of the INA219: It seems that it supports i2c fast mode and high speed mode, however not fast mode plus. E.g., on page 10 it says "supports the transmission protocol for fast (1kHz to 400kHz) [...]" and also the table on page 13 states that. Now, since it supports high speed mode as well, normally such ICs can be "overclocked" in fast mode up to 1 MHz—but this really depends on the IC and on the quality of the signals, especially raise times.
    Thus, you may try with 400 kHz first, see if it works and then increase SCL speed.

Looking at the software side:
(I had only a very very short look at your code. And I have not yet checked, when the INA216 needs a repeated start and all those stuff)

What do you mean "it is not working"? Do you get any brzo i2c error codes? Your sample code seems not to catch them, but it is wise to do so ;-)

from brzo_i2c.

muenznej avatar muenznej commented on July 23, 2024

Hi Pasko, thanks for the fast response!

In the meantime I have been "working" on this problem:

  • I changed the 10k PullUps to 2k2 pullups, which should be fine. AND the device is still working with wire, despite my incredible soldering skills 😅

  • the code has been changed too!
    Please take a look at the code if you find time, its not really complex but maybe too long to post here in total.
    The only brzo relevant parts in these methods:

int16_t ICACHE_RAM_ATTR INA219_brzo::readRegister16(uint8_t reg)

and

void ICACHE_RAM_ATTR INA219_brzo::writeRegister16(uint8_t reg, uint16_t val)

I also added

    if (_ecode != 0) // on error
    {
        Serial.println(_ecode);
    }

But it does never return an error, its basically zero all the time!

  • Regarding the datasheet:
    image
    Thats from page 13. I thought it means it does support this HS mode, but the "protocol" is used differently, or do i get this wrong?

I also found some interesting things! The bus itself is working and read and write do work, but some things are just non-sense. Maybe my bitoperations are just wrong?

For example i used:

ina.configure(INA219_RANGE_16V, INA219_GAIN_40MV, INA219_BUS_RES_9BIT, INA219_SHUNT_RES_9BIT_1S, INA219_MODE_SHUNT_CONT);

which sets some registers in the setup part, but when i use the reading code it gives:

Mode:                 Shunt and Bus, Continuous
Range:                32V
Gain:                 +/- 320mV
Bus resolution:       12-bit
Shunt resolution:     12-bit / 1 sample
Max possible current: 0.40 A
Max current:          0.40 A
Max shunt voltage:    0.04 V
Max power:            6.40 W
510029 µs; 510.02899 µs/READ; 0.0000000000000000 mA;0.0000000000 V

As you can see, many parameters are not correct. I think these are default values. (This exact same code works for the wire version perfectly!)

Greetz
Jürgen

from brzo_i2c.

muenznej avatar muenznej commented on July 23, 2024

Ok, i thought about the latest result and i come to the conclusion that if the (default) modes are read out correctly, the read function has to be working. If this would not be the case, the code would throw "unknown" but it does not! This is in agreement with the finding that the settings are defaults, and hence not overwritten by the write command!
Since the Bus is as fast as i set it up, the startup itself also has to be correct. This leaves only

void ICACHE_RAM_ATTR INA219_brzo::writeRegister16(uint8_t reg, uint16_t val)
{
    /*
    uint8_t vla = (uint8_t)val;
    val >>= 8;
    _buffer[1] = (uint8_t)val;
    _buffer[2] = vla;
    brzo_i2c_start_transaction(ADDR, SCL_frequency_KHz);
    brzo_i2c_write(&_buffer[0], 1, true);  // 1 byte, repeat
    brzo_i2c_write(&_buffer[1], 2, false); // 2 byte, no repeat
    */

    /* val = 1011 1111 1001 0110
       val >> 8: 0000 0000 1011 1111
       0xFF = 1111 1111
       (val >> 8) & 0xFF: 1011 1111 // seems to be some implicity typecast to byte
    */
    _buffer[0] = reg;
    _buffer[1] = (val >> 8) & 0xFF;  // high BYTE of DWORD
    _buffer[2] = val & 0xFF;    // low BYTE of DWORD
    brzo_i2c_start_transaction(ADDR, SCL_frequency_KHz);
    brzo_i2c_write(&_buffer[0], 1, true);  // Set Register
    brzo_i2c_write(&_buffer[1], 2, false);  // Write 2Bytes
    uint8_t _ecode = brzo_i2c_end_transaction();

    if (_ecode != 0) // on error
    {
        Serial.println(_ecode);
    }
}

to be faulty. (But i could be wrong with my conclusions as well)

greetz
Jürgen

P.S.: Yes, my comments are confusing and generally reflect the state of my mind regarding this problem ;-)

from brzo_i2c.

muenznej avatar muenznej commented on July 23, 2024

Cool, i did it 👯‍♂️

As i thought the problem was the writing part: The INA219 uses 1 Byte register and 2 Byte values, and it seems that you have to send them at once with a single

  brzo_i2c_start_transaction(ADDR, SCL_frequency_KHz);
   brzo_i2c_write(&_buffer[0], 3, true);  // 1Byte Register + 2Bytes data
   uint8_t _ecode = brzo_i2c_end_transaction();

I will update the code and make it a bit less ugly!

Thanks for your support and the library Mr. Pasko 😄

P.S.: I just tested it for 100k, 400k, 800k, and 1000k with 2k2 resistors and everything works very well.

from brzo_i2c.

pasko-zh avatar pasko-zh commented on July 23, 2024

Cool that it works now! 👍
(my other life keeps me busy from time to time, thus sorry for my late response)

Yes, in the datasheet it states that after sending register pointer address (1), two bytes of data (2) need to be transfered without a START nor STOP between (1) and (2).

Concerning i2c high speed mode: You need different hardware, see here under electrical characteristics. The esp8266 does not support HS mode (you would have to use additional hardware components).

Looking at the code in your last comment, I have the following remarks:

  • Since you are sending 3 bytes from the beginning of _buffer you can simply use brzo_i2c_write(_buffer, 3, false), cf. readme.
  • I haven't seen your full code, but is there a reason why you are using a repeated start? I would not use it! When I look at writeRegister16(.) function it sends register pointer address and then the two bytes of data to stored in that register. Thus, use brzo_i2c_write(_buffer, 3, false)
  • Note: Sending a repeated start and then not continue with any i2c commands may leave the bus stalled! Thus, you have to make sure the last command sent from the master (i.e. esp8266) does not send a repeated start!

from brzo_i2c.

muenznej avatar muenznej commented on July 23, 2024

Since you are sending 3 bytes from the beginning of _buffer you can simply use brzo_i2c_write(_buffer, 3, false)

There are no repeated starts anymore and i amended many parts of the code, and fixed some minor bugs.
It can be found here.

thx
brzo pasko

P.S.: When i add more sensors i ll come back to this issues section i guess 😅

from brzo_i2c.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.