I2C issues

   i2cWrite(IMUAddress,0x6B,0x00); // disable sleep mode  

  while (i2cRead(IMUAddress,0x75,1)[0] != 0x68)  // confirms that it is IC2 address 68
   {
          digitalWrite(4, HIGH);
          delay(250);
          digitalWrite(4, LOW);
          delay(250);
    }
void i2cWrite(uint8_t Address, uint8_t registerAddress, uint8_t data){

  Wire.beginTransmission(Address);  // address 68
  Wire.write(registerAddress);   // the address
  Wire.write(data);
  Wire.endTransmission(); // Send stop

}
//////////////
uint8_t* i2cRead(uint8_t Address, uint8_t registerAddress, uint8_t nbytes) {
  uint8_t data[nbytes];  

  Wire.beginTransmission(Address);
  Wire.write(registerAddress);
  Wire.endTransmission(false); // Don't release the bus
  Wire.requestFrom(Address, nbytes); // Send a repeated start and then release the bus after reading
  for(uint8_t i = 0; i < nbytes; i++)
    data[i] = Wire.read();
  return data;
}

The I2C write seems to works fine, it never holds up the program, although it might just time out properly.

When the 6050 is not connected to I2C it properly times out on the readI2C, when the 6050 is connected the whole program stalls on Wire.endTransmission(false) and will never move past it. I’ve confirmed this by inserting a digitalWrite(4, HIGH) into various parts of the code so I would know where it was having issues.

They didn’t change the wire.h library in the last year did they?

This exact code works fine on a different board that was made a year ago.

Using a custom made Leonardo, with a proper I2C level shifter chip, all other I2C tests have worked without issue so far although I have no other chips that require register reading/writing.

Why does i2cRead return a global array?

A local array, you mean?

[quote author=Nick Gammon link=msg=2019266 date=1419806964] A local array, you mean? [/quote] I missed that. That is why, in my opinion, the curly brace does NOT belong at the end of the function declaration.

The only other thing that could be an issue is a pull up values. I followed the chip calculated spec but they may be conflicting with the breakout boards pull ups.

Increased the pull up values on the I2C lines and fixed the issue.

On my I2C level shifting chip I used the lowest allowed value of 360 ohms (based on there chart).

My on board 6050 was as I expected un-solderable by hand without more practice. So when I used a break out board, it had its own pull ups of 2.2K and screwed up the math.

By making my boards values 1K, it can now voltage divide without messing up the operation.

Didn't screw up the other IC2 tests cause they didn't have there own pull ups.

http://www.gammon.com.au/forum/?id=12153#trap18