Adafruit_LEDBackpack

Hallo,
I am using "Adafruit_7-Segment LEDBackpack" with "Arduino-UNO". Everything works perfect.

But just need to know about "Wire.endTransmission()" its in "Adafruit_LEDBackpack.cpp" file . coz, I want to do same project with "efm8bb10f8g" microcontroller.

So, Wire.endTransmission() --> goes in "wire.cpp" file and calls

uint8_t TwoWire::endTransmission(void) ---> and then calls

uint8_t TwoWire::endTransmission(uint8_t sendStop)
{......


As I understood, its only for sending the "STOP" bit through the BUS to terminate the communication and make the BUS free.
see more: http://www.arduino.cc/en/Reference/WireEndTransmission

Now, my question is, is it necessary to send "STOP" bit after every data send ? Why ?

Thanks

Of course.

Because that is part of the protocol.

Is it not possible, to send several times data and then send "STOP" bit ?

see in the frame on this web -->
http://images.google.de/imgres?imgurl=http%3A%2F%2Fwww.eeworld.com.cn%2Fuploadfile%2Fmcu%2Fuploadfile%2F201202%2F20120221095807728.jpg&imgrefurl=http%3A%2F%2Fele-tech.com%2Fhtml%2Farm-dsp-multicomputer-i2c-communication-cipher-scheme-on-the-basis-of-linux-operating-system.html&h=134&w=413&tbnid=pBk4gnB8IzDO1M%3A&docid=gbUgGGVrJCfh4M&ei=N9IhV5ikJ4H8sQH6tKZ4&tbm=isch&iact=rc&uact=3&dur=1110&page=1&start=0&ndsp=12&ved=0ahUKEwjYm6aP_bDMAhUBfiwKHXqaCQ8QMwghKAIwAg&bih=639&biw=1152


Start bit--> Salve Address--> R/W -->A-->Data-->A-->Data-->A-->Stop bit

That is one of the most ridiculous Web links I have ever seen!

It appears to be one version of explanation of the I2C protocol, but not the usual one.

You are correct about sending several successive data frames in one transaction, but as far as I can tell, the only way to cease sending frames without a STOP code is to stop the clock. If you do that, it will cause a time out fault and yes, you are locking up the bus in the meantime.

So what would be the point?

HamingBird, you are correct. it is not necessary to end the i2c bus connection after each i2c data byte transfer.

Many libraries including the the adafruit backpack library do this.

Have a look at the writeColon() function as one example of this:

void Adafruit_7segment::writeColon(void) {
    Wire.beginTransmission(i2c_addr);
    Wire.write((uint8_t)0x04); // start at address $02
    
    Wire.write(displaybuffer[2] & 0xFF);
    Wire.write(displaybuffer[2] >> 8);

    Wire.endTransmission();
}

The value is that it increases performance because you don't have to go through the extra overhead of start and end bus negotiations between each byte transfer.
It can also reduce overall i2c bus utilization and reduce CPU overhead.

The Wire library supports multiple write() functions.

write(data);
write(ptr, count);

Ideally if you have all the bytes ready in a buffer you can use the write() call that allows passing a pointer to the data buffer and a count.
If not, you can call the other version for write() to send the bytes 1 at a time before you call the endTransmission() function.

Just be aware that the write() that uses a count can not send more than 32 bytes a time.


I do exactly what you are talking about in a hd44780 LCD backpack library I've written.
For something like a hd44780 LCD which uses a PCF8574 of MCP32008 i/o expander it means you can send out multiple i2c bytes to the i/o port in the same bus acquisition.

I do this for sending each lcd byte to the hd44780 display through the i2c i/o expander as each lcd byte being sent to the LCD requires sending multiple i2c bytes to the i/o expander.

Each lcd byte sent to the display must be broken into nibbles and each nibble requires sending two i2c data bytes to the i/o port.
So each lcd byte sent to the hd44780 interface needs 8 i2c bytes sent to the hd44780 i/o port.
Each i2c byte could be sent separately but instead, I grab the bus, send the 8 i2c bytes, and let go.

--- bill