ADXL345 triple axis, digital accelerometer library.

Dependents:   AntiTheftGPS

Embed: (wiki syntax)

« Back to documentation index

ADXL345 Class Reference

ADXL345 Class Reference

ADXL345 triple axis, digital interface, accelerometer. More...

#include <ADXL345.h>

Public Member Functions

 ADXL345 (PinName mosi, PinName miso, PinName sck, PinName cs)
 Constructor.
int getDevId (void)
 Read the device ID register on the device.
int getTapThreshold (void)
 Read the tap threshold on the device.
void setTapThreshold (int threshold)
 Set the tap threshold.
int getOffset (int axis)
 Get the current offset for a particular axis.
void setOffset (int axis, char offset)
 Set the offset for a particular axis.
int getTapDuration (void)
 Get the tap duration required to trigger an event.
void setTapDuration (int duration_us)
 Set the tap duration required to trigger an event.
float getTapLatency (void)
 Get the tap latency between the detection of a tap and the time window.
void setTapLatency (int latency_ms)
 Set the tap latency between the detection of a tap and the time window.
float getWindowTime (void)
 Get the time of window between tap latency and a double tap.
void setWindowTime (int window_ms)
 Set the time of the window between tap latency and a double tap.
int getActivityThreshold (void)
 Get the threshold value for detecting activity.
void setActivityThreshold (int threshold)
 Set the threshold value for detecting activity.
int getInactivityThreshold (void)
 Get the threshold value for detecting inactivity.
void setInactivityThreshold (int threshold)
 Set the threshold value for detecting inactivity.
int getTimeInactivity (void)
 Get the time required for inactivity to be declared.
void setTimeInactivity (int timeInactivity)
 Set the time required for inactivity to be declared.
int getActivityInactivityControl (void)
 Get the activity/inactivity control settings.
void setActivityInactivityControl (int settings)
 Set the activity/inactivity control settings.
int getFreefallThreshold (void)
 Get the threshold for free fall detection.
void setFreefallThreshold (int threshold)
 Set the threshold for free fall detection.
int getFreefallTime (void)
 Get the time required to generate a free fall interrupt.
void setFreefallTime (int freefallTime_ms)
 Set the time required to generate a free fall interrupt.
int getTapAxisControl (void)
 Get the axis tap settings.
void setTapAxisControl (int settings)
 Set the axis tap settings.
int getTapSource (void)
 Get the source of a tap.
void setPowerMode (char mode)
 Set the power mode.
void setDataRate (int rate)
 Set the data rate.
int getPowerControl (void)
 Get the power control settings.
void setPowerControl (int settings)
 Set the power control settings.
int getInterruptEnableControl (void)
 Get the interrupt enable settings.
void setInterruptEnableControl (int settings)
 Set the interrupt enable settings.
int getInterruptMappingControl (void)
 Get the interrupt mapping settings.
void setInterruptMappingControl (int settings)
 Set the interrupt mapping settings.
int getInterruptSource (void)
 Get the interrupt source.
int getDataFormatControl (void)
 Get the data format settings.
void setDataFormatControl (int settings)
 Set the data format settings.
void getOutput (int *readings)
 Get the output of all three axes.
int getAx ()
 Get acceleration of X axis.
int getAy ()
 Get acceleration of Y axis.
int getAz ()
 Get acceleration of Z axis.
int getFifoControl (void)
 Get the FIFO control settings.
void setFifoControl (int settings)
 Set the FIFO control settings.
int getFifoStatus (void)
 Get FIFO status.

Detailed Description

ADXL345 triple axis, digital interface, accelerometer.

Definition at line 101 of file ADXL345.h.


Constructor & Destructor Documentation

ADXL345 ( PinName  mosi,
PinName  miso,
PinName  sck,
PinName  cs 
)

Constructor.

Includes.

Parameters:
mosimbed pin to use for MOSI line of SPI interface.
misombed pin to use for MISO line of SPI interface.
sckmbed pin to use for SCK line of SPI interface.
csmbed pin to use for not chip select line of SPI interface.
Author:
Aaron Berk

LICENSE

Copyright (c) 2010 ARM Limited

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

DESCRIPTION

ADXL345, triple axis, digital interface, accelerometer.

Datasheet:

http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf

Definition at line 40 of file ADXL345.cpp.


Member Function Documentation

int getActivityInactivityControl ( void   )

Get the activity/inactivity control settings.

D7 D6 D5 D4 +-----------+--------------+--------------+--------------+ | ACT ac/dc | ACT_X enable | ACT_Y enable | ACT_Z enable | +-----------+--------------+--------------+--------------+

D3 D2 D1 D0 +-------------+----------------+----------------+----------------+ | INACT ac/dc | INACT_X enable | INACT_Y enable | INACT_Z enable | +-------------+----------------+----------------+----------------+

See datasheet for details.

Returns:
The contents of the ACT_INACT_CTL register.

Definition at line 183 of file ADXL345.cpp.

int getActivityThreshold ( void   )

Get the threshold value for detecting activity.

Returns:
The threshold value for detecting activity as an 8-bit number. Scale factor is 62.5mg/LSB.

Definition at line 147 of file ADXL345.cpp.

int getAx (  )

Get acceleration of X axis.

Returns:
Accelerometer value for the x-axis.

Definition at line 316 of file ADXL345.cpp.

int getAy (  )

Get acceleration of Y axis.

Returns:
Accelerometer value for the y-axis

Definition at line 326 of file ADXL345.cpp.

int getAz (  )

Get acceleration of Z axis.

Returns:
Accelerometer value for the z-axis

Definition at line 335 of file ADXL345.cpp.

int getDataFormatControl ( void   )

Get the data format settings.

Returns:
The contents of the DATA_FORMAT register.

Definition at line 292 of file ADXL345.cpp.

int getDevId ( void   )

Read the device ID register on the device.

Returns:
The device ID code [0xE5]

Definition at line 55 of file ADXL345.cpp.

int getFifoControl ( void   )

Get the FIFO control settings.

Returns:
The contents of the FIFO_CTL register.

Definition at line 358 of file ADXL345.cpp.

int getFifoStatus ( void   )

Get FIFO status.

Returns:
The contents of the FIFO_STATUS register.

Definition at line 370 of file ADXL345.cpp.

int getFreefallThreshold ( void   )

Get the threshold for free fall detection.

Returns:
The threshold value for free-fall detection, as an 8-bit number, with scale factor 62.5mg/LSB.

Definition at line 195 of file ADXL345.cpp.

int getFreefallTime ( void   )

Get the time required to generate a free fall interrupt.

Returns:
The minimum time that the value of all axes must be less than the freefall threshold to generate a free-fall interrupt, in milliseconds.

Definition at line 207 of file ADXL345.cpp.

int getInactivityThreshold ( void   )

Get the threshold value for detecting inactivity.

Returns:
The threshold value for detecting inactivity as an 8-bit number. Scale factor is 62.5mg/LSB.

Definition at line 159 of file ADXL345.cpp.

int getInterruptEnableControl ( void   )

Get the interrupt enable settings.

Returns:
The contents of the INT_ENABLE register.

Definition at line 262 of file ADXL345.cpp.

int getInterruptMappingControl ( void   )

Get the interrupt mapping settings.

Returns:
The contents of the INT_MAP register.

Definition at line 274 of file ADXL345.cpp.

int getInterruptSource ( void   )

Get the interrupt source.

Returns:
The contents of the INT_SOURCE register.

Definition at line 286 of file ADXL345.cpp.

int getOffset ( int  axis )

Get the current offset for a particular axis.

Parameters:
axis0x00 -> X-axis 0x01 -> Y-axis 0x02 -> Z-axis
Returns:
The current offset as an 8-bit 2's complement number with scale factor 15.6mg/LSB.

Definition at line 73 of file ADXL345.cpp.

void getOutput ( int *  readings )

Get the output of all three axes.

Parameters:
Pointerto a buffer to hold the accelerometer value for the x-axis, y-axis and z-axis [in that order].

Definition at line 346 of file ADXL345.cpp.

int getPowerControl ( void   )

Get the power control settings.

See datasheet for details.

Returns:
The contents of the POWER_CTL register.

Definition at line 250 of file ADXL345.cpp.

int getTapAxisControl ( void   )

Get the axis tap settings.

D3 D2 D1 D0 +----------+--------------+--------------+--------------+ | Suppress | TAP_X enable | TAP_Y enable | TAP_Z enable | +----------+--------------+--------------+--------------+

(D7-D4 are 0s).

See datasheet for more details.

Returns:
The contents of the TAP_AXES register.

Definition at line 221 of file ADXL345.cpp.

int getTapDuration ( void   )

Get the tap duration required to trigger an event.

Returns:
The max time that an event must be above the tap threshold to qualify as a tap event, in microseconds.

Definition at line 105 of file ADXL345.cpp.

float getTapLatency ( void   )

Get the tap latency between the detection of a tap and the time window.

Returns:
The wait time from the detection of a tap event to the start of the time window during which a possible second tap event can be detected in milliseconds.

Definition at line 119 of file ADXL345.cpp.

int getTapSource ( void   )

Get the source of a tap.

Returns:
The contents of the ACT_TAP_STATUS register.

Definition at line 233 of file ADXL345.cpp.

int getTapThreshold ( void   )

Read the tap threshold on the device.

Returns:
The tap threshold as an 8-bit number with a scale factor of 62.5mg/LSB.

Definition at line 61 of file ADXL345.cpp.

int getTimeInactivity ( void   )

Get the time required for inactivity to be declared.

Returns:
The amount of time that acceleration must be less than the inactivity threshold for inactivity to be declared, in seconds.

Definition at line 171 of file ADXL345.cpp.

float getWindowTime ( void   )

Get the time of window between tap latency and a double tap.

Returns:
The amount of time after the expiration of the latency time during which a second valid tap can begin, in milliseconds.

Definition at line 133 of file ADXL345.cpp.

void setActivityInactivityControl ( int  settings )

Set the activity/inactivity control settings.

D7 D6 D5 D4 +-----------+--------------+--------------+--------------+ | ACT ac/dc | ACT_X enable | ACT_Y enable | ACT_Z enable | +-----------+--------------+--------------+--------------+

D3 D2 D1 D0 +-------------+----------------+----------------+----------------+ | INACT ac/dc | INACT_X enable | INACT_Y enable | INACT_Z enable | +-------------+----------------+----------------+----------------+

See datasheet for details.

Parameters:
settingsThe control byte to write to the ACT_INACT_CTL register.

Definition at line 189 of file ADXL345.cpp.

void setActivityThreshold ( int  threshold )

Set the threshold value for detecting activity.

Parameters:
thresholdThe threshold value for detecting activity as an 8-bit number. Scale factor is 62.5mg/LSB. A value of 0 may result in undesirable behavior if the activity interrupt is enabled.

Definition at line 153 of file ADXL345.cpp.

void setDataFormatControl ( int  settings )

Set the data format settings.

Parameters:
settingsThe control byte to write to the DATA_FORMAT register.

Definition at line 298 of file ADXL345.cpp.

void setDataRate ( int  rate )

Set the data rate.

Parameters:
rateThe rate code (see defines or datasheet).

Definition at line 304 of file ADXL345.cpp.

void setFifoControl ( int  settings )

Set the FIFO control settings.

Parameters:
Thecontrol byte to write to the FIFO_CTL register.

Definition at line 364 of file ADXL345.cpp.

void setFreefallThreshold ( int  threshold )

Set the threshold for free fall detection.

Returns:
The threshold value for free-fall detection, as an 8-bit number, with scale factor 62.5mg/LSB. A value of 0 may result in undesirable behavior if the free-fall interrupt is enabled. Values between 300 mg and 600 mg (0x05 to 0x09) are recommended.

Definition at line 201 of file ADXL345.cpp.

void setFreefallTime ( int  freefallTime_ms )

Set the time required to generate a free fall interrupt.

Returns:
The minimum time that the value of all axes must be less than the freefall threshold to generate a free-fall interrupt, in milliseconds. A value of 0 may result in undesirable behavior if the free-fall interrupt is enabled. Values between 100 ms and 350 ms (0x14 to 0x46) are recommended.

Definition at line 213 of file ADXL345.cpp.

void setInactivityThreshold ( int  threshold )

Set the threshold value for detecting inactivity.

Parameters:
thresholdThe threshold value for detecting inactivity as an 8-bit number. Scale factor is 62.5mg/LSB.

Definition at line 165 of file ADXL345.cpp.

void setInterruptEnableControl ( int  settings )

Set the interrupt enable settings.

Parameters:
settingsThe control byte to write to the INT_ENABLE register.

Definition at line 268 of file ADXL345.cpp.

void setInterruptMappingControl ( int  settings )

Set the interrupt mapping settings.

Parameters:
settingsThe control byte to write to the INT_MAP register.

Definition at line 280 of file ADXL345.cpp.

void setOffset ( int  axis,
char  offset 
)

Set the offset for a particular axis.

Parameters:
axis0x00 -> X-axis 0x01 -> Y-axis 0x02 -> Z-axis
offsetThe offset as an 8-bit 2's complement number with scale factor 15.6mg/LSB.

Definition at line 89 of file ADXL345.cpp.

void setPowerControl ( int  settings )

Set the power control settings.

See datasheet for details.

Parameters:
Thecontrol byte to write to the POWER_CTL register.

Definition at line 256 of file ADXL345.cpp.

void setPowerMode ( char  mode )

Set the power mode.

Parameters:
mode0 -> Normal operation. 1 -> Reduced power operation.

Definition at line 239 of file ADXL345.cpp.

void setTapAxisControl ( int  settings )

Set the axis tap settings.

D3 D2 D1 D0 +----------+--------------+--------------+--------------+ | Suppress | TAP_X enable | TAP_Y enable | TAP_Z enable | +----------+--------------+--------------+--------------+

(D7-D4 are 0s).

See datasheet for more details.

Parameters:
Thecontrol byte to write to the TAP_AXES register.

Definition at line 227 of file ADXL345.cpp.

void setTapDuration ( int  duration_us )

Set the tap duration required to trigger an event.

Parameters:
duration_usThe max time that an event must be above the tap threshold to qualify as a tap event, in microseconds. Time will be normalized by the scale factor which is 625us/LSB. A value of 0 disables the single/double tap functions.

Definition at line 111 of file ADXL345.cpp.

void setTapLatency ( int  latency_ms )

Set the tap latency between the detection of a tap and the time window.

Parameters:
latency_msThe wait time from the detection of a tap event to the start of the time window during which a possible second tap event can be detected in milliseconds. A value of 0 disables the double tap function.

Definition at line 125 of file ADXL345.cpp.

void setTapThreshold ( int  threshold )

Set the tap threshold.

Parameters:
Thetap threshold as an 8-bit number with a scale factor of 62.5mg/LSB.

Definition at line 67 of file ADXL345.cpp.

void setTimeInactivity ( int  timeInactivity )

Set the time required for inactivity to be declared.

Parameters:
inactivityThe amount of time that acceleration must be less than the inactivity threshold for inactivity to be declared, in seconds. A value of 0 results in an interrupt when the output data is less than the threshold inactivity.

Definition at line 177 of file ADXL345.cpp.

void setWindowTime ( int  window_ms )

Set the time of the window between tap latency and a double tap.

Parameters:
window_msThe amount of time after the expiration of the latency time during which a second valid tap can begin, in milliseconds.

Definition at line 139 of file ADXL345.cpp.