LibDriver ADXL345  2.0.0
ADXL345 full-featured driver
driver_adxl345.c File Reference

driver adxl345 source file More...

#include "driver_adxl345.h"

Go to the source code of this file.

Macros

#define CHIP_NAME   "Analog Devices ADXL345"
 chip register definition More...
 
#define MANUFACTURER_NAME   "Analog Devices"
 
#define SUPPLY_VOLTAGE_MIN   2.0f
 
#define SUPPLY_VOLTAGE_MAX   3.6f
 
#define MAX_CURRENT   0.14f
 
#define TEMPERATURE_MIN   -40.0f
 
#define TEMPERATURE_MAX   85.0f
 
#define DRIVER_VERSION   2000
 
#define ADXL345_REG_DEVID   0x00
 chip register definition More...
 
#define ADXL345_REG_THRESH_TAP   0x1D
 
#define ADXL345_REG_OFSX   0x1E
 
#define ADXL345_REG_OFSY   0x1F
 
#define ADXL345_REG_OFSZ   0x20
 
#define ADXL345_REG_DUR   0x21
 
#define ADXL345_REG_LATENT   0x22
 
#define ADXL345_REG_WINDOW   0x23
 
#define ADXL345_REG_THRESH_ACT   0x24
 
#define ADXL345_REG_THRESH_INACT   0x25
 
#define ADXL345_REG_TIME_INACT   0x26
 
#define ADXL345_REG_ACT_INACT_CTL   0x27
 
#define ADXL345_REG_THRESH_FF   0x28
 
#define ADXL345_REG_TIME_FF   0x29
 
#define ADXL345_REG_TAP_AXES   0x2A
 
#define ADXL345_REG_ACT_TAP_STATUS   0x2B
 
#define ADXL345_REG_BW_RATE   0x2C
 
#define ADXL345_REG_POWER_CTL   0x2D
 
#define ADXL345_REG_INT_ENABLE   0x2E
 
#define ADXL345_REG_INT_MAP   0x2F
 
#define ADXL345_REG_INT_SOURCE   0x30
 
#define ADXL345_REG_DATA_FORMAT   0x31
 
#define ADXL345_REG_DATAX0   0x32
 
#define ADXL345_REG_DATAX1   0x33
 
#define ADXL345_REG_DATAY0   0x34
 
#define ADXL345_REG_DATAY1   0x35
 
#define ADXL345_REG_DATAZ0   0x36
 
#define ADXL345_REG_DATAZ1   0x37
 
#define ADXL345_REG_FIFO_CTL   0x38
 
#define ADXL345_REG_FIFO_STATUS   0x39
 

Functions

uint8_t adxl345_set_interface (adxl345_handle_t *handle, adxl345_interface_t interface)
 set the chip interface More...
 
uint8_t adxl345_get_interface (adxl345_handle_t *handle, adxl345_interface_t *interface)
 get the chip interface More...
 
uint8_t adxl345_set_addr_pin (adxl345_handle_t *handle, adxl345_address_t addr_pin)
 set the iic address pin More...
 
uint8_t adxl345_get_addr_pin (adxl345_handle_t *handle, adxl345_address_t *addr_pin)
 get the iic address pin More...
 
uint8_t adxl345_set_tap_threshold (adxl345_handle_t *handle, uint8_t threshold)
 set the tap threshold More...
 
uint8_t adxl345_get_tap_threshold (adxl345_handle_t *handle, uint8_t *threshold)
 get the tap threshold More...
 
uint8_t adxl345_tap_threshold_convert_to_register (adxl345_handle_t *handle, float g, uint8_t *reg)
 convert the tap threshold to the register raw data More...
 
uint8_t adxl345_tap_threshold_convert_to_data (adxl345_handle_t *handle, uint8_t reg, float *g)
 convert the register raw data to the tap threshold More...
 
uint8_t adxl345_set_offset (adxl345_handle_t *handle, int8_t x, int8_t y, int8_t z)
 set the axis offset More...
 
uint8_t adxl345_get_offset (adxl345_handle_t *handle, int8_t *x, int8_t *y, int8_t *z)
 get the axis offset More...
 
uint8_t adxl345_offset_convert_to_register (adxl345_handle_t *handle, float g, int8_t *reg)
 convert the offset to the register raw data More...
 
uint8_t adxl345_offset_convert_to_data (adxl345_handle_t *handle, int8_t reg, float *g)
 convert the register raw data to the offset More...
 
uint8_t adxl345_set_duration (adxl345_handle_t *handle, uint8_t t)
 set the duration More...
 
uint8_t adxl345_get_duration (adxl345_handle_t *handle, uint8_t *t)
 get the duration More...
 
uint8_t adxl345_duration_convert_to_register (adxl345_handle_t *handle, uint32_t us, uint8_t *reg)
 convert the duration to the register raw data More...
 
uint8_t adxl345_duration_convert_to_data (adxl345_handle_t *handle, uint8_t reg, uint32_t *us)
 convert the register raw data to the duration More...
 
uint8_t adxl345_set_latent (adxl345_handle_t *handle, uint8_t t)
 set the latent More...
 
uint8_t adxl345_get_latent (adxl345_handle_t *handle, uint8_t *t)
 get the latent More...
 
uint8_t adxl345_latent_convert_to_register (adxl345_handle_t *handle, float ms, uint8_t *reg)
 convert the latent to the register raw data More...
 
uint8_t adxl345_latent_convert_to_data (adxl345_handle_t *handle, uint8_t reg, float *ms)
 convert the register raw data to the latent More...
 
uint8_t adxl345_set_window (adxl345_handle_t *handle, uint8_t t)
 set the window More...
 
uint8_t adxl345_get_window (adxl345_handle_t *handle, uint8_t *t)
 get the window More...
 
uint8_t adxl345_window_convert_to_register (adxl345_handle_t *handle, float ms, uint8_t *reg)
 convert the window time to the register raw data More...
 
uint8_t adxl345_window_convert_to_data (adxl345_handle_t *handle, uint8_t reg, float *ms)
 convert the register raw data to the window time More...
 
uint8_t adxl345_set_action_threshold (adxl345_handle_t *handle, uint8_t threshold)
 set the action threshold More...
 
uint8_t adxl345_get_action_threshold (adxl345_handle_t *handle, uint8_t *threshold)
 get the action threshold More...
 
uint8_t adxl345_action_threshold_convert_to_register (adxl345_handle_t *handle, float g, uint8_t *reg)
 convert the action threshold to the register raw data More...
 
uint8_t adxl345_action_threshold_convert_to_data (adxl345_handle_t *handle, uint8_t reg, float *g)
 convert the register raw data to the action threshold More...
 
uint8_t adxl345_set_inaction_threshold (adxl345_handle_t *handle, uint8_t threshold)
 set the inaction threshold More...
 
uint8_t adxl345_get_inaction_threshold (adxl345_handle_t *handle, uint8_t *threshold)
 get the inaction threshold More...
 
uint8_t adxl345_inaction_threshold_convert_to_register (adxl345_handle_t *handle, float g, uint8_t *reg)
 convert the inaction threshold to the register raw data More...
 
uint8_t adxl345_inaction_threshold_convert_to_data (adxl345_handle_t *handle, uint8_t reg, float *g)
 convert the register raw data to the inaction threshold More...
 
uint8_t adxl345_set_inaction_time (adxl345_handle_t *handle, uint8_t t)
 set the inaction time More...
 
uint8_t adxl345_get_inaction_time (adxl345_handle_t *handle, uint8_t *t)
 get the inaction time More...
 
uint8_t adxl345_inaction_time_convert_to_register (adxl345_handle_t *handle, uint8_t s, uint8_t *reg)
 convert the inaction time to the register raw data More...
 
uint8_t adxl345_inaction_time_convert_to_data (adxl345_handle_t *handle, uint8_t reg, uint8_t *s)
 convert the register raw data to the inaction time More...
 
uint8_t adxl345_set_action_inaction (adxl345_handle_t *handle, adxl345_action_inaction_t type, adxl345_bool_t enable)
 enable or disable the action or inaction More...
 
uint8_t adxl345_get_action_inaction (adxl345_handle_t *handle, adxl345_action_inaction_t type, adxl345_bool_t *enable)
 get the action or inaction status More...
 
uint8_t adxl345_set_action_coupled (adxl345_handle_t *handle, adxl345_coupled_t coupled)
 set the action coupled More...
 
uint8_t adxl345_get_action_coupled (adxl345_handle_t *handle, adxl345_coupled_t *coupled)
 get the action coupled More...
 
uint8_t adxl345_set_inaction_coupled (adxl345_handle_t *handle, adxl345_coupled_t coupled)
 set the inaction coupled More...
 
uint8_t adxl345_get_inaction_coupled (adxl345_handle_t *handle, adxl345_coupled_t *coupled)
 get the inaction coupled More...
 
uint8_t adxl345_set_free_fall_threshold (adxl345_handle_t *handle, uint8_t threshold)
 set the free fall threshold More...
 
uint8_t adxl345_get_free_fall_threshold (adxl345_handle_t *handle, uint8_t *threshold)
 get the free fall threshold More...
 
uint8_t adxl345_free_fall_threshold_convert_to_register (adxl345_handle_t *handle, float g, uint8_t *reg)
 convert the free fall threshold to the register raw data More...
 
uint8_t adxl345_free_fall_threshold_convert_to_data (adxl345_handle_t *handle, uint8_t reg, float *g)
 convert the register raw data to the free fall threshold More...
 
uint8_t adxl345_set_free_fall_time (adxl345_handle_t *handle, uint8_t t)
 set the free fall time More...
 
uint8_t adxl345_get_free_fall_time (adxl345_handle_t *handle, uint8_t *t)
 get the free fall time More...
 
uint8_t adxl345_free_fall_time_convert_to_register (adxl345_handle_t *handle, uint16_t ms, uint8_t *reg)
 convert the free fall time to the register raw data More...
 
uint8_t adxl345_free_fall_time_convert_to_data (adxl345_handle_t *handle, uint8_t reg, uint16_t *ms)
 convert the register raw data to the free fall time More...
 
uint8_t adxl345_set_tap_axis (adxl345_handle_t *handle, adxl345_tap_axis_t axis, adxl345_bool_t enable)
 enable or disable the tap axis More...
 
uint8_t adxl345_get_tap_axis (adxl345_handle_t *handle, adxl345_tap_axis_t axis, adxl345_bool_t *enable)
 get the tap axis status More...
 
uint8_t adxl345_set_tap_suppress (adxl345_handle_t *handle, adxl345_bool_t enable)
 enable or disable the tap suppress More...
 
uint8_t adxl345_get_tap_suppress (adxl345_handle_t *handle, adxl345_bool_t *enable)
 get the tap suppress status More...
 
uint8_t adxl345_get_tap_status (adxl345_handle_t *handle, uint8_t *status)
 get the tap status More...
 
uint8_t adxl345_set_rate (adxl345_handle_t *handle, adxl345_rate_t rate)
 set the sampling rate More...
 
uint8_t adxl345_get_rate (adxl345_handle_t *handle, adxl345_rate_t *rate)
 get the sampling rate More...
 
uint8_t adxl345_set_interrupt (adxl345_handle_t *handle, adxl345_interrupt_t type, adxl345_bool_t enable)
 enable or disable the interrupt More...
 
uint8_t adxl345_get_interrupt (adxl345_handle_t *handle, adxl345_interrupt_t type, adxl345_bool_t *enable)
 get the interrupt status More...
 
uint8_t adxl345_set_interrupt_map (adxl345_handle_t *handle, adxl345_interrupt_t type, adxl345_interrupt_pin_t pin)
 set the interrupt map More...
 
uint8_t adxl345_get_interrupt_map (adxl345_handle_t *handle, adxl345_interrupt_t type, adxl345_interrupt_pin_t *pin)
 get the interrupt map More...
 
uint8_t adxl345_get_interrupt_source (adxl345_handle_t *handle, uint8_t *source)
 get the interrupt source More...
 
uint8_t adxl345_set_self_test (adxl345_handle_t *handle, adxl345_bool_t enable)
 enable or disable the self test More...
 
uint8_t adxl345_get_self_test (adxl345_handle_t *handle, adxl345_bool_t *enable)
 get the self test status More...
 
uint8_t adxl345_set_spi_wire (adxl345_handle_t *handle, adxl345_spi_wire_t wire)
 set the chip spi wire More...
 
uint8_t adxl345_get_spi_wire (adxl345_handle_t *handle, adxl345_spi_wire_t *wire)
 get the chip spi wire More...
 
uint8_t adxl345_set_interrupt_active_level (adxl345_handle_t *handle, adxl345_interrupt_active_level_t active_level)
 set the interrupt active level More...
 
uint8_t adxl345_get_interrupt_active_level (adxl345_handle_t *handle, adxl345_interrupt_active_level_t *active_level)
 get the interrupt active level More...
 
uint8_t adxl345_set_full_resolution (adxl345_handle_t *handle, adxl345_bool_t enable)
 enable or disable the full resolution More...
 
uint8_t adxl345_get_full_resolution (adxl345_handle_t *handle, adxl345_bool_t *enable)
 get the full resolution status More...
 
uint8_t adxl345_set_justify (adxl345_handle_t *handle, adxl345_justify_t enable)
 enable or disable the justify More...
 
uint8_t adxl345_get_justify (adxl345_handle_t *handle, adxl345_justify_t *enable)
 get the justify status More...
 
uint8_t adxl345_set_range (adxl345_handle_t *handle, adxl345_range_t range)
 set the chip range More...
 
uint8_t adxl345_get_range (adxl345_handle_t *handle, adxl345_range_t *range)
 get the chip range More...
 
uint8_t adxl345_set_mode (adxl345_handle_t *handle, adxl345_mode_t mode)
 set the chip mode More...
 
uint8_t adxl345_get_mode (adxl345_handle_t *handle, adxl345_mode_t *mode)
 get the chip mode More...
 
uint8_t adxl345_set_trigger_pin (adxl345_handle_t *handle, adxl345_interrupt_pin_t pin)
 set the trigger pin More...
 
uint8_t adxl345_get_trigger_pin (adxl345_handle_t *handle, adxl345_interrupt_pin_t *pin)
 get the trigger pin More...
 
uint8_t adxl345_set_watermark (adxl345_handle_t *handle, uint8_t level)
 set the fifo watermark More...
 
uint8_t adxl345_get_watermark (adxl345_handle_t *handle, uint8_t *level)
 get the fifo watermark More...
 
uint8_t adxl345_get_watermark_level (adxl345_handle_t *handle, uint8_t *level)
 get the current fifo watermark level More...
 
uint8_t adxl345_get_trigger_status (adxl345_handle_t *handle, adxl345_trigger_status_t *status)
 get the trigger status More...
 
uint8_t adxl345_set_link_activity_inactivity (adxl345_handle_t *handle, adxl345_bool_t enable)
 enable or disable the activity and inactivity linking More...
 
uint8_t adxl345_get_link_activity_inactivity (adxl345_handle_t *handle, adxl345_bool_t *enable)
 get the activity and inactivity linking status More...
 
uint8_t adxl345_set_auto_sleep (adxl345_handle_t *handle, adxl345_bool_t enable)
 enable or disable the auto sleep More...
 
uint8_t adxl345_get_auto_sleep (adxl345_handle_t *handle, adxl345_bool_t *enable)
 get the auto sleep status More...
 
uint8_t adxl345_set_measure (adxl345_handle_t *handle, adxl345_bool_t enable)
 enable or disable the measure More...
 
uint8_t adxl345_get_measure (adxl345_handle_t *handle, adxl345_bool_t *enable)
 get the measure status More...
 
uint8_t adxl345_set_sleep (adxl345_handle_t *handle, adxl345_bool_t enable)
 enable or disable the sleep mode More...
 
uint8_t adxl345_get_sleep (adxl345_handle_t *handle, adxl345_bool_t *enable)
 get the sleep mode status More...
 
uint8_t adxl345_set_sleep_frequency (adxl345_handle_t *handle, adxl345_sleep_frequency_t sleep_frequency)
 set the sleep frequency More...
 
uint8_t adxl345_get_sleep_frequency (adxl345_handle_t *handle, adxl345_sleep_frequency_t *sleep_frequency)
 get the sleep frequency More...
 
uint8_t adxl345_init (adxl345_handle_t *handle)
 initialize the chip More...
 
uint8_t adxl345_deinit (adxl345_handle_t *handle)
 close the chip More...
 
uint8_t adxl345_read (adxl345_handle_t *handle, int16_t(*raw)[3], float(*g)[3], uint16_t *len)
 read the data More...
 
uint8_t adxl345_irq_handler (adxl345_handle_t *handle)
 irq handler More...
 
uint8_t adxl345_set_reg (adxl345_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
 set the chip register More...
 
uint8_t adxl345_get_reg (adxl345_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
 get the chip register More...
 
uint8_t adxl345_info (adxl345_info_t *info)
 get chip's information More...
 

Detailed Description

driver adxl345 source file

Copyright (c) 2015 - present LibDriver All rights reserved

The MIT License (MIT)

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.

Version
2.0.0
Author
Shifeng Li
Date
2021-04-20

history

Date Version Author Description
2021/04/20 2.0 Shifeng Li format the code
2020/12/23 1.0 Shifeng Li first upload

Definition in file driver_adxl345.c.

Macro Definition Documentation

◆ ADXL345_REG_ACT_INACT_CTL

#define ADXL345_REG_ACT_INACT_CTL   0x27

act inact ctl register

Definition at line 66 of file driver_adxl345.c.

◆ ADXL345_REG_ACT_TAP_STATUS

#define ADXL345_REG_ACT_TAP_STATUS   0x2B

act tap status register

Definition at line 70 of file driver_adxl345.c.

◆ ADXL345_REG_BW_RATE

#define ADXL345_REG_BW_RATE   0x2C

bandwidth rate register

Definition at line 71 of file driver_adxl345.c.

◆ ADXL345_REG_DATA_FORMAT

#define ADXL345_REG_DATA_FORMAT   0x31

data format register

Definition at line 76 of file driver_adxl345.c.

◆ ADXL345_REG_DATAX0

#define ADXL345_REG_DATAX0   0x32

data X0 register

Definition at line 77 of file driver_adxl345.c.

◆ ADXL345_REG_DATAX1

#define ADXL345_REG_DATAX1   0x33

data X1 register

Definition at line 78 of file driver_adxl345.c.

◆ ADXL345_REG_DATAY0

#define ADXL345_REG_DATAY0   0x34

data Y0 register

Definition at line 79 of file driver_adxl345.c.

◆ ADXL345_REG_DATAY1

#define ADXL345_REG_DATAY1   0x35

data Y1 register

Definition at line 80 of file driver_adxl345.c.

◆ ADXL345_REG_DATAZ0

#define ADXL345_REG_DATAZ0   0x36

data Z0 register

Definition at line 81 of file driver_adxl345.c.

◆ ADXL345_REG_DATAZ1

#define ADXL345_REG_DATAZ1   0x37

data Z1 register

Definition at line 82 of file driver_adxl345.c.

◆ ADXL345_REG_DEVID

#define ADXL345_REG_DEVID   0x00

chip register definition

device id register

Definition at line 55 of file driver_adxl345.c.

◆ ADXL345_REG_DUR

#define ADXL345_REG_DUR   0x21

duration time register

Definition at line 60 of file driver_adxl345.c.

◆ ADXL345_REG_FIFO_CTL

#define ADXL345_REG_FIFO_CTL   0x38

fifo control register

Definition at line 83 of file driver_adxl345.c.

◆ ADXL345_REG_FIFO_STATUS

#define ADXL345_REG_FIFO_STATUS   0x39

fifo status register

Definition at line 84 of file driver_adxl345.c.

◆ ADXL345_REG_INT_ENABLE

#define ADXL345_REG_INT_ENABLE   0x2E

interrupt enable register

Definition at line 73 of file driver_adxl345.c.

◆ ADXL345_REG_INT_MAP

#define ADXL345_REG_INT_MAP   0x2F

interrupt map register

Definition at line 74 of file driver_adxl345.c.

◆ ADXL345_REG_INT_SOURCE

#define ADXL345_REG_INT_SOURCE   0x30

interrupt source register

Definition at line 75 of file driver_adxl345.c.

◆ ADXL345_REG_LATENT

#define ADXL345_REG_LATENT   0x22

latent register

Definition at line 61 of file driver_adxl345.c.

◆ ADXL345_REG_OFSX

#define ADXL345_REG_OFSX   0x1E

x offset register

Definition at line 57 of file driver_adxl345.c.

◆ ADXL345_REG_OFSY

#define ADXL345_REG_OFSY   0x1F

y offset register

Definition at line 58 of file driver_adxl345.c.

◆ ADXL345_REG_OFSZ

#define ADXL345_REG_OFSZ   0x20

z offset register

Definition at line 59 of file driver_adxl345.c.

◆ ADXL345_REG_POWER_CTL

#define ADXL345_REG_POWER_CTL   0x2D

power control register

Definition at line 72 of file driver_adxl345.c.

◆ ADXL345_REG_TAP_AXES

#define ADXL345_REG_TAP_AXES   0x2A

tap axes register

Definition at line 69 of file driver_adxl345.c.

◆ ADXL345_REG_THRESH_ACT

#define ADXL345_REG_THRESH_ACT   0x24

act thresh register

Definition at line 63 of file driver_adxl345.c.

◆ ADXL345_REG_THRESH_FF

#define ADXL345_REG_THRESH_FF   0x28

free fall thresh register

Definition at line 67 of file driver_adxl345.c.

◆ ADXL345_REG_THRESH_INACT

#define ADXL345_REG_THRESH_INACT   0x25

inact thresh register

Definition at line 64 of file driver_adxl345.c.

◆ ADXL345_REG_THRESH_TAP

#define ADXL345_REG_THRESH_TAP   0x1D

thresh tap register

Definition at line 56 of file driver_adxl345.c.

◆ ADXL345_REG_TIME_FF

#define ADXL345_REG_TIME_FF   0x29

free fall time register

Definition at line 68 of file driver_adxl345.c.

◆ ADXL345_REG_TIME_INACT

#define ADXL345_REG_TIME_INACT   0x26

inact time register

Definition at line 65 of file driver_adxl345.c.

◆ ADXL345_REG_WINDOW

#define ADXL345_REG_WINDOW   0x23

window register

Definition at line 62 of file driver_adxl345.c.

◆ CHIP_NAME

#define CHIP_NAME   "Analog Devices ADXL345"

chip register definition

chip name

Definition at line 43 of file driver_adxl345.c.

◆ DRIVER_VERSION

#define DRIVER_VERSION   2000

driver version

Definition at line 50 of file driver_adxl345.c.

◆ MANUFACTURER_NAME

#define MANUFACTURER_NAME   "Analog Devices"

manufacturer name

Definition at line 44 of file driver_adxl345.c.

◆ MAX_CURRENT

#define MAX_CURRENT   0.14f

chip max current

Definition at line 47 of file driver_adxl345.c.

◆ SUPPLY_VOLTAGE_MAX

#define SUPPLY_VOLTAGE_MAX   3.6f

chip max supply voltage

Definition at line 46 of file driver_adxl345.c.

◆ SUPPLY_VOLTAGE_MIN

#define SUPPLY_VOLTAGE_MIN   2.0f

chip min supply voltage

Definition at line 45 of file driver_adxl345.c.

◆ TEMPERATURE_MAX

#define TEMPERATURE_MAX   85.0f

chip max operating temperature

Definition at line 49 of file driver_adxl345.c.

◆ TEMPERATURE_MIN

#define TEMPERATURE_MIN   -40.0f

chip min operating temperature

Definition at line 48 of file driver_adxl345.c.