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:

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


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 -->

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.write((uint8_t)0x04); // start at address $02
    Wire.write(displaybuffer[2] & 0xFF);
    Wire.write(displaybuffer[2] >> 8);


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(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