ADXL345 3-Axis accelerometer

Device driver interface for the ADXL345. More...

Detailed Description

Files

file  adxl345_regs.h
 Register and bit definitions for the ADXL345.
 
file  adxl345.h
 Interface definition for the ADXL345.
 

Data Structures

struct  adxl345_data_t
 ADXL345 result vector struct. More...
 
struct  adxl345_interrupt_t
 Interrupt configuration struct for the ADXL345 sensor. More...
 
struct  adxl345_params_t
 Configuration struct for the ADXL345 sensor. More...
 
struct  adxl345_t
 Device descriptor for the ADXL345 sensor. More...
 

Enumerations

enum  { ADXL345_ADDR_1D = 0x1D, ADXL345_ADDR_53 = 0x53 }
 Possible ADXL345 hardware addresses (wiring specific) More...
 
enum  { ADXL345_MEASURE_MODE, ADXL345_STANDBY_MODE, ADXL345_SLEEP_MODE, ADXL345_AUTOSLEEP_MODE }
 List ADXL345 power mode.
 
enum  { ADXL345_RANGE_2G = 1, ADXL345_RANGE_4G = 2, ADXL345_RANGE_8G = 4, ADXL345_RANGE_16G = 8 }
 Define ADXL345 sensitivity. More...
 
enum  {
  ADXL345_RATE_0HZ1 = 0, ADXL345_RATE_0HZ2 = 1, ADXL345_RATE_0HZ39 = 2, ADXL345_RATE_0HZ78 = 3,
  ADXL345_RATE_1HZ56 = 4, ADXL345_RATE_3HZ13 = 5, ADXL345_RATE_6HZ25 = 6, ADXL345_RATE_12HZ50 = 7,
  ADXL345_RATE_25HZ = 8, ADXL345_RATE_50HZ = 9, ADXL345_RATE_100HZ = 10, ADXL345_RATE_200HZ = 11,
  ADXL345_RATE_400HZ = 12, ADXL345_RATE_800HZ = 13, ADXL345_RATE_1600HZ = 14, ADXL345_RATE_3200HZ = 15
}
 List bandwidth rate. More...
 
enum  { BYPASS = 0, FIFO = 1, STREAM = 2, TRIGGER = 3 }
 List fifo mode. More...
 
enum  { INT1, INT2 }
 Output Interrupt selection. More...
 
enum  {
  ADXL345_OK = 0, ADXL345_DATA_READY = 1, ADXL345_NOI2C = -1, ADXL345_NODEV = -2,
  ADXL345_NODATA = -3
}
 Named return values. More...
 

Functions

int adxl345_init (adxl345_t *dev, const adxl345_params_t *params)
 Initialize the ADXL345 accelerometer driver. More...
 
void adxl345_read (const adxl345_t *dev, adxl345_data_t *data)
 Read accelerometer's data. More...
 
void adxl345_set_interrupt (const adxl345_t *dev)
 set ADXL345's interrupts configuration More...
 
void adxl345_set_measure (const adxl345_t *dev)
 set ADXL345's measure mode More...
 
void adxl345_set_standby (const adxl345_t *dev)
 Set standby mode. More...
 
void adxl345_set_sleep (const adxl345_t *dev)
 Set sleep mode. More...
 
void adxl345_set_autosleep (const adxl345_t *dev)
 Set autosleep mode. More...
 
void adxl345_set_bandwidth_rate (const adxl345_t *dev, uint8_t bw_rate)
 Set bandwidth rate. More...
 
void adxl345_set_fifo_mode (const adxl345_t *dev, uint8_t mode, uint8_t output, uint8_t value)
 Set fifo mode with its configuration. More...
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
ADXL345_ADDR_1D 

I2C device address if Alt addr pin is high.

ADXL345_ADDR_53 

I2C device address if Alt addr pin is low.

Definition at line 34 of file adxl345.h.

◆ anonymous enum

anonymous enum
Enumerator
ADXL345_RANGE_2G 

+/- 2 g Full Scale Rang

ADXL345_RANGE_4G 

+/- 4 g Full Scale Rang

ADXL345_RANGE_8G 

+/- 8 g Full Scale Rang

ADXL345_RANGE_16G 

+/- 16 g Full Scale Rang

Definition at line 52 of file adxl345.h.

◆ anonymous enum

anonymous enum
Enumerator
ADXL345_RATE_0HZ1 

0.1 Hz Output Data Rate

ADXL345_RATE_0HZ2 

0.2 Hz Output Data Rate

ADXL345_RATE_0HZ39 

0.39 Hz Output Data Rate

ADXL345_RATE_0HZ78 

0.78 Hz Output Data Rate

ADXL345_RATE_1HZ56 

1.56 Hz Output Data Rate

ADXL345_RATE_3HZ13 

3.13 Hz Output Data Rate

ADXL345_RATE_6HZ25 

6.25 Hz Output Data Rate

ADXL345_RATE_12HZ50 

12.5 Hz Output Data Rate

ADXL345_RATE_25HZ 

25 Hz Output Data Rate

ADXL345_RATE_50HZ 

50 Hz Output Data Rate

ADXL345_RATE_100HZ 

100 Hz Output Data Rate

ADXL345_RATE_200HZ 

200 Hz Output Data Rate

ADXL345_RATE_400HZ 

400 Hz Output Data Rate

ADXL345_RATE_800HZ 

800 Hz Output Data Rate

ADXL345_RATE_1600HZ 

1600 Hz Output Data Rate

ADXL345_RATE_3200HZ 

3200 Hz Output Data Rate

Definition at line 62 of file adxl345.h.

◆ anonymous enum

anonymous enum
Enumerator
BYPASS 

FIFO bypass mode.

FIFO 

FIFO mode.

STREAM 

FIFO stream mode.

TRIGGER 

FIFO trigger mode.

Definition at line 84 of file adxl345.h.

◆ anonymous enum

anonymous enum
Enumerator
INT1 

Output interrupt on INT1 pin.

INT2 

Output interrupt on INT2 pin.

Definition at line 93 of file adxl345.h.

◆ anonymous enum

anonymous enum
Enumerator
ADXL345_OK 

everything was fine

ADXL345_DATA_READY 

new data ready to be read

ADXL345_NOI2C 

I2C communication failed.

ADXL345_NODEV 

no ADXL345 device found on the bus

ADXL345_NODATA 

no data available

Definition at line 101 of file adxl345.h.

Function Documentation

◆ adxl345_init()

int adxl345_init ( adxl345_t dev,
const adxl345_params_t params 
)
Parameters
[out]devdevice descriptor of accelerometer to initialize
[in]paramsconfiguration parameters
Returns
ADXL345_OK on success
ADXL345_NOI2C if initialization of I2C bus failed
ADXL345_NODEV if accelerometer test failed

◆ adxl345_read()

void adxl345_read ( const adxl345_t dev,
adxl345_data_t data 
)

Acceleration will be calculated as:
$ accel = {value \times 3.9} $ if full scale is set to 2g
$ accel = {value \times 7.8} $ if full scale is set to 4g
$ accel = {value \times 15.6} $ if full scale is set to 8g
$ accel = {value \times 31.2} $ if full scale is set to 16g

Parameters
[in]devdevice descriptor of accelerometer
[out]datathe current acceleration data [in mg]

◆ adxl345_set_autosleep()

void adxl345_set_autosleep ( const adxl345_t dev)
Parameters
[in]devdevice descriptor of accelerometer

◆ adxl345_set_bandwidth_rate()

void adxl345_set_bandwidth_rate ( const adxl345_t dev,
uint8_t  bw_rate 
)
Parameters
[in]devdevice descriptor of accelerometer
[in]bw_ratenew datarate

◆ adxl345_set_fifo_mode()

void adxl345_set_fifo_mode ( const adxl345_t dev,
uint8_t  mode,
uint8_t  output,
uint8_t  value 
)
Parameters
[in]devdevice descriptor of accelerometer
[in]modefifo mode configuration
[in]outputset trigger output
[in]valueset trigger's value

◆ adxl345_set_interrupt()

void adxl345_set_interrupt ( const adxl345_t dev)
Parameters
[in]devdevice descriptor of accelerometer

◆ adxl345_set_measure()

void adxl345_set_measure ( const adxl345_t dev)
Parameters
[in]devdevice descriptor of accelerometer

◆ adxl345_set_sleep()

void adxl345_set_sleep ( const adxl345_t dev)
Parameters
[in]devdevice descriptor of accelerometer

◆ adxl345_set_standby()

void adxl345_set_standby ( const adxl345_t dev)
Parameters
[in]devdevice descriptor of accelerometer