TPA 81 Troubleshooting

i have problem using arduino uno to interface with TPA81. this is the code that i use to read the sensor:

#include <Wire.h>
#define TPA81ADDR (0xd0>>1)

void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
Serial.print(“starting TPA81 test\n”);
}

void loop()
{
byte b;
int i;

for (i=1; i<=9; i++)
{
Wire.beginTransmission(TPA81ADDR);
Wire.send(i);
Wire.endTransmission();

Wire.requestFrom(TPA81ADDR, (int) 1);

while(Wire.available() < 1)
{ ; }

b = Wire.receive(); // receive a byte as character

Serial.print(b, DEC);
Serial.print(" “);
}
Serial.println(”");

delay(2000);
}

after i tested it my output always 21 21 21 21 21 21 21 21 21.
anyone know why it happened?

In the ASCII table, 21 is the code for NAK (negative acknowledge). Perhaps there's a clue in that value.

#define TPA81ADDR (0xd0>>1)

Check the datasheet if the address is allready shifted / needs to be shifted. Not all I2C devices have to.

update: this datasheet does not mention shifting the address.. - http://www.rapidonline.com/netalogue/specs/78-0792.pdf

The shift is correct. That looks exactly like my original working code from here.

My guess is that the device is wired incorrectly, damaged, or maybe has had the address changed.

this datasheet does not mention shifting the address…

Just one of many that do not know the difference between an I2C address and the first byte sent to an I2C device. 0xd0 is the latter. One clue is the fact that I2C addresses are all less than 12810 (that’s 0x80) - 0xd0 can’t be an address.

The Wire library expects the address, and does its own shifting.

-j

One clue is the fact that I2C addresses are all less than 12810 (that's 0x80) - 0xd0 can't be an address.

yeah, makes sense, learned again something today, thankx :)