Go Down

Topic: Weird problem connecting to KXTI9-1001 (I2C) (Read 929 times) previous topic - next topic

Russ111

Hi All,

I am having a very odd problem getting the value of I2C registers on this sensor. I have used I2C many times before, and am sure that I am structuring the commands propperly. My issue is that when I try to get the value of a register, I instead get back the address of the register, rather than the data in the register.

Has anyone else encountered this problem? Any suggestions out there?

Thanks in advance!

pylon

Show us the code and the output you get.

Russ111

Sure.

Code: [Select]

Serial.begin(9600);
Wire.begin();

Wire.beginTransmission(0x0F); //start transmission to device
Wire.send(0x0F);        //sends address to read from
Wire.endTransmission(); //end transmission

Wire.beginTransmission(0x0F); //start transmission to device
Wire.requestFrom(device, 1);    // request 1 bytes from device
 
while(!Wire.available());

Serial.println(Wire.receive(),BIN);


The output produces (in binary): 1111 (corresponding to 0x0F), rather than the device ID, which should be (in binary): 100

pylon

#3
Jun 12, 2012, 06:59 pm Last Edit: Jun 12, 2012, 07:02 pm by pylon Reason: 1
Your second

Code: [Select]
Wire.beginTransmission(0x0F); //start transmission to device

is wrong (you start another write but don't end it). And the "device" variable is not declared. If you use a variable to hold the device's address, use it in the "Wire.beginTransmission()" calls too.

Edit: In the current version of the IDE it's called "Wire.read()" and not "Wire.receive()".

Russ111

Oops, that "device" variable should contain 0x0F. I've tried running the program with that line included and commented out, because I've seen I2C reads implemented in Arduino both ways. However neither work.

I was using Arduino 0022, I just tired in Arduino 1.0 however it produced the same results.

pylon

What does that return?

Code: [Select]
Serial.begin(9600);
Wire.begin();

Wire.beginTransmission(0x0F); //start transmission to device
Wire.write(0x0C);        //sends address to read from
Wire.endTransmission(); //end transmission

Wire.requestFrom(0x0F, 1);    // request 1 bytes from device
 
while(!Wire.available());

Serial.println(Wire.read(),BIN);

Russ111

For some reason, when I try getting the data off of this register I do get the correct data, rather than the address. Any ideas why this would be the case?

We are also doing development in PIC, and in that environment I get exactly the data I am expecting, using the equivalent commands. This mystery is killing me!

pylon

You're trying to read the ID register. This has a default value but the datasheet also mentions that another ID may be configured. Maybe your device has a different ID set? Maybe they changed it to be the address of the device? Have you tried other registers? Does only the one I've chosen return correct (other than the address) values?

Russ111

Thanks for the reply. I understand what you are saying, however other registers such as the CTRL_REG1 returns 11011 (the address) instead of 0 (the reset value). Also, on the PIC microcontroller I do get the device ID that I am expecting.

pylon

Do you have external pull-ups applied? The internal work in many cases but often they are too high to let the signal reach correct levels. See this page for details:

http://www.dsscircuits.com/articles/effects-of-varying-i2c-pull-up-resistors.html

Nick Gammon

http://www.gammon.com.au/electronics

Go Up