Hello,
I recently purchased a LIS302DL from http://www.nkcelectronics.com/triple-axis-accelerometer-breakout--lis30302.html. Sadly I had failed to read the little blurb saying:
"Normally, you can use the CS line to select whether you want to use the SPI or I2C interface. Because we did not breakout CS to a pin, you really can't use the SPI interface. Therefore, this version of the breakout board can only be used in I2C mode. Future versions will have the CS pin broken out so that you can use either interface."
Now I don't know if i'm blind or not, but it sure looks like they did broke out CS to a pin so I don't know what they're talking about, but anyways, I'm still trying to get the thing working through I2C.
Now i'm still in the learning phase of all this arduino stuff (aka: i is a n00B) but here is where i've gotten so far.
Reading up on the spec sheet (http://www.stmicroelectronics.com/stonline/products/literature/ds/12726.pdf) i found:
"The Slave ADdress (SAD) associated to the LIS302DL may be selected among the two
predefined values 0011100b or 0011101b depending on the logic level present on SDO pin.
In details, if SDO pin is either connected to Vdd_IO or left unconnected the slave address is
0011101b, otherwise when it is connected to GND the slave address is 0011100b."
So i'm assuming that the address is 0x1D (can anyone tell me what that b stands for?) if i leave the SDO pin unconnected. Then, doing a thorough search of I2C, arduino and accelerometers i found this handy blog post of a gentleman getting the LIS3LV02DQ up and running through I2C. This particular chip is slightly different than mine, but i went ahead and tried to port his code. Looking up the registers of my chip, i found the ctr 1 register, which takes 7 bits that have some initial setup value, and turn the thing on (supposedly) and the X output, and in this code, i am just trying to get a reading from that.
Here's the code:
#include <Wire.h>
// TWI (I2C) sketch to communicate with the LIS3LV02DQ accelerometer
// Using the Wire library (created by Nicholas Zambetti)
// http://wiring.org.co/reference/libraries/Wire/index.html
// On the Arduino board, Analog In 4 is SDA, Analog In 5 is SCL
// These correspond to pin 27 (PC4/ADC4/SDA) and pin 28 (PC5/ADC5/SCL) on the Atmega8
// The Wire class handles the TWI transactions, abstracting the nitty-gritty to make
// prototyping easy.
void setup()
{
Serial.begin(9600);
CLKPR = (1<<CLKPCE);
CLKPR = 0;
Wire.begin(); // join i2c bus (address optional for master)
Wire.beginTransmission(0x1D);
Wire.send(0x20); // CTRL_REG1 (20h)
Wire.send(0x87); // Device on, 40hz, normal mode, all axis's enabled
Wire.endTransmission();
}
void loop()
{
byte x_val_h;
int x_val;
Wire.beginTransmission(0x1D);
// send the sub address for the register we want to read
// this is for the OUT_X register
Wire.send(0x29);
// stop transmitting
Wire.endTransmission();
// Now do a transfer reading one byte from the LIS3L*
// This data will be the contents of register 0x28
Wire.requestFrom(0x1D, 1);
while(Wire.available())
{
x_val_l = Wire.receive();
}
x_val = x_val_h;
x_val <<= 8; // Why am I doing this?
Serial.print(x_val, HEX);
delay(100);
}
All i get from this is 0. For the physical setup, i have 3.3v going to Vcc, gnd going to gnd, SCL to analog 5 in and SDA to analog 4. I tried used pull-up resistors by hooking a res from the two alnalog pins to Vcc but that didn't seem to work either.
Is there something i'm missing, or did i perhaps fry the chip?
Thanks for any help! Seeing this thing pump data into my computer would be pretty awesome.
- Paul