0
Offline
Newbie
Karma: 0
Posts: 23
Arduino rocks
|
 |
« on: June 12, 2012, 10:15:19 am » |
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
Faraday Member
Karma: 69
Posts: 3305
|
 |
« Reply #1 on: June 12, 2012, 11:31:21 am » |
Show us the code and the output you get.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 23
Arduino rocks
|
 |
« Reply #2 on: June 12, 2012, 11:51:49 am » |
Sure. 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
Faraday Member
Karma: 69
Posts: 3305
|
 |
« Reply #3 on: June 12, 2012, 11:59:55 am » |
Your second 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
Newbie
Karma: 0
Posts: 23
Arduino rocks
|
 |
« Reply #4 on: June 12, 2012, 12:37:23 pm » |
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
Faraday Member
Karma: 69
Posts: 3305
|
 |
« Reply #5 on: June 12, 2012, 12:44:56 pm » |
What does that return? 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
Newbie
Karma: 0
Posts: 23
Arduino rocks
|
 |
« Reply #6 on: June 13, 2012, 08:54:44 am » |
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
Faraday Member
Karma: 69
Posts: 3305
|
 |
« Reply #7 on: June 13, 2012, 01:25:01 pm » |
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
Newbie
Karma: 0
Posts: 23
Arduino rocks
|
 |
« Reply #8 on: June 14, 2012, 09:30:49 am » |
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
|
|
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #10 on: June 14, 2012, 04:17:01 pm » |
Show your current code.
|
|
|
|
|
Logged
|
|
|
|
|
|