This is an old revision of the document!
The ADXL312 is a small, thin, low power, 3-axis accelerometer with high resolution (13-bit) measurement up to ±12 g. More information about the device can be found here.
The ADXL313 is a small, thin, low power, 3-axis accelerometer with high resolution (13-bit) measurement up to ±4g. More information about the device can be found here.
The ADXL314 is a small, thin, 3-axis accelerometer that provides low power consumption and high-resolution measurement of ±200 g. More information about the device can be found here.
Digital output data is formatted as 16-bit twos complement and is accessible through either a serial port interface (SPI) (3- or 4-wire) or I2C digital interface.
Each device is mounted on a simple breakout board that enables easy connection into an existing system.
The goal of ADI Microcontroller No-OS is to be able to provide reference projects for lower end processors, which can't run Linux, or aren't running a specific operating system, to help those customers using microcontrollers with ADI parts. ADI No-OS offers generic drivers which can be used as a base for any microcontroller platform and also example projects which are using these drivers on various microcontroller platforms.
For more information about ADI No-OS and supported microcontroller platforms see: ADI No-OS.
The source code for the ADXL313 driver:
The driver also uses the ADI util library, so make sure you also add the necessary files in your project. The source code for the util library:
In order to be able to use this driver you will have to provide the specific implementation for the communication APIs and the specific types they use. If the SPI communication is chosen, there are three functions which are called by the ADXL313 driver and have to be implemented:
And there are two data types that have to be defined:
If the I2C communication is chosen, there are four functions which are called by the ADXL313 driver:
And there are two data types that have to be defined:
Example of a header file containing the prototypes of the functions which have to be implemented, along with some generic data types they are using:
Source code documentation for the driver is automatically generated using the Doxygen tool and it is available at:
In order to be able to use the device, you will have to provide the support for the communication protocol (SPI or I2C) as mentioned above. The first API to be called is adxl313_init. Make sure that it returns 0, which means that the driver was initialized correctly.
After initialization, a soft reset can be performed (only for ADXL313), by calling adxl313_soft_reset, in order to reset the device. The driver reads the device settings saved in the device's registers in the initialization phase.
By default, the device uses the minimum range configuration (valid for ADXL312 and ADXL313; ADXL314 has fixed range). You may modify this value by using adxl313_set_range API.
You may set an offset for each axis for calibration purposes by using adxl313_set_offset. The offset is set to 0 by default. The data provided in adxl313_set_offset is in twos complement format, with a scale factor depending on device. The value stored in the offset registers is automatically added to the acceleration data, and the resulting value is stored in the output data registers.
The devices contain patent pending technology for an embedded memory management system with a 32-level FIFO that can be used to minimize host processor burden. This buffer has four modes: bypass, FIFO, stream, and trigger. Each mode is selected by the using the adxl313_set_fifo_mode function.
In case you want to use the FIFO, you can to modify the number of FIFO samples to be stored in the FIFO. The default and maximum value is 32 samples (3 values per sample, one for each axis), but can be modified using the adxl313_set_fifo_samples API.
In case you want to use the activity / inactivity detection algorithm, you can enable this feature on any axis using the adxl313_set_activity_detection / adxl313_set_inactivity_detection API.
The device allows the usage of interrupts which can be mapped to INT1 or INT2 pins. In case you want to use interrupts, make sure you configure the interrupt pin by using adxl313_interrupt_int_map API, where interrupt is replaced with the desired interrupt (data_ready, activity, inactivity, watermark, overrun). You may also configure the polarity of the interrupt, whether is active high or active low, by using adxl313_set_int_pol API.
It is recommended that the device be configured in standby mode before measurement mode is enabled. The setting of the operation mode is performed through the use of the adxl313_set_op_mode function.
If you want to obtain a single data set, you may use the adxl313_get_xyz API to obtain the data converted to g, or the adxl313_get_raw_xyz API to obtain the raw data. The raw data is in two's complement format and it does not have the scaling applied.
If you want to read from the FIFO, you may use the adxl313_get_fifo_data API to obtain the data converted to g or the adxl313_get_raw_fifo_data API to obtain the raw data. The raw data is in two's complement format and it does not have the scaling applied. The parameter fifo_entries shows the number of valid measurements in the FIFO which were read.
struct adxl313_dev *adxl313; /* Particular SPI configuration */ struct no_os_spi_init_param sip = { .device_id = SPI_DEVICE_ID, .max_speed_hz = SPI_MAX_HZ, .bit_order = NO_OS_SPI_BIT_ORDER_MSB_FIRST, .mode = NO_OS_SPI_MODE_0, .extra = &xsip, .platform_ops = SPI_OPS, .chip_select = SPI_CS, }; struct adxl313_init_param adxl313_user_init = { .dev_type = ID_ADXL313, .comm_type = ADXL313_SPI_COMM, }; /* Initialize component. */ ret = adxl313_init(&adxl313, adxl313_user_init); if (ret) goto error; /* Perform device self-test. */ ret = adxl313_self_test(adxl313); if (ret) goto error; /* Set Standby mode, required for performing setup. */ ret = adxl313_set_op_mode(adxl313, ADXL313_STDBY); if (ret) goto error; /* Set output data rate. */ ret = adxl313_set_odr(adxl313, ADXL313_ODR_800HZ); if (ret) goto error; /* Put device in Measure mode after setup. */ ret = adxl313_set_op_mode(adxl313, ADXL313_MEAS); if (ret) goto error; /* Read single accel data */ struct adxl313_frac_repr x; struct adxl313_frac_repr y; struct adxl313_frac_repr z; ret = adxl313_get_xyz(adxl313,&x, &y, &z); if (ret < 0) goto error; /* Read FIFO accel data */ struct adxl313_frac_repr x[32] = {0}; struct adxl313_frac_repr y[32] = {0}; struct adxl313_frac_repr z[32] = {0}; uint8_t fifo_entries = 0; ret = adxl313_get_fifo_data(adxl313, &fifo_entries, &x[0], &y[0], &z[0]); if (ret < 0) goto error;
Application Example Projects for ADXL313 driver: Evaluating the ADXL313.
More on no-OS IIO.
The ADXL313 IIO driver comes on top of ADXL313 driver and offers support for interfacing IIO clients through IIO lib.
Source code for ADXL313 driver:
Source code documentation for the IIO driver is automatically generated using the Doxygen tool and it is available at:
The ADXL313 IIO device does not have any device specific attributes.
The ADXL313 IIO device has 0 input channels and 3 output channels, corresponding to the acceleration on the three axes.
The acceleration channels are:
Each acceleration channel has 8 attributes. 6 of these attributes are shared in value with the other acceleration channels and 2 of these attributes can have different values for each channel.
The attributes are:
struct adxl313_iio_dev *adxl313_iio_desc; struct adxl313_iio_dev_init_param adxl313_init_par; struct no_os_spi_init_param sip = { .device_id = SPI_DEVICE_ID, .max_speed_hz = SPI_MAX_HZ, .bit_order = NO_OS_SPI_BIT_ORDER_MSB_FIRST, .mode = NO_OS_SPI_MODE_0, .extra = &xsip, .platform_ops = SPI_OPS, .chip_select = SPI_CS, }; struct adxl313_init_param adxl313_user_init = { .dev_type = ID_ADXL313, .comm_type = ADXL313_SPI_COMM, }; adxl313_init_par.adxl313_dev_init = &adxl313_user_init; ret = adxl313_iio_init(&adxl313_iio_desc, &adxl313_init_par); if (ret) return ret; switch(adxl313_iio_desc->adxl313_dev->dev_type) { case ID_ADXL312: dev_name = "ADXL312"; break; case ID_ADXL313: dev_name = "ADXL313"; break; case ID_ADXL314: dev_name = "ADXL314"; break; default: return -ENODEV; } struct iio_app_device iio_devices[] = { { .name = dev_name, .dev = adxl313_iio_desc, .dev_descriptor = adxl313_iio_desc->iio_dev, } }; return iio_app_run(iio_devices, NO_OS_ARRAY_SIZE(iio_devices));
Application Example Project for the ADXL313 IIO driver: Evaluating the ADXL313.