LIS302DL Accelerometer and I2C

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

Hi Paul,

This thread has a sketch that should work with the LIS302DL. I couldn't actually test the sketch but used it as a guide. (I'm using an Atmega168 directly)

One possible problem is that you write 0x87 to CTRL_REG1 0x20. I used 0x47. If you look in twi.h you'll notice that the TWI speed is hardcoded to 100kHz so this could be causing your problems. I have only tested 100kHz so far.

With regard to pull-up resistors. I tested 4.7k, 5.6k and the internal pull-ups resistors successfully.

I'm using a version of the breakout board that only works in I2C mode. I confirmed this by testing the voltage on the CS pin with power applied. In my case, it was high.

Did you tie the MISO pin high? If not, I think the device address should be 0x1C instead of 0x1D. I connected the MISO pin to the CS pin.

I hope this helps.

I checked that thread out and used his code per his wiring and it worked flawlessly, thank you so much!

I was addressin it wrong because as you said i didn't have the MISO pin on high.

Again, thank you very much!

Great! Glad you got it working. By any chance do you see the displayed measurements quickly switch between two values? For example, on my display I see the measurements for all of the axes switch between 0 and 3 rapidly with a constant status of FF. Are you seeing this behaviour? Thanks in advance.

Yeah i get the same results.

from what I gather it is a super sensitive device. I plan on using it on a boat project to detect the orientation of the vessel. I'll probably end up averaging the values over 1 - 2 second interval to further dampen the result and give a more stable output.