ADXL312

ADXL312, ADXL313, ADXL314 Low Noise, Low Drift, Low Power, 3-Axis MEMS Accelerometers.

Supported Devices

Evaluation Boards

Description

This is a Linux industrial I/O (Linux Industrial I/O Subsystem) subsystem driver, targeting serial interface accelerometers. The industrial I/O subsystem provides a unified framework for drivers for many different types of converters and sensors using a number of different physical interfaces (i2c, spi, etc). See Linux Industrial I/O Subsystem for more information.

Source Code

Status

Source

Mainlined?

ADI tree

Yes

Files

Function

File

core driver

adxl313_core.c

spi driver

adxl313_spi.c

i2c driver

adxl313_i2c.c

header

adxl313.h

Documentation

adi,adxl313.yaml

Adding Linux driver support

Devicetree configuration

Example platform device initialization

Required devicetree properties:

  • compatible: Needs to be the name of the device. E.g. adi,adxl313, adi,adxl314

  • reg: the I2C address or SPI chip select number for the device

Required properties for SPI bus usage:

  • spi-max-frequency: Maximum SPI clock frequency.

Optional properties:

  • interrupts: optional board wiring description. This driver uses direct register reads; it does not install an interrupt handler or provide a triggered buffer.

Example for a SPI device node:

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/interrupt-controller/irq.h>
spi {
    #address-cells = <1>;
    #size-cells = <0>;

    /* Example for a SPI device node */
    accelerometer@0 {
        compatible = "adi,adxl313";
        reg = <0>;
        spi-max-frequency = <5000000>;
        interrupt-parent = <&gpio0>;
        interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
        interrupt-names = "INT1";
    };
};

Example for a I2C device node:

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/interrupt-controller/irq.h>
i2c0 {
    #address-cells = <1>;
    #size-cells = <0>;

    /* Example for a I2C device node */
    accelerometer@53 {
        compatible = "adi,adxl313";
        reg = <0x53>;
        interrupt-parent = <&gpio0>;
        interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
        interrupt-names = "INT1";
    };
};

Driver testing

root@analog:~# cd /sys/bus/iio/devices/
root@analog:/sys/bus/iio/devices# ls
iio:device0  iio_sysfs_trigger
root@analog:/sys/bus/iio/devices# cd iio\:device0
root@analog:/sys/bus/iio/devices/iio:device0# ls -l
total 0
-r--r--r-- 1 root root 4096 Sep 23 14:33 dev
-rw-r--r-- 1 root root 4096 Sep 23 14:33 in_accel_sampling_frequency
-r--r--r-- 1 root root 4096 Sep 23 14:33 in_accel_sampling_frequency_available
-rw-r--r-- 1 root root 4096 Sep 23 14:33 in_accel_scale
-rw-r--r-- 1 root root 4096 Sep 23 14:33 in_accel_x_calibbias
-rw-r--r-- 1 root root 4096 Sep 23 14:33 in_accel_x_raw
-rw-r--r-- 1 root root 4096 Sep 23 14:33 in_accel_y_calibbias
-rw-r--r-- 1 root root 4096 Sep 23 14:33 in_accel_y_raw
-rw-r--r-- 1 root root 4096 Sep 23 14:33 in_accel_z_calibbias
-rw-r--r-- 1 root root 4096 Sep 23 14:33 in_accel_z_raw
-r--r--r-- 1 root root 4096 Sep 23 14:33 name
lrwxrwxrwx 1 root root    0 Sep 23 14:33 of_node -> ../../../../../../../../firmware/devicetree/base/soc/spi@7e204000/adxl313@0
drwxr-xr-x 2 root root    0 Sep 23 14:33 power
lrwxrwxrwx 1 root root    0 Sep 23 14:33 subsystem -> ../../../../../../../../bus/iio
-rw-r--r-- 1 root root 4096 Sep 23 14:33 uevent

Identify the device

root@analog:/sys/bus/iio/devices/iio:device0# cat name
adxl313

Basic operation

Show scale

Description: scale to be applied to in_accel_*_raw in order to obtain the acceleration.

root@analog:/sys/bus/iio/devices/iio:device0# cat in_accel_scale
0.009576806

Show axis x measurement

Description: Raw unscaled acceleration measurement on x axis

root@analog:/sys/bus/iio/devices/iio:device0# cat in_accel_x_raw
-14

Set sampling frequency

For ADXL313, the datasheet recommends 1600 Hz and 3200 Hz output rates only with SPI clocks of at least 2 MHz. An 800 Hz output rate requires at least 400 kHz communication; lower rates scale proportionally (for example, 200 Hz at 100 kHz). The I2C interface supports up to 400 kHz. Select the output rate to suit the actual bus speed even when a higher rate appears in the available list.

root@analog:/sys/bus/iio/devices/iio:device0# cat in_accel_sampling_frequency_available
6.250000 12.500000 25.000000 50.000000 100.000000 200.000000 400.000000 800.000000 1600.000000 3200.000000
root@analog:/sys/bus/iio/devices/iio:device0# cat in_accel_sampling_frequency
100.000000
root@analog:/sys/bus/iio/devices/iio:device0# echo 12.5 > in_accel_sampling_frequency
root@analog:/sys/bus/iio/devices/iio:device0# cat in_accel_sampling_frequency
12.500000

Set calibbias for the Z channel

root@analog:/sys/bus/iio/devices/iio:device0# cat in_accel_z_calibbias
0
root@analog:/sys/bus/iio/devices/iio:device0# echo 4 > in_accel_z_calibbias
root@analog:/sys/bus/iio/devices/iio:device0# cat in_accel_z_calibbias
4

More Information