Accelerometer SPI Mode
Accelerometer SPI Mode
This document describes the Altera University Program’s IP core that can be used to access the accelerometer
peripheral found on Altera’s DE0-Nano and VEEK-MT boards.
1 Accelerometer Chip
The accelerometer peripheral consists of the Analog Devices’ ADXL345 chip. It measures acceleration in three
directions, which are referred to as x -axis, y -axis and z -axis. When stationary, the only acceleration experienced by
the chip is due to gravity. The measured results have 13-bit resolution in the range up to ±16 g .
The accelerometer chip includes a set of eight-bit registers that store the results of measurements and provide settings
for various modes of operation. To accommodate the 13-bit size, the measured values of x , y and z are stored in
pairs of registers.
The AXDL345 chip supports serial communication using either the SPI (Serial Peripheral Interface Bus) or I2 C
(Inter-Integrated Circuit) Standards. The SPI communication is supported using either a three-wire or four-wire
connection. On the DE0-Nano and VEEK-MT boards, the accelerometer chip is connected to the FPGA chip by the
three-wire SPI arrangement.
A full description can be found in Analog Devices datasheets: Digital Accelerometer ADXL345.
Figure 1 shows a high-level block diagram of the core. To set up the accelerometer device, the core takes information
from a program (via the Avalon bus) or an auto-initialization circuit and sends it out via the serial bus.
Avalon
Bus Serial
Bus
Serializer
Auto-Init
In the following sections, we describe the memory-mapped registers and how to use them, both directly and using
the HAL interface.
The UP Accelerometer Core has two 8-bit registers, called address and data. They are mapped to specific memory
addresses at the time the core is instantiated in a Qsys-developed system. Their addresses are offset by one byte, as
indicated in Table 1. The table shows the byte offset, access rights (Read/Write) and the meaning of each bit in the
registers.
By writing into these registers, the processor can specify the operationg mode of the accelerometer and read its
current values.
Table 1. UP Accelerometer Core Registers
Offset in Register
Read/Write 7. . . 6 5. . . 0
bytes Name
0 address W 0 Addr
1 data R/W Data
The address register is used to transmit the address of a register in the ADXL345 device that is to be accessed.
The desired address is is given in the six least-significant bits, as shown in Table 1.
The data register is used to transmit data from/to the registers in the ADXL345 device. Reading from or writing to
this register will initiate a serial transfer from/to the accelerometer.
The ADXL345 chip has a number of control and data registers, which are identified by six-bit addresses in the range
0x00 to 0x39. All registers are eight bits long. The control registers are used to define various modes of operation.
They are loaded by performing a write operation. Their contents can be examined by performing a read operation.
The data registers comprise three pairs of registers, which hold the currently measured values of acceleration in the
x , y and z directions.
Data registers DATAX0 and DATAX1, with addresses 0x32 and 0x33, hold the 2’s-complement value of the x -axis
measurement. The DATAX0 register holds the low-order byte and DATAX1 holds the high-order byte. Similarly,
DATAY0 and DATAY1, with addresses 0x34 and 0x35, hold the y -axis value, while DATAZ0 and DATAZ1, with
addresses 0x36 and 0x37, hold the z -axis value.
The accelerometer chip has to be configured to perform the desired functions, which is accomplished by writing
into the appropriate control registers. Using the UP Accelerometer Core, this can be achieved by writing the nec-
essary addresses and data into the address and data registers in the core. However, the UP Accelerator Core has an
auto-initialize option, which automatically configures it into a mode that causes measurements to be continuously
performed and allows reading of the results through the X , Y and Z register pairs using the resolution of ±2 g .
The automatic initialization is performed whenever the core is reset, which also occurs when the hardware system
that contains the core is downloaded into the FPGA device on the board.
#include "altera_up_avalon_accelerometer_spi.h"
Prototype: alt_up_accelerometer_spi_dev*
alt_up_accelerometer_spi_open_dev(const char
*name)
Include: <altera_up_avalon_accelerometer_spi_spi.h>
Parameters: name – the accelerometer_spi component name in Qsys.
Returns: The corresponding device structure, or NULL if the device is not found.
Description: Opens the accelerometer_spi device specified by name .