Why is a delay needed for I2C?

Hi everyone

I was struggling to communicate with my MPU6050 sensor through I2C. It turns out the solution was to add a small delay after setting some of the initial registers:

Wire.begin();

Wire.beginTransmission(MPU_addr);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true);

** delay(1000);**

Wire.beginTransmission(MPU_addr);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr,14,true);
acX=Wire.read()<<8|Wire.read();
acY=Wire.read()<<8|Wire.read();
acZ=Wire.read()<<8|Wire.read();

Now I am wondering, what exactly is the delay needed for? Through some trial and error, I discovered that it consistently needs the same, specific amount of time between starting up and reading in the first values properly.

Thanks for any help you can provide for this question.

(1) There are following sections in an Arduino Sketch:

Global Space
Setup Function Space
Loop Function Space
Users Function Space

(2) Please, put your codes at the appropriate sections of the following 'Blank Arduino Sketch'. This will help us to study your codes and to think over your question.

//---------Global Space-----------

//---end of Global Space

void setup()
{

}

void loop()
{

}

//-----Users Function Space

//----end of user Function Space

(3) Do you agree with the following arrangement of your codes? If not, please do your arrangement to comply with my above request.

#include <Wire.h>
//#include <MPU6050.h>
#define MPU_addr 0x69
MPU6050 mpu;   //device address 0x69 keyed in Librart AD0=LH

void setup()
{
  Serial.begin(9600);
  Wire.begin();

  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);
  Wire.write(0);
  Wire.endTransmission(true);

  delay(1000);

  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);
  Wire.endTransmission(false);

  Wire.requestFrom(MPU_addr, 14, true);
  int acX = Wire.read() << 8 | Wire.read();
  int acY = Wire.read() << 8 | Wire.read();
  int acZ = Wire.read() << 8 | Wire.read();
  Serial.println(acX, HEX);
  Serial.println(acY, HEX);
  Serial.println(acZ, HEX);

}

void loop()
{

}

BillMahooney:
It turns out the solution was to add a small delay after setting some of the initial registers:

delay(1000);

I can't answer your question about why a delay() is needed, but I'd hardly think a 1000ms is "small". In computer terms that's for ever. (I'm pretty sure I saw a fix somewhere just using delay(5).)

If I were you I'd experiment with smaller values and establish the smallest that works reliably.

Why are you changing 0x6B, a power management and clock source register?

Please post ALL the code, using code tags, so we can see what else you are doing to the chip.

Now I am wondering, what exactly is the delay needed for? Through some trial and error, I discovered that it consistently needs the same, specific amount of time between starting up and reading in the first values properly.

Your subject is misleading. If this delay is really needed, your MPU is needing it, not I2C as the interface between them. A lot of sensors need some time to startup and you have to wait before you can read actual values from them.