Wiki

This version (20 Nov 2018 16:52) was approved by spopa.The Previously approved version (05 Sep 2018 13:45) is available.Diff

ADXL372 Input 3-Axis Digital Accelerometer Linux Driver

Supported Devices

Evaluation Boards

Description

This is a Linux industrial I/O (IIO) subsystem driver, targeting dual or quad channel serial interface ADCs. 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

Devicetree

Required devicetree properties:

  • compatible: Needs to be the name of the device. E.g. “adi,adxl372”
  • 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:

	#address-cells = <1>;
	#size-cells = <0>;
	status = "okay";

	adxl372@0 {
		compatible = "adi,adxl372";
		reg = <0>;
		spi-max-frequency = <1000000>;
		interrupts = <25 2>;
		interrupt-parent = <&gpio>;
	};

Example for a I2C device node:

	#address-cells = <1>;
	#size-cells = <0>;
	status = "okay";

	adxl372@53 {
		compatible = "adi,adxl372";
		reg = <0x53>;
		interrupts = <25 2>;
		interrupt-parent = <&gpio>;
	};

Driver testing

This specifies any shell prompt running on the target

root:/> cd /sys/bus/iio/devices/
root:/sys/bus/iio/devices> ls
iio:device0

root:/sys/bus/iio/devices> cd iio\:device0

root:/sys/bus/iio/devices/iio:device0> ls -l
drwxr-xr-x 2 root root    0 Oct 25 04:25 buffer
-rw-r--r-- 1 root root 4096 Oct 25 04:25 current_timestamp_clock
-r--r--r-- 1 root root 4096 Oct 25 04:25 dev
-rw-r--r-- 1 root root 4096 Oct 25 04:28 in_accel_filter_low_pass_3db_frequency
-r--r--r-- 1 root root 4096 Oct 25 04:25 in_accel_filter_low_pass_3db_frequency_available
-rw-r--r-- 1 root root 4096 Oct 25 04:27 in_accel_sampling_frequency
-rw-r--r-- 1 root root 4096 Oct 25 04:25 in_accel_scale
-rw-r--r-- 1 root root 4096 Oct 25 04:25 in_accel_x_raw
-rw-r--r-- 1 root root 4096 Oct 25 04:25 in_accel_y_raw
-rw-r--r-- 1 root root 4096 Oct 25 04:25 in_accel_z_raw
-r--r--r-- 1 root root 4096 Oct 25 04:25 name
lrwxrwxrwx 1 root root    0 Oct 25 04:25 of_node -> ../../../../../../../../firmware/devicetree/base/soc/spi@7e204000/adxl372@0
drwxr-xr-x 2 root root    0 Oct 25 04:25 power
-r--r--r-- 1 root root 4096 Oct 25 04:25 sampling_frequency_available
drwxr-xr-x 2 root root    0 Oct 25 04:25 scan_elements
lrwxrwxrwx 1 root root    0 Oct 25 04:25 subsystem -> ../../../../../../../../bus/iio
drwxr-xr-x 2 root root    0 Oct 25 04:25 trigger
-rw-r--r-- 1 root root 4096 Oct 25 04:25 uevent

Show device name

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0> cat name
adxl372

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:/sys/bus/iio/devices/iio:device0> cat in_accel_scale
0.958241

Show axis x measurement

Description:
Raw unscaled acceleration measurement on x axis

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0> cat in_accel_x_raw
-5

Set sampling frequency

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0> cat sampling_frequency_available
400 800 1600 3200 6400
root:/sys/bus/iio/devices/iio:device0> cat in_accel_sampling_frequency
6400
root:/sys/bus/iio/devices/iio:device0> echo 3200 > in_accel_sampling_frequency
root:/sys/bus/iio/devices/iio:device0> cat in_accel_sampling_frequency
3200

Show available bandwidths for the current set frequency

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0> cat in_accel_sampling_frequency
256000
root:/sys/bus/iio/devices/iio:device0> cat in_accel_filter_low_pass_3db_frequency_available
200 400 800 1600 3200
root:/sys/bus/iio/devices/iio:device0>

Change the bandwidth

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0> cat in_accel_filter_low_pass_3db_frequency_available
200 400 800 1600 3200
root:/sys/bus/iio/devices/iio:device0> cat in_accel_filter_low_pass_3db_frequency
3200
root:/sys/bus/iio/devices/iio:device0> echo 1600 > in_accel_filter_low_pass_3db_frequency
root:/sys/bus/iio/devices/iio:device0> cat in_accel_filter_low_pass_3db_frequency
1600
root:/sys/bus/iio/devices/iio:device0> echo 3200 > in_accel_sampling_frequency
root:/sys/bus/iio/devices/iio:device0> cat in_accel_filter_low_pass_3db_frequency_available
200 400 800 1600
root:/sys/bus/iio/devices/iio:device0> echo 1600 > in_accel_sampling_frequency
root:/sys/bus/iio/devices/iio:device0> cat in_accel_filter_low_pass_3db_frequency
800

Trigger management

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0> cat trigger/current_trigger 
adxl372-dev-*

Buffer management

Description:
The scan_elements directory contains interfaces for elements that will be captured for a single triggered sample set in the buffer

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0/scan_elements> ls -l
-rw-r--r-- 1 root root 4096 Oct 25 08:08 in_accel_x_en
-r--r--r-- 1 root root 4096 Oct 25 08:08 in_accel_x_index
-r--r--r-- 1 root root 4096 Oct 25 08:08 in_accel_x_type
-rw-r--r-- 1 root root 4096 Oct 25 08:08 in_accel_y_en
-r--r--r-- 1 root root 4096 Oct 25 08:08 in_accel_y_index
-r--r--r-- 1 root root 4096 Oct 25 08:08 in_accel_y_type
-rw-r--r-- 1 root root 4096 Oct 25 08:08 in_accel_z_en
-r--r--r-- 1 root root 4096 Oct 25 08:08 in_accel_z_index
-r--r--r-- 1 root root 4096 Oct 25 08:08 in_accel_z_type
-rw-r--r-- 1 root root 4096 Oct 25 08:08 in_timestamp_en
-r--r--r-- 1 root root 4096 Oct 25 08:08 in_timestamp_index
-r--r--r-- 1 root root 4096 Oct 25 08:08 in_timestamp_type
root:/sys/bus/iio/devices/iio:device0/scan_elements>

Before enabling the buffer, a few steps need to be completed.

  • First, the axis that we want to read data from need to be enabled:

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0/scan_elements> echo 1 > in_accel_x_en
root:/sys/bus/iio/devices/iio:device0/scan_elements> echo 1 > in_accel_y_en
root:/sys/bus/iio/devices/iio:device0/scan_elements> echo 1 > in_accel_z_en

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0/buffer> ls
enable hwfifo_enabled  hwfifo_watermark  hwfifo_watermark_max  hwfifo_watermark_min  length  watermark
root:/sys/bus/iio/devices/iio:device0/buffer>

  • Set the buffer length:

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0/buffer> echo 1024 > length

  • Set the fifo watermak:

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0/buffer> echo 170 > watermark

  • Enable the buffer:

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0/buffer> echo 1 > enable

To read samples:

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:device0/buffer> cat /dev/iio:device0

Low level register access via debugfs (direct_reg_access)

Some IIO drivers feature an optional debug facility, allowing users to read or write registers directly. Special care needs to be taken when using this feature, since you can modify registers on the back of the driver. Accessing debugfs requires root privileges.

In order to identify if the IIO device in question feature this option you first need to identify the IIO device number.

Therefore read the name attribute of each IIO device

This specifies any shell prompt running on the target

root@analog:~# grep "" /sys/bus/iio/devices/iio\:device*/name
adxl372
root@analog:~# 

Change directory to /sys/kernel/debug/iio/iio:deviceX and check if the direct_reg_access file exists.

This specifies any shell prompt running on the target

root@analog:~# cd /sys/kernel/debug/iio/iio\:device0/
root@analog:/sys/kernel/debug/iio/iio:device0# ls direct_reg_access  
ls direct_reg_access
root@analog:/sys/kernel/debug/iio/iio:device0#

Reading

This specifies any shell prompt running on the target

root@analog:/sys/kernel/debug/iio/iio:device0# echo 0x0 > direct_reg_access   
  
root@analog:/sys/kernel/debug/iio/iio:device0# cat direct_reg_access 
0xAD
root@analog:/sys/kernel/debug/iio/iio:device0#

Writing

Write ADDRESS VALUE

This specifies any shell prompt running on the target

root@analog:/sys/kernel/debug/iio/iio:device0# echo 0x3D 0x80 > direct_reg_access   
root@analog:/sys/kernel/debug/iio/iio:device0# cat direct_reg_access 
0x80
root@analog:/sys/kernel/debug/iio/iio:device0#

More Information

resources/tools-software/linux-drivers/iio-accelerometer/adxl372.txt · Last modified: 20 Nov 2018 16:52 by spopa