I2C: Delay() between Wire.beginTransmission() and Wire.endTransmission()

Hi,
I am currently looking at some I2C code for a display and wonder if a delay() between Wire.beginTransmission() and Wire.endTransmission() makes any sense. Looking at the docs it looks like bytes are sent out after the Wire.endTransmission() command is executed. Or do I misunderstand something?

      Wire.beginTransmission ( _i2cAddress );
      Wire.write ( DISP_CMD );
      Wire.write ( FUNC_SET_TBL0 ); // Function set: 8 bit, 2 line display 5x8, funct tab 0
      delay ( _cmdDelay );
      Wire.write ( RAM_WRITE_CMD + (PIXEL_ROWS_PER_CHAR * char_num) );
      _status = Wire.endTransmission ();

Thanks in advance,

Anguel

I am currently looking at some I2C code for a display and wonder if a delay() between Wire.beginTransmission() and Wire.endTransmission() makes any sense.

No, it simply shows that the author of the code doesn't know how the Arduino I2C subsystem works.

anguel:
Looking at the docs it looks like bytes are sent out after the Wire.endTransmission() command is executed.

That is correct. But I would use the word "when" rather than "after"

...R

Thanks a lot, it's actually from a widely used LCD library, e.g. used here:
https://github.com/NeelsKruger/Water-Level-Sensor/blob/master/fw/ST7036.cpp
This code does not appear in all but in some cases.

I am actually trying to port the code to STM32CubeIDE and stumbled upon this. I also looked around and watched some Arduino videos on Youtube but nobody actually explained that detail. I think in one of the most watched videos even the author said that his transfers did not complete sometimes but probably forgot to call endTransmission().

Thank you, I have made an issue.
The Wire library is used in a wrong way a lot (click).
You can read my pages about the Wire library: Home · Koepel/How-to-use-the-Arduino-Wire-library Wiki · GitHub.

@Koepel: a DUE board (main uc is an 32-bit ARM Sam3x) will not behave properly to the Arduino Wire library for multiple reasons.

There is no glitch filtering (unlike most if not any AVR uc), no slope control, is multi-Master compliant (may be an issue) and last but not least (extract from page 715 of Sam3x datasheet):
When a single data byte read is performed, the START and STOP bits must be set at the same time, i.e. send a STOP before reading the data byte.
When a multiple data byte read is performed, the STOP bit must be set after the next-to-last data received, i.e. before the last data byte to be read.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.