This is an old revision of the document!
The ADXL345 is a small, thin, low power, 3-axis accelerometer with high resolution (13-bit) measurement at up to ±16 g. Digital output data is formatted as 16-bit twos complement and is accessible through either a SPI (3- or 4-wire) or I2C digital interface. The ADXL345 is well suited for mobile device applications. It measures the static acceleration of gravity in tilt-sensing appli-cations, as well as dynamic acceleration resulting from motion or shock. Its high resolution (4 mg/LSB) enables measurement of inclination changes less than 1.0°.
The goal of this project (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. Here you can find a generic driver which can be used as a base for any microcontroller platform and also specific drivers for Renesas platforms.
HW Platform(s):
The driver contains two parts:
The Communication Driver has a standard interface, so the ADXL345 driver can be used exactly as it is provided.
If the SPI communication is chosen, there are three functions which are called by the ADXL345 driver:
SPI driver architecture
If the I2C communication is chosen, there are three functions which are called by the ADXL345 driver:
I2C driver architecture
The implementation of these three functions depends on the used microcontroller.
Example:
#define ADXL345_COMMUNICATION SPI_COMMUNICATION
or
#define ADXL345_COMMUNICATION I2C_COMMUNICATION
The driver for ADXL345 contains functions for reading or writing any of the registers, for placing the device into standby or measure mode, for enable or disable various types of events detection, etc.
The following functions are implemented in this version of ADXL345 driver:
Function | Description |
---|---|
void ADXL345_SetRegisterValue(unsigned char registerAddress, unsigned char registerValue) | Writes data into a register. |
unsigned char ADXL345_GetRegisterValue(unsigned char registerAddress) | Reads the value of a register. |
unsigned char ADXL345_Init(void) | Initializes the communication peripheral and checks if the ADXL345 part is present. |
void ADXL345_SetPowerMode(unsigned char pwrMode) | Places the device into standby/measure mode. |
void ADXL345_GetXyz(unsigned short* x, unsigned short* y, unsigned short* z) | Reads the output data of each axis. |
void ADXL345_SetTapDetection(unsigned char tapType, unsigned char tapAxes, unsigned char tapDur, unsigned char tapLatent, unsigned char tapWindow, unsigned char tapThresh, unsigned char tapInt) | Enables/disables the tap detection. |
void ADXL345_SetActivityDetection(unsigned char actOnOff, unsigned char actAxes, unsigned char actAcDc, unsigned char actThresh, unsigned char actInt) | Enables/disables the activity detection. |
void ADXL345_SetInactivityDetection(unsigned char inactOnOff, unsigned char inactAxes, unsigned char inactAcDc, unsigned char inactThresh, unsigned char inactTime, unsigned char inactInt) | Enables/disables the inactivity detection. |
void ADXL345_SetFreeFallDetection(unsigned char ffOnOff, unsigned char ffThresh, unsigned char ffTime, unsigned char ffInt) | Enables/disables the free-fall detection. |
void ADXL345_SetOffset(unsigned char xOffset, unsigned char yOffset, unsigned char zOffset) | Calibrates the accelerometer. |
This section contains a description of the steps required to run the ADXL345 demonstration project on a Renesas RL78G13 platform.
There are two options:
With the Applilet3 for RL78G13 tool the following peripherals have to be configured:
Choose to generate the Transmit/receive function for the CSI10 and configure the interface with the following settings:
Choose the Single master transfer mode and configure the interface with the following settings:
Configure TM00 as an interval timer:
Disable the watchdog timer:
In this example, the output data of each axis is read and displayed on the Renesas Demonstration Kit for RL78G13 board’s LCD. Were also activated “Single Tap”, “Double Tap” and “Free-Fall” interrupts. When one of them occurs, on the LCD screen appears a corresponding message.
This section presents the steps for developing a software application that will run on the Renesas Demo Kit for RL78G13 for controlling and monitoring the operation of the ADI part.
Two software applications have to be used: Applilet3 for RL78G13 (a tool that automatically generates device drivers for MCU peripheral functions) and IAR Embedded Workbench for Renesas RL78 (the integrated development environment).
This section contains a description of the steps required to run the ADXL345 demonstration project on a Renesas RX62N platform.
There are two options:
PmodACL Pin 1 (CS) → YRDKRX62N J8 connector Pin 15 PmodACL Pin 2 (MOSI) → YRDKRX62N J8 connector Pin 19 PmodACL Pin 3 (MISO) → YRDKRX62N J8 connector Pin 22 PmodACL Pin 4 (CLK) → YRDKRX62N J8 connector Pin 20 PmodACL Pin 5 (GND) → YRDKRX62N J8 connector Pin 4 PmodACL Pin 6 (VCC) → YRDKRX62N J8 connector Pin 3
In this example, the output data of each axis is read and displayed on the Renesas Demonstration Kit for RX62N board’s LCD. Were also activated “Single Tap”, “Double Tap” and “Free-Fall” interrupts. When one of them occurs, on the LCD screen appears a corresponding message.
This section presents the steps for developing a software application that will run on the Renesas Demo Kit for RX62N for controlling and monitoring the operation of the ADI part.
This section contains a description of the steps required to run the ADXL345 demonstration project on a Digilent Cerebot MC7 platform.
A PmodACL can be connected to the J6 connector of Cerebot MC7 development board for I2C operation,
or to the JB connector of Cerebot MC7 development board for SPI operation.
Following commands were implemented in this version of AD7991 reference project for Cerebot MC7 board.
Command | Description |
---|---|
help? | Displays all available commands. |
communication= | Selects the communication interface. Accepted values: 0(I2C),1(SPI). |
communication? | Displays the selected communication interface. |
acceleration? | Displays the acceleration on XYZ axis. |
interrupts? | Displays the state of the interrupts. |
Commands can be executed using a serial terminal connected to the UART1 peripheral of dsPIC33FJ128MC706A.
The following image shows a list of commands in a serial terminal connected to processor’s UART peripheral.
This section presents the steps for developing a software application that will run on the Digilent Cerebot MC7 development board for controlling and monitoring the operation of the ADI part.