COSA
An Object-Oriented Platform for Arduino Programming
ADXL345 Class Reference

#include <ADXL345.hh>

Inheritance diagram for ADXL345:
Inheritance graph
Collaboration diagram for ADXL345:
Collaboration graph

Classes

struct  offset_t
 
struct  sample_t
 

Public Types

enum  {
  DATA_READY = 7, SINGLE_TAP = 6, DOUBLE_TAP = 5, ACT = 4,
  INACT = 3, FREE_FALL = 2, WATERMARK = 1, OVERRUN = 0
}
 

Public Member Functions

 ADXL345 (bool use_alt_address=false)
 
bool begin ()
 
bool end ()
 
void calibrate (int8_t x, int8_t y, int8_t z)
 
void calibrate ()
 
void sample (sample_t &s)
 
uint8_t is_activity ()
 

Protected Types

enum  Register {
  DEVID = 0x00, THRESH_TAP = 0x1D, OFS = 0x1E, DUR = 0x21,
  LATENT = 0x22, WINDOW = 0x23, THRESH_ACT = 0x24, THRESH_INACT = 0x25,
  TIME_INACT = 0x26, ACT_INACT_CTL = 0x27, THRESH_FF = 0x28, TIME_FF = 0x29,
  TAP_AXES = 0x2A, ACT_TAP_STATUS = 0x2B, BW_RATE = 0x2C, POWER_CTL = 0x2D,
  INT_ENABLE = 0x2E, INT_MAP = 0x2F, INT_SOURCE = 0x30, DATA_FORMAT = 0x31,
  DATA = 0x32, FIFO_CTL = 0x38, FIFO_STATUS = 0x39
}
 
enum  {
  ACT_AC_DC = 7, ACT_X_EN = 6, ACT_Y_EN = 5, ACT_Z_EN = 4,
  INACT_AC_DC = 3, INACT_X_EN = 2, INACT_Y_EN = 1, INACT_Z_EN = 0
}
 
enum  { SUPPRES = 3, TAP_X_EN = 2, TAP_Y_EN = 1, TAP_Z_EN = 0 }
 
enum  {
  ACT_X_SRC = 6, ACT_Y_SRC = 5, ACT_Z_SRC = 4, ASLEEP = 3,
  TAP_X_SRC = 2, TAP_Y_SRC = 1, TAP_Z_SRC = 0
}
 
enum  { LOW_POWER = 4, RATE = 0, RATE_MASK = 0x0f }
 
enum  {
  LINK = 5, AUTO_SLEEP = 4, MEASURE = 3, SLEEP = 2,
  WAKEUP = 0
}
 
enum  {
  WAKEUP_8_HZ = 0, WAKEUP_4_HZ = 1, WAKEUP_2_HZ = 2, WAKEUP_1_HZ = 3,
  WAKEUP_MASK = 3
}
 
enum  {
  SELF_TEST = 7, SPI_WIRE_MODE = 6, INT_INVERT = 5, FULL_RES = 3,
  JUSTIFY = 2, RANGE = 0
}
 
enum  {
  RANGE_2G = 0, RANGE_4G = 1, RANGE_8G = 2, RANGE_16G = 3,
  RANGE_MASK = 3
}
 
enum  {
  FIFO_MODE = 6, FIFO_MASK = 0xc0, TRIG = 5, SAMPLES = 0,
  SAMPLES_MASK = 0x1f
}
 
enum  { BYPASS = 0x00, FIFO = 0x40, STREAM = 0x80, TRIGGER = 0xc0 }
 
enum  { FIFO_TRIG = 7, ENTRIES = 0, ENTRIES_MASK = 0x3f }
 
enum  { X = 4, Y = 2, Z = 1 }
 

Protected Member Functions

void write (Register reg, uint8_t value)
 
void write (Register reg, void *buffer, uint8_t count)
 
uint8_t read (Register reg)
 
void read (Register reg, void *buffer, uint8_t count)
 

Static Protected Attributes

static const uint8_t ID = 0xe5
 

Private Member Functions

bool is_async () const
 
void sync_request ()
 
void async_request ()
 
virtual void on_completion (uint8_t type, int count)
 

Private Attributes

uint8_t m_addr
 
bool m_async
 

Detailed Description

Cosa TWI driver for Analog Devices ADXL345 Digital Accelerometer. http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf Rev. D, 2/13.

Circuit

The GY-291 module with pull-up resistors (4K7) for TWI signals and 3V3 internal voltage converter.

GY-291
+------------+
(GND)---------------1-|GND |
(VCC)---------------2-|VCC |
3-|CS |
4-|A-INT1 |
5-|A-INT2 |
6-|SDO |
(A4/SDA)------------7-|SDA |
(A5/SCL)------------8-|SCL |
+------------+

Definition at line 49 of file ADXL345.hh.

Member Enumeration Documentation

anonymous enum

Register INT_ENABLE/INT_MAP/INT_SOURCE bitfields.

Enumerator
DATA_READY 

Data ready interrupt enable/map/source.

SINGLE_TAP 

Single tap.

DOUBLE_TAP 

Double tap.

ACT 

Activity.

INACT 

Inactivity.

FREE_FALL 

Free fall.

WATERMARK 

Watermark.

OVERRUN 

Overrun interrupt enable/map/source.

Definition at line 129 of file ADXL345.hh.

anonymous enum
protected

Register ACT_INACT_CTL bitfields.

Enumerator
ACT_AC_DC 

AC/DC coupled activity.

ACT_X_EN 

Activity x axis enable.

ACT_Y_EN 

Activity x axis enable.

ACT_Z_EN 

Activity x axis enable.

INACT_AC_DC 

AC/DC coupled inactivity.

INACT_X_EN 

Inactivity x axis enable.

INACT_Y_EN 

Inactivity x axis enable.

INACT_Z_EN 

Inactivity x axis enable.

Definition at line 183 of file ADXL345.hh.

anonymous enum
protected

Register TAP_AXES bitfields.

Enumerator
SUPPRES 

Suppress.

TAP_X_EN 

Tap x enable.

TAP_Y_EN 

Tap y enable.

TAP_Z_EN 

Tap z enable.

Definition at line 197 of file ADXL345.hh.

anonymous enum
protected

Register ACT_TAP_STATUS bitfields.

Enumerator
ACT_X_SRC 

Activity x event.

ACT_Y_SRC 

Activity y event.

ACT_Z_SRC 

Activity z event.

ASLEEP 

Device is asleep.

TAP_X_SRC 

Tap x event.

TAP_Y_SRC 

Tap y event.

TAP_Z_SRC 

Tap z event.

Definition at line 207 of file ADXL345.hh.

anonymous enum
protected

Register BW_RATE bitfields.

Enumerator
LOW_POWER 

Low power move.

RATE 

Data rate (4 bits).

RATE_MASK 

Data rate mask.

Definition at line 220 of file ADXL345.hh.

anonymous enum
protected

Register POWER_CTL bitfields.

Enumerator
LINK 

Link mode select.

AUTO_SLEEP 

Auto sleep enable.

MEASURE 

Measurement mode.

SLEEP 

Sleep mode.

WAKEUP 

Wakeup frequency (2 bits).

Definition at line 229 of file ADXL345.hh.

anonymous enum
protected
Enumerator
WAKEUP_8_HZ 

8 hz.

WAKEUP_4_HZ 

4 hz.

WAKEUP_2_HZ 

2 hz.

WAKEUP_1_HZ 

1 hz.

WAKEUP_MASK 

Wakeup frequency mask.

Definition at line 236 of file ADXL345.hh.

anonymous enum
protected

Register DATA_FORMAT bitfields.

Enumerator
SELF_TEST 

Self-test force.

SPI_WIRE_MODE 

SPI wire mode.

INT_INVERT 

Interrupt active high/low.

FULL_RES 

Full resolution.

JUSTIFY 

Left justified/sign extend.

RANGE 

Range 2-16 g (2 bits).

Definition at line 247 of file ADXL345.hh.

anonymous enum
protected
Enumerator
RANGE_2G 

+-2g.

RANGE_4G 

+-4g.

RANGE_8G 

+-8g.

RANGE_16G 

+-16g.

RANGE_MASK 

Mask range field.

Definition at line 255 of file ADXL345.hh.

anonymous enum
protected

Register FIFO_CTL bitfields.

Enumerator
FIFO_MODE 

FIFO Mode.

FIFO_MASK 

Dito Mask.

TRIG 

Trigger event to interrupt pin.

SAMPLES 

Number of samples (5 bits).

SAMPLES_MASK 

Dito Mask.

Definition at line 266 of file ADXL345.hh.

anonymous enum
protected
Enumerator
BYPASS 

FIFO is bypassed.

FIFO 

Collects up to 32 values.

STREAM 

Holds the latest 32 values.

TRIGGER 

Latest 32 values before trigger.

Definition at line 273 of file ADXL345.hh.

anonymous enum
protected

Register FIFO_STATUS bitfields.

Enumerator
FIFO_TRIG 

FIFO trigger event occuring.

ENTRIES 

Number of entries in FIFO (6 bits).

ENTRIES_MASK 

Dito Mask.

Definition at line 283 of file ADXL345.hh.

anonymous enum
protected

3-Axis setting (add or or values).

Enumerator

Definition at line 325 of file ADXL345.hh.

enum ADXL345::Register
protected

Registers Map (See tab. 19, pp. 23).

Enumerator
DEVID 

Device ID.

THRESH_TAP 

Tap threshold.

OFS 

Offset (x, y, z).

DUR 

Tap duration.

LATENT 

Tap latency.

WINDOW 

Tap window.

THRESH_ACT 

Activity threshold.

THRESH_INACT 

Inactivity threshold.

TIME_INACT 

Inactivity time.

ACT_INACT_CTL 

Axis enable control for activity detection.

THRESH_FF 

Free-fall threshold.

TIME_FF 

Free-fall time.

TAP_AXES 

Axis control for single tap/double tap.

ACT_TAP_STATUS 

Source of single tap/double tap.

BW_RATE 

Data rate and power mode control.

POWER_CTL 

Power-saving features control.

INT_ENABLE 

Interrupt enable control.

INT_MAP 

Interrupt mapping control.

INT_SOURCE 

Source of interrupts.

DATA_FORMAT 

Data format control.

DATA 

Data (x, y, z).

FIFO_CTL 

FIFO control.

FIFO_STATUS 

FIFO status.

Definition at line 151 of file ADXL345.hh.

Constructor & Destructor Documentation

ADXL345::ADXL345 ( bool  use_alt_address = false)
inline

Construct ADXL345 driver with normal or alternative address (pp. 18).

Parameters
[in]use_alt_address.

Definition at line 56 of file ADXL345.hh.

Member Function Documentation

bool ADXL345::begin ( )

Start interaction with device. Set full resolution and 16G. Single and double tap detection in XYZ-axis. Activity/inactivity (5 seconds), and free fall detect. Power control with auto-sleep and wakeup at 2 Hz. Interrupts enabled. Measurement turned on.

Returns
true(1) if successful otherwise false(0)

Definition at line 24 of file ADXL345.cpp.

void ADXL345::calibrate ( int8_t  x,
int8_t  y,
int8_t  z 
)
inline

Calibrate accelerometer with given offsets.

Parameters
[in]xaxis offset.
[in]yaxis offset.
[in]zaxis offset.

Definition at line 90 of file ADXL345.hh.

void ADXL345::calibrate ( )

Calibrate accelerometer by resetting offset and using the current accelerometer values as offset. (-sample/4) according to ADXL345 documentation.

Definition at line 93 of file ADXL345.cpp.

bool ADXL345::end ( )

Stop sequence of interaction with device. Turn off measurement.

Returns
true(1) if successful otherwise false(0)

Definition at line 61 of file ADXL345.cpp.

uint8_t ADXL345::is_activity ( )

Check for activity. Returns a bitset with current activity. Ignore WATERMARK and OVERRUN.

Returns
activities

Definition at line 102 of file ADXL345.cpp.

uint8_t ADXL345::read ( Register  reg)
inlineprotected

Read contents of register.

Parameters
[in]regregister address.
Returns
register value.

Definition at line 309 of file ADXL345.hh.

void ADXL345::read ( Register  reg,
void *  buffer,
uint8_t  count 
)
protected

Read contents of registers, multiple values from give address.

Parameters
[in]regregister address.
[in]bufferstorage.
[in]countnumber of bytes.

Definition at line 84 of file ADXL345.cpp.

void ADXL345::sample ( sample_t s)
inline

Sample accelerometer. Return sample is given data structure

Parameters
[in]ssample storage.

Definition at line 120 of file ADXL345.hh.

void ADXL345::write ( Register  reg,
uint8_t  value 
)
protected

Write given value to register.

Parameters
[in]regregister address.
[in]valueregister value.

Definition at line 68 of file ADXL345.cpp.

void ADXL345::write ( Register  reg,
void *  buffer,
uint8_t  count 
)
protected

Write multiple registers with values from give address.

Parameters
[in]regregister address.
[in]bufferstorage.
[in]countnumber of bytes.

Definition at line 76 of file ADXL345.cpp.

Member Data Documentation

const uint8_t ADXL345::ID = 0xe5
staticprotected

Register DEVID value (345).

Definition at line 178 of file ADXL345.hh.


The documentation for this class was generated from the following files: