... Why you didn't host it on google code?
Google smoogle. Github ftw.
... Why you didn't host it on google code?
int16_t MPU9150_readSensor(int addrL, int addrH){
Wire.beginTransmission(MPU9150_I2C_ADDRESS);
Wire.write(addrL);
Wire.endTransmission(I2C_NOSTOP);
Wire.requestFrom(MPU9150_I2C_ADDRESS, 1, I2C_STOP);
byte L = Wire.read();
Wire.beginTransmission(MPU9150_I2C_ADDRESS);
Wire.write(addrH);
Wire.endTransmission(I2C_NOSTOP);
Wire.requestFrom(MPU9150_I2C_ADDRESS, 1, I2C_STOP);
while (Wire.available() < 1);
byte H = Wire.read();
return (H<<8)+L;
}
Hi,
I works just fine right after the code has been downloaded to the Teensy, but the values become incorrect (constant zero) if I switch to external power or unplug and reinserts the USB power. SDA and SDL signals are similar in both cases, so I suspect the issue to be timing related.
[COLOR=#ff0000]void print_i2c_status(void)
{
switch(Wire.status())
{
case I2C_WAITING: Serial.print("I2C waiting, no errors\n"); break;
case I2C_ADDR_NAK: Serial.print("Slave addr not acknowledged\n"); break;
case I2C_DATA_NAK: Serial.print("Slave data not acknowledged\n"); break;
case I2C_ARB_LOST: Serial.print("Bus Error: Arbitration Lost\n"); break;
default: Serial.print("I2C busy\n"); break;
}
}[/COLOR]
int16_t MPU9150_readSensor(int addrL, int addrH){
Wire.beginTransmission(MPU9150_I2C_ADDRESS);
Wire.write(addrL);
Wire.endTransmission(I2C_NOSTOP);
[COLOR=#ff0000]print_i2c_status();[/COLOR]
Wire.requestFrom(MPU9150_I2C_ADDRESS, 1, I2C_STOP);
[COLOR=#ff0000]print_i2c_status();[/COLOR]
byte L = Wire.read();
Wire.beginTransmission(MPU9150_I2C_ADDRESS);
Wire.write(addrH);
Wire.endTransmission(I2C_NOSTOP);
[COLOR=#ff0000]print_i2c_status();[/COLOR]
Wire.requestFrom(MPU9150_I2C_ADDRESS, 1, I2C_STOP);
[COLOR=#ff0000]print_i2c_status();[/COLOR]
while (Wire.available() < 1);
byte H = Wire.read();
return (H<<8)+L;
}
void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t * dest)
{
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.endTransmission(I2C_NOSTOP); // Send the Tx buffer, but send a restart to keep connection alive
uint8_t i = 0;
Wire.requestFrom(address, count); // Read bytes from slave register address
while (Wire.available()) {
dest[i++] = Wire.read(); } // Put read results in the Rx buffer
}
In file included from MPU6050IMU.ino:29:0:
C:\Documents and Settings\Kris\My Documents\Arduino\libraries\i2c_t3/i2c_t3.h: In function 'uint8_t readByte(uint8_t, uint8_t)':
C:\Documents and Settings\Kris\My Documents\Arduino\libraries\i2c_t3/i2c_t3.h:592:19: note: candidate 1: size_t i2c_t3::requestFrom(int, int)
C:\Documents and Settings\Kris\My Documents\Arduino\libraries\i2c_t3/i2c_t3.h:590:19: note: candidate 2: size_t i2c_t3::requestFrom(uint8_t, size_t)
C:\Documents and Settings\Kris\My Documents\Arduino\libraries\i2c_t3/i2c_t3.h: In function 'void readBytes(uint8_t, uint8_t, uint8_t, uint8_t*)':
C:\Documents and Settings\Kris\My Documents\Arduino\libraries\i2c_t3/i2c_t3.h:592:19: note: candidate 1: size_t i2c_t3::requestFrom(int, int)
C:\Documents and Settings\Kris\My Documents\Arduino\libraries\i2c_t3/i2c_t3.h:590:19: note: candidate 2: size_t i2c_t3::requestFrom(uint8_t, size_t)
Binary sketch size: 37,560 bytes (of a 262,144 byte maximum)
Estimated memory use: 5,436 bytes (of a 65,536 byte maximum)
Just answered my own question. Apparently I needed to change the uint8_t to size_t in the request from call.
So my question is, how well vetted is the Wire1 mode and the use of the I2C_PINS29_30? I can't seem to get it to work.
Make sure I2C_BUS_ENABLE is set to 2 in the i2c_t3.h header file.
Glad you got it working. I've been soldering right angle headers to the back of the Teensy on my test boards and using the master/slave function - very useful library.It looks like the I2C_BUS_ENABLE defaults to 2 in the v6b 12c_t3.h library so that wasn't the problem. Instead, it was that I had no external pullups on SDA/SCL even though I was asking for them in the Wire1 call. I got everything to work once I figured this out; the little sensor board is happily i2c-ing away on the back Teensy 3.1 pads! Thanks for such a great library, without it I wouldn't have been able to finish this part of the project.
Instead, it was that I had no external pullups on SDA/SCL even though I was asking for them in the Wire1 call.
Hi Nox771,
Just wanted to thank you for your efforts. I recently switched to the new I2C library for humidity and temperature measurements (Si7021, HTU21) and everything worked as expected. No compile errors, etc. Next steps may include stepping up the bus speed to 400 to reduce the time the I2C interrogation of the sensor takes. But that presumes this non-CS grad will figure out a good non-blocking approach to extracting the info and turn off the internal heater also. Maybe use Metro as a quasi RTOS? Anyhow, that's for me to figure out.
Your efforts are super appreciated since they 'just work' and are easy to adopt.
And here's one from me:
adafruit_fram_i2c_t3
Uses i2c_t3 to access the Adafruit FRAM board. Read speeds of 12 microseconds per byte are possible, a major speed-up over using Wire.