Wiki

This version (03 Oct 2022 13:02) was approved by George Mois.

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 (IIO) 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 IIO for more information.

Source Code

Status

Source Mainlined?
git Yes

Files

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: a list of interrupt specifiers

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

This specifies any shell prompt running on the target

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

Show device name

This specifies any shell prompt running on the target

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

Show scale

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

This specifies any shell prompt running on the target

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

This specifies any shell prompt running on the target

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

Set sampling frequency

This specifies any shell prompt running on the target

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

This specifies any shell prompt running on the target

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

resources/tools-software/linux-drivers/iio-accelerometer/adxl313.txt · Last modified: 23 Sep 2022 23:14 by George Mois