Library 35- LIS302DL or LIS3DSH accelerometer

Maybe you’ve noticed one chip between four leds on STM32F4-Discovery board. This chip is accelerometer. On market, there are 2 versions of STM32F4-Discovery board. First release had LIS302DL (old board) and new release (current) has LIS3DSH device. LIS3DSH has 5 selectables full scales (2/4/6/8/16G), old LIS302DL has only 2 (2.3/9.2G).

I made a simple library which supports both devices. Library automatically recognize connected device, if there is any. You just have to check which is on board, because different devices have different possible settings. Both devices uses the same pinout on board. They use SPI for communication with STM32F4.

I have a new version of STM32F4-Discovery board, so LIS3DSH is in use. In that case i had to find someone who will test this for me. I found one, he is also very good with STM32F4 devices. His website is here.

Library

Features

  • Supports LIS302DL accelerometer
    • old STM32F4-Discovery boards
  • Supports LIS3DSH accelerometer
    • new STM32F4-Discovery boards
  • Selectable full scales
  • Supports sensor detection

Dependencies

  • CMSIS
    • STM32F4xx
    • STM32F4xx RCC
    • STM32F4xx GPIO
    • STM32F4xx SPI
  • TM
    • TM SPI
    • defines.h
LIS302DL/LIS3DSH STM32F4-Discovery Description
MOSI PA7 Master out, Slave in for SPI1
MISO PA6 Master in, Slave out for SPI1
SCK PA5 Serial clock for SPI1
CS PE3 Chip select

If you are working with custom application, and you want to use custom pinout, open defines.h file and edit settings:

Remember: This library also works if you are working with custom application!

Functions and enumerations

New LIS3DSH is a little more powerful, has more selectable full scales and also high pass output filter. For that purpose you have more possible settings on initialization. Possible configuration with functions is described below:

Example

Below is simple example. You have to use STM32F4-Discovery board for this. It works like this:

  • If LIS302DL device is detected, then RED and GREEN leds will be turned on for 2 seconds
  • If LIS3DSH device is detected, then BLUE and ORANGE leds will be turned on for 2 seconds
  • If all 4 leds are on, there was an error, because device is not recognized
  • After 2 seconds leds will be off.
  • If you move your board, leds will be on according to direction you move your board.

This example first checks for connected device. After you know which device is connected, you don’t need to always check that. You can simple just initialize device that you know is connected on board.

Project is available on my Github account, download library below.

tilz0R

Owner of this site. Application engineer, currently employed by STMicroelectronics. Exploring latest technologies and owner of different libraries posted on Github.

You may also like...