Go to the documentation of this file.
48 #define ADXL345_SPI_COMM 0
49 #define ADXL345_I2C_COMM 1
52 #define ADXL345_ADDRESS 0x1D
55 #define ADXL345_SPI_READ (1 << 7)
56 #define ADXL345_SPI_WRITE (0 << 7)
57 #define ADXL345_SPI_MB (1 << 6)
60 #define ADXL345_DEVID 0x00 // R Device ID.
61 #define ADXL345_THRESH_TAP 0x1D // R/W Tap threshold.
62 #define ADXL345_OFSX 0x1E // R/W X-axis offset.
63 #define ADXL345_OFSY 0x1F // R/W Y-axis offset.
64 #define ADXL345_OFSZ 0x20 // R/W Z-axis offset.
65 #define ADXL345_DUR 0x21 // R/W Tap duration.
66 #define ADXL345_LATENT 0x22 // R/W Tap latency.
67 #define ADXL345_WINDOW 0x23 // R/W Tap window.
68 #define ADXL345_THRESH_ACT 0x24 // R/W Activity threshold.
69 #define ADXL345_THRESH_INACT 0x25 // R/W Inactivity threshold.
70 #define ADXL345_TIME_INACT 0x26 // R/W Inactivity time.
71 #define ADXL345_ACT_INACT_CTL 0x27 // R/W Axis enable control for activity
73 #define ADXL345_THRESH_FF 0x28 // R/W Free-fall threshold.
74 #define ADXL345_TIME_FF 0x29 // R/W Free-fall time.
75 #define ADXL345_TAP_AXES 0x2A // R/W Axis control for tap/double tap.
76 #define ADXL345_ACT_TAP_STATUS 0x2B // R Source of tap/double tap.
77 #define ADXL345_BW_RATE 0x2C // R/W Data rate and power mode control.
78 #define ADXL345_POWER_CTL 0x2D // R/W Power saving features control.
79 #define ADXL345_INT_ENABLE 0x2E // R/W Interrupt enable control.
80 #define ADXL345_INT_MAP 0x2F // R/W Interrupt mapping control.
81 #define ADXL345_INT_SOURCE 0x30 // R Source of interrupts.
82 #define ADXL345_DATA_FORMAT 0x31 // R/W Data format control.
83 #define ADXL345_DATAX0 0x32 // R X-Axis Data 0.
84 #define ADXL345_DATAX1 0x33 // R X-Axis Data 1.
85 #define ADXL345_DATAY0 0x34 // R Y-Axis Data 0.
86 #define ADXL345_DATAY1 0x35 // R Y-Axis Data 1.
87 #define ADXL345_DATAZ0 0x36 // R Z-Axis Data 0.
88 #define ADXL345_DATAZ1 0x37 // R Z-Axis Data 1.
89 #define ADXL345_FIFO_CTL 0x38 // R/W FIFO control.
90 #define ADXL345_FIFO_STATUS 0x39 // R FIFO status.
91 #define ADXL345_TAP_SIGN 0x3A // R Sign and source for single tap/double tap.
92 #define ADXL345_ORIENT_CONF 0x3B // R/W Orientation configuration.
93 #define ADXL345_ORIENT 0x3C // R Orientation status.
96 #define ADXL345_ACT_ACDC (1 << 7)
97 #define ADXL345_ACT_X_EN (1 << 6)
98 #define ADXL345_ACT_Y_EN (1 << 5)
99 #define ADXL345_ACT_Z_EN (1 << 4)
100 #define ADXL345_INACT_ACDC (1 << 3)
101 #define ADXL345_INACT_X_EN (1 << 2)
102 #define ADXL345_INACT_Y_EN (1 << 1)
103 #define ADXL345_INACT_Z_EN (1 << 0)
106 #define ADXL345_SUPPRESS (1 << 3)
107 #define ADXL345_TAP_X_EN (1 << 2)
108 #define ADXL345_TAP_Y_EN (1 << 1)
109 #define ADXL345_TAP_Z_EN (1 << 0)
112 #define ADXL345_ACT_X_SRC (1 << 6)
113 #define ADXL345_ACT_Y_SRC (1 << 5)
114 #define ADXL345_ACT_Z_SRC (1 << 4)
115 #define ADXL345_ASLEEP (1 << 3)
116 #define ADXL345_TAP_X_SRC (1 << 2)
117 #define ADXL345_TAP_Y_SRC (1 << 1)
118 #define ADXL345_TAP_Z_SRC (1 << 0)
121 #define ADXL345_LOW_POWER (1 << 4)
122 #define ADXL345_RATE(x) ((x) & 0xF)
125 #define ADXL345_PCTL_LINK (1 << 5)
126 #define ADXL345_PCTL_AUTO_SLEEP (1 << 4)
127 #define ADXL345_PCTL_MEASURE (1 << 3)
128 #define ADXL345_PCTL_SLEEP (1 << 2)
129 #define ADXL345_PCTL_WAKEUP(x) ((x) & 0x3)
132 #define ADXL345_DATA_READY (1 << 7)
133 #define ADXL345_SINGLE_TAP (1 << 6)
134 #define ADXL345_DOUBLE_TAP (1 << 5)
135 #define ADXL345_ACTIVITY (1 << 4)
136 #define ADXL345_INACTIVITY (1 << 3)
137 #define ADXL345_FREE_FALL (1 << 2)
138 #define ADXL345_WATERMARK (1 << 1)
139 #define ADXL345_OVERRUN (1 << 0)
140 #define ADXL345_ORIENTATION (1 << 0)
143 #define ADXL345_SELF_TEST (1 << 7)
144 #define ADXL345_SPI (1 << 6)
145 #define ADXL345_INT_INVERT (1 << 5)
146 #define ADXL345_FULL_RES (1 << 3)
147 #define ADXL345_JUSTIFY (1 << 2)
148 #define ADXL345_RANGE(x) ((x) & 0x3)
151 #define ADXL345_RANGE_PM_2G 0
152 #define ADXL345_RANGE_PM_4G 1
153 #define ADXL345_RANGE_PM_8G 2
154 #define ADXL345_RANGE_PM_16G 3
157 #define ADXL345_FIFO_MODE(x) (((x) & 0x3) << 6)
158 #define ADXL345_TRIGGER (1 << 5)
159 #define ADXL345_SAMPLES(x) ((x) & 0x1F)
162 #define ADXL345_FIFO_BYPASS 0
163 #define ADXL345_FIFO_FIFO 1
164 #define ADXL345_FIFO_STREAM 2
165 #define ADXL345_FIFO_TRIGGER 3
168 #define ADXL345_FIFO_TRIG (1 << 7)
169 #define ADXL345_ENTRIES(x) ((x) & 0x3F)
172 #define ADXL345_INT_ORIENT(x) (((x) & 0x1) << 7)
173 #define ADXL345_DEAD_ZONE(x) (((x) & 0x7) << 4)
174 #define ADXL345_INT_3D(x) (((x) & 0x1) << 3)
175 #define ADXL345_DIVISOR(x) ((x) & 7)
178 #define ADXL345_ID 0xE5
180 #define ADXL346_ID 0xE6
183 #define ADXL345_SCALE_FACTOR 0.0039
272 uint8_t register_address);
276 uint8_t register_address,
277 uint8_t register_value);
322 uint8_t inact_on_off,
325 uint8_t inact_thresh,
339 uint8_t orient_on_off,
void adxl345_set_orientation_detection(struct adxl345_dev *dev, uint8_t orient_int, uint8_t orient_on_off, uint8_t int_3d, enum adxl345_dead_zone_angle dead_zone, enum adxl345_divisor_bandwidth divisor)
Enables/disables the orientation detection (only for adxl346).
Definition: adxl345.c:579
#define ADXL345_WINDOW
Definition: adxl345.h:67
struct no_os_i2c_desc * i2c_desc
Definition: adxl345.h:234
void adxl345_get_g_xyz(struct adxl345_dev *dev, float *x, float *y, float *z)
Reads the raw output data of each axis and converts it to g.
Definition: adxl345.c:267
Structure holding the parameters for ADXL345 device initialization.
Definition: adxl345.h:251
#define ADXL345_OFSY
Definition: adxl345.h:63
@ DEGREES_20_4
Definition: adxl345.h:206
int32_t no_os_i2c_write(struct no_os_i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Write data to slave device.
Definition: no_os_i2c.c:159
#define ADXL345_ACT_INACT_CTL
Definition: adxl345.h:71
int32_t no_os_i2c_init(struct no_os_i2c_desc **desc, const struct no_os_i2c_init_param *param)
Initialize the I2C communication peripheral.
Definition: no_os_i2c.c:52
void adxl345_set_free_fall_detection(struct adxl345_dev *dev, uint8_t ff_on_off, uint8_t ff_thresh, uint8_t ff_time, uint8_t ff_int)
Enables/disables the free-fall detection.
Definition: adxl345.c:525
#define ADXL345_INT_ENABLE
Definition: adxl345.h:79
uint8_t full_resolution_set
Definition: adxl345.h:263
void adxl345_set_range_resolution(struct adxl345_dev *dev, uint8_t g_range, uint8_t full_res)
Selects the measurement range.
Definition: adxl345.c:659
@ ODR_DIV_200
Definition: adxl345.h:222
#define ADXL345_ACT_Y_EN
Definition: adxl345.h:98
int32_t no_os_spi_write_and_read(struct no_os_spi_desc *desc, uint8_t *data, uint16_t bytes_number)
Write and read data to/from SPI.
Definition: no_os_spi.c:159
void adxl345_set_free_fall_detection(struct adxl345_dev *dev, uint8_t ff_on_off, uint8_t ff_thresh, uint8_t ff_time, uint8_t ff_int)
Enables/disables the free-fall detection.
Definition: adxl345.c:525
#define ADXL345_SPI_MB
Definition: adxl345.h:57
#define ADXL345_THRESH_INACT
Definition: adxl345.h:69
Header file of SPI Interface.
@ DEGREES_10_2
Definition: adxl345.h:204
uint8_t communication_type
Definition: adxl345.h:240
int32_t no_os_i2c_remove(struct no_os_i2c_desc *desc)
Free the resources allocated by no_os_i2c_init().
Definition: no_os_i2c.c:113
#define ADXL345_ID
Definition: adxl345.h:178
@ DEGREES_41_4
Definition: adxl345.h:210
int32_t adxl345_init(struct adxl345_dev **device, struct adxl345_init_param init_param)
Initializes the communication peripheral and checks if the ADXL345 part is present.
Definition: adxl345.c:133
int32_t adxl345_remove(struct adxl345_dev *dev)
Free the resources allocated by adxl345_init().
Definition: adxl345.c:169
void adxl345_set_inactivity_detection(struct adxl345_dev *dev, uint8_t inact_on_off, uint8_t inact_axes, uint8_t inact_ac_dc, uint8_t inact_thresh, uint8_t inact_time, uint8_t inact_int)
Enables/disables the inactivity detection.
Definition: adxl345.c:460
#define ADXL345_DIVISOR(x)
Definition: adxl345.h:175
Definition: ad9361_util.h:69
@ DEGREES_36_1
Definition: adxl345.h:209
#define ADXL345_DEAD_ZONE(x)
Definition: adxl345.h:173
uint8_t selected_range
Definition: adxl345.h:261
#define ADXL345_TIME_INACT
Definition: adxl345.h:70
void adxl345_set_register_value(struct adxl345_dev *dev, uint8_t register_address, uint8_t register_value)
Writes data into a register.
Definition: adxl345.c:97
#define ADXL345_THRESH_FF
Definition: adxl345.h:73
#define ADXL345_LATENT
Definition: adxl345.h:66
#define ADXL345_INACT_Z_EN
Definition: adxl345.h:103
#define ADXL345_DATAX0
Definition: adxl345.h:83
uint8_t adxl345_get_register_value(struct adxl345_dev *dev, uint8_t register_address)
Reads the value of a register.
Definition: adxl345.c:61
void adxl345_set_activity_detection(struct adxl345_dev *dev, uint8_t act_on_off, uint8_t act_axes, uint8_t act_ac_dc, uint8_t act_thresh, uint8_t act_int)
Enables/disables the activity detection.
Definition: adxl345.c:392
#define ADXL345_PCTL_MEASURE
Definition: adxl345.h:127
void adxl345_set_register_value(struct adxl345_dev *dev, uint8_t register_address, uint8_t register_value)
Writes data into a register.
Definition: adxl345.c:97
int32_t adxl345_init(struct adxl345_dev **device, struct adxl345_init_param init_param)
Initializes the communication peripheral and checks if the ADXL345 part is present.
Definition: adxl345.c:133
adxl345_divisor_bandwidth
ADXL346 Divisor bandwidth encoding.
Definition: adxl345.h:217
#define ADXL345_INACT_Y_EN
Definition: adxl345.h:102
#define ADXL345_TAP_AXES
Definition: adxl345.h:75
#define ADXL345_ACT_ACDC
Definition: adxl345.h:96
void adxl345_set_offset(struct adxl345_dev *dev, uint8_t x_offset, uint8_t y_offset, uint8_t z_offset)
Sets an offset value for each axis (Offset Calibration).
Definition: adxl345.c:628
#define ADXL345_ACTIVITY
Definition: adxl345.h:135
#define ADXL345_INT_ORIENT(x)
Definition: adxl345.h:172
enum adxl345_type dev_type
Definition: adxl345.h:238
Header file of ADXL345 Driver.
#define ADXL345_SPI_COMM
Definition: adxl345.h:48
#define ADXL345_DOUBLE_TAP
Definition: adxl345.h:134
#define ADXL345_POWER_CTL
Definition: adxl345.h:78
#define ADXL345_DUR
Definition: adxl345.h:65
@ ODR_DIV_100
Definition: adxl345.h:221
void adxl345_set_tap_detection(struct adxl345_dev *dev, uint8_t tap_type, uint8_t tap_axes, uint8_t tap_dur, uint8_t tap_latent, uint8_t tap_window, uint8_t tap_thresh, uint8_t tap_int)
Enables/disables the tap detection.
Definition: adxl345.c:313
void adxl345_get_xyz(struct adxl345_dev *dev, int16_t *x, int16_t *y, int16_t *z)
Reads the raw output data of each axis.
Definition: adxl345.c:218
uint8_t communication_type
Definition: adxl345.h:259
#define ADXL345_SPI_READ
Definition: adxl345.h:55
#define ADXL345_DEVID
Definition: adxl345.h:60
#define ADXL345_INT_3D(x)
Definition: adxl345.h:174
ADXL345 Device structure.
Definition: adxl345.h:232
struct no_os_spi_init_param spi_init
Definition: adxl345.h:255
Structure holding SPI descriptor.
Definition: no_os_spi.h:192
#define ADXL345_INACT_ACDC
Definition: adxl345.h:100
#define ADXL345_OFSZ
Definition: adxl345.h:64
void adxl345_set_power_mode(struct adxl345_dev *dev, uint8_t pwr_mode)
Places the device into standby/measure mode.
Definition: adxl345.c:193
#define ADXL345_TAP_Y_EN
Definition: adxl345.h:108
#define ADXL345_FULL_RES
Definition: adxl345.h:146
void adxl345_get_xyz(struct adxl345_dev *dev, int16_t *x, int16_t *y, int16_t *z)
Reads the raw output data of each axis.
Definition: adxl345.c:218
@ DEGREES_25_5
Definition: adxl345.h:207
@ ODR_DIV_9
Definition: adxl345.h:218
void adxl345_set_range_resolution(struct adxl345_dev *dev, uint8_t g_range, uint8_t full_res)
Selects the measurement range.
Definition: adxl345.c:659
@ ODR_DIV_1600
Definition: adxl345.h:225
@ ODR_DIV_400
Definition: adxl345.h:223
void adxl345_set_power_mode(struct adxl345_dev *dev, uint8_t pwr_mode)
Places the device into standby/measure mode.
Definition: adxl345.c:193
Structure holding I2C address descriptor.
Definition: no_os_i2c.h:101
#define ADXL345_INT_MAP
Definition: adxl345.h:80
@ DEGREES_30_8
Definition: adxl345.h:208
int32_t no_os_i2c_read(struct no_os_i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Read data from slave device.
Definition: no_os_i2c.c:190
void adxl345_set_activity_detection(struct adxl345_dev *dev, uint8_t act_on_off, uint8_t act_axes, uint8_t act_ac_dc, uint8_t act_thresh, uint8_t act_int)
Enables/disables the activity detection.
Definition: adxl345.c:392
void * no_os_malloc(size_t size)
Allocate memory and return a pointer to it.
Definition: chibios_alloc.c:43
Header file of I2C Interface.
struct no_os_spi_desc * spi_desc
Definition: adxl345.h:236
@ DEGREES_15_2
Definition: adxl345.h:205
void adxl345_set_orientation_detection(struct adxl345_dev *dev, uint8_t orient_int, uint8_t orient_on_off, uint8_t int_3d, enum adxl345_dead_zone_angle dead_zone, enum adxl345_divisor_bandwidth divisor)
Enables/disables the orientation detection (only for adxl346).
Definition: adxl345.c:579
@ ODR_DIV_800
Definition: adxl345.h:224
#define ADXL345_ACT_X_EN
Definition: adxl345.h:97
void no_os_free(void *ptr)
Deallocate memory previously allocated by a call to no_os_calloc or no_os_malloc.
Definition: chibios_alloc.c:69
#define ADXL345_ORIENTATION
Definition: adxl345.h:140
@ ODR_DIV_22
Definition: adxl345.h:219
#define ADXL345_TAP_X_EN
Definition: adxl345.h:107
#define ADXL345_THRESH_TAP
Definition: adxl345.h:61
void adxl345_set_inactivity_detection(struct adxl345_dev *dev, uint8_t inact_on_off, uint8_t inact_axes, uint8_t inact_ac_dc, uint8_t inact_thresh, uint8_t inact_time, uint8_t inact_int)
Enables/disables the inactivity detection.
Definition: adxl345.c:460
int32_t adxl345_remove(struct adxl345_dev *dev)
Free the resources allocated by adxl345_init().
Definition: adxl345.c:169
void adxl345_get_g_xyz(struct adxl345_dev *dev, float *x, float *y, float *z)
Reads the raw output data of each axis and converts it to g.
Definition: adxl345.c:267
#define ADXL345_ORIENT_CONF
Definition: adxl345.h:92
Structure holding the parameters for I2C initialization.
Definition: no_os_i2c.h:64
#define ADXL345_SPI_WRITE
Definition: adxl345.h:56
#define ADXL346_ID
Definition: adxl345.h:180
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:113
uint8_t selected_range
Definition: adxl345.h:242
uint8_t adxl345_get_register_value(struct adxl345_dev *dev, uint8_t register_address)
Reads the value of a register.
Definition: adxl345.c:61
#define ADXL345_SINGLE_TAP
Definition: adxl345.h:133
int32_t no_os_spi_remove(struct no_os_spi_desc *desc)
Free the resources allocated by no_os_spi_init().
Definition: no_os_spi.c:116
@ DEGREES_5_1
Definition: adxl345.h:203
#define ADXL345_SCALE_FACTOR
Definition: adxl345.h:183
#define ADXL345_RANGE(x)
Definition: adxl345.h:148
int32_t no_os_spi_init(struct no_os_spi_desc **desc, const struct no_os_spi_init_param *param)
Initialize the SPI communication peripheral.
Definition: no_os_spi.c:52
void adxl345_set_offset(struct adxl345_dev *dev, uint8_t x_offset, uint8_t y_offset, uint8_t z_offset)
Sets an offset value for each axis (Offset Calibration).
Definition: adxl345.c:628
#define ADXL345_THRESH_ACT
Definition: adxl345.h:68
#define ADXL345_INACT_X_EN
Definition: adxl345.h:101
#define ADXL345_DATA_FORMAT
Definition: adxl345.h:82
#define ADXL345_TAP_Z_EN
Definition: adxl345.h:109
#define ADXL345_INACTIVITY
Definition: adxl345.h:136
uint8_t full_resolution_set
Definition: adxl345.h:244
#define ADXL345_ACT_Z_EN
Definition: adxl345.h:99
enum adxl345_type dev_type
Definition: adxl345.h:257
#define ADXL345_OFSX
Definition: adxl345.h:62
#define ADXL345_FREE_FALL
Definition: adxl345.h:137
void adxl345_set_tap_detection(struct adxl345_dev *dev, uint8_t tap_type, uint8_t tap_axes, uint8_t tap_dur, uint8_t tap_latent, uint8_t tap_window, uint8_t tap_thresh, uint8_t tap_int)
Enables/disables the tap detection.
Definition: adxl345.c:313
adxl345_dead_zone_angle
ADXL346 Dead zone angle encoding.
Definition: adxl345.h:202
@ ID_ADXL346
Definition: adxl345.h:195
struct no_os_i2c_init_param i2c_init
Definition: adxl345.h:253
@ ID_ADXL345
Definition: adxl345.h:194
adxl345_type
ADXL345 Supported devices.
Definition: adxl345.h:193
@ ODR_DIV_50
Definition: adxl345.h:220
#define ADXL345_TIME_FF
Definition: adxl345.h:74
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:140