Pages: [1]   Go Down
Author Topic: Weird problem connecting to KXTI9-1001 (I2C)  (Read 851 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Show us the code and the output you get.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sure.

Code:
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
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your second

Code:
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()".
« Last Edit: June 12, 2012, 12:02:26 pm by pylon » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What does that return?

Code:
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);
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Show your current code.
Logged

Pages: [1]   Go Up
Jump to: