adxl345.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef __ADXL345_H__
00042 #define __ADXL345_H__
00043 #include <stdio.h>
00044 #include "i2cmaster.h"
00045
00046 #define DEBUGLEDS 0
00047 #if DEBUGLEDS
00048 #undef LEDS_ON(x)
00049 #undef LEDS_OFF(x)
00050 #define LEDS_ON(x) (LEDS_PxOUT &= ~x)
00051 #define LEDS_OFF(x) (LEDS_PxOUT |= x)
00052 #else
00053 #undef LEDS_ON
00054 #undef LEDS_OFF
00055 #define LEDS_ON(x)
00056 #define LEDS_OFF(x)
00057 #endif
00058
00059 #define LEDS_R 0x10
00060 #define LEDS_G 0x40
00061 #define LEDS_B 0x20
00062 #define L_ON(x) (LEDS_PxOUT &= ~x)
00063 #define L_OFF(x) (LEDS_PxOUT |= x)
00064
00065
00066 #ifndef P1SEL2_
00067 #define P1SEL2_ 0x0041
00068 sfrb(P1SEL2, P1SEL2_);
00069 #endif
00070
00071
00072 enum ADXL345_AXIS {
00073 X_AXIS = 0,
00074 Y_AXIS = 2,
00075 Z_AXIS = 4,
00076 };
00077
00078
00079
00080
00081 void accm_init(void);
00082
00083
00084
00085
00086
00087
00088 void accm_write_reg(u8_t reg, u8_t val);
00089
00090
00091
00092
00093
00094
00095
00096
00097 void accm_write_stream(u8_t len, u8_t *data);
00098
00099
00100
00101
00102
00103
00104 u8_t accm_read_reg(u8_t reg);
00105
00106
00107
00108
00109
00110
00111
00112 void accm_read_stream(u8_t reg, u8_t len, u8_t *whereto);
00113
00114
00115
00116
00117
00118 int16_t accm_read_axis(enum ADXL345_AXIS axis);
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 void accm_set_grange(u8_t grange);
00130
00131
00132
00133 void accm_set_irq(uint8_t int1, uint8_t int2);
00134
00135
00136
00137
00138
00139 #define ACCM_REGISTER_INT1_CB(ptr) accm_int1_cb = ptr;
00140 #define ACCM_REGISTER_INT2_CB(ptr) accm_int2_cb = ptr;
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 #define SUPPRESS_TIME_INT1 CLOCK_SECOND/4
00159 #define SUPPRESS_TIME_INT2 CLOCK_SECOND/4
00160
00161
00162 #define ADXL345_THRESH_TAP_DEFAULT 0x48 // 4.5g (0x30 == 3.0g) (datasheet: 3g++)
00163 #define ADXL345_OFSX_DEFAULT 0x00 // for individual units calibration purposes
00164 #define ADXL345_OFSY_DEFAULT 0x00
00165 #define ADXL345_OFSZ_DEFAULT 0x00
00166 #define ADXL345_DUR_DEFAULT 0x20 // 20 ms (datasheet: 10ms++)
00167 #define ADXL345_LATENT_DEFAULT 0x50 // 100 ms (datasheet: 20ms++)
00168 #define ADXL345_WINDOW_DEFAULT 0xFF // 320 ms (datasheet: 80ms++)
00169 #define ADXL345_THRESH_ACT_DEFAULT 0x15 // 1.3g (62.5 mg/LSB)
00170 #define ADXL345_THRESH_INACT_DEFAULT 0x08 // 0.5g (62.5 mg/LSB)
00171 #define ADXL345_TIME_INACT_DEFAULT 0x02 // 2 s (1 s/LSB)
00172 #define ADXL345_ACT_INACT_CTL_DEFAULT 0xFF // all axis involved, ac-coupled
00173 #define ADXL345_THRESH_FF_DEFAULT 0x09 // 563 mg
00174 #define ADXL345_TIME_FF_DEFAULT 0x20 // 160 ms
00175 #define ADXL345_TAP_AXES_DEFAULT 0x07 // all axis, no suppression
00176
00177 #define ADXL345_BW_RATE_DEFAULT (0x00|ADXL345_SRATE_100) // 100 Hz, normal operation
00178 #define ADXL345_POWER_CTL_DEFAULT 0x28 // link bit set, no autosleep, start normal measuring
00179 #define ADXL345_INT_ENABLE_DEFAULT 0x00 // no interrupts enabled
00180 #define ADXL345_INT_MAP_DEFAULT 0x00 // all mapped to int_1
00181
00182
00183
00184
00185
00186
00187
00188 #define ADXL345_DATA_FORMAT_DEFAULT (0x00|ADXL345_RANGE_2G) // right-justify, 2g, 10-bit mode, int is active high
00189 #define ADXL345_FIFO_CTL_DEFAULT 0x00 // FIFO bypass mode
00190
00191
00192
00193
00194 #define ADXL345_ADDR 0x53
00195
00196
00197 #define ADXL345_DEVID 0x00 // read only
00198
00199 #define ADXL345_THRESH_TAP 0x1D
00200 #define ADXL345_OFSX 0x1E
00201 #define ADXL345_OFSY 0x1F
00202 #define ADXL345_OFSZ 0x20
00203 #define ADXL345_DUR 0x21
00204 #define ADXL345_LATENT 0x22
00205 #define ADXL345_WINDOW 0x23
00206 #define ADXL345_THRESH_ACT 0x24
00207 #define ADXL345_THRESH_INACT 0x25
00208 #define ADXL345_TIME_INACT 0x26
00209 #define ADXL345_ACT_INACT_CTL 0x27
00210 #define ADXL345_THRESH_FF 0x28
00211 #define ADXL345_TIME_FF 0x29
00212 #define ADXL345_TAP_AXES 0x2A
00213 #define ADXL345_ACT_TAP_STATUS 0x2B // read only
00214 #define ADXL345_BW_RATE 0x2C
00215 #define ADXL345_POWER_CTL 0x2D
00216 #define ADXL345_INT_ENABLE 0x2E
00217 #define ADXL345_INT_MAP 0x2F
00218 #define ADXL345_INT_SOURCE 0x30 // read only
00219 #define ADXL345_DATA_FORMAT 0x31
00220 #define ADXL345_DATAX0 0x32 // read only, LSByte X, two's complement
00221 #define ADXL345_DATAX1 0x33 // read only, MSByte X
00222 #define ADXL345_DATAY0 0x34 // read only, LSByte Y
00223 #define ADXL345_DATAY1 0x35 // read only, MSByte X
00224 #define ADXL345_DATAZ0 0x36 // read only, LSByte Z
00225 #define ADXL345_DATAZ1 0x37 // read only, MSByte X
00226 #define ADXL345_FIFO_CTL 0x38
00227 #define ADXL345_FIFO_STATUS 0x39 // read only
00228
00229
00230 #define ADXL345_INT_DISABLE 0X00 // used for disabling interrupts
00231 #define ADXL345_INT_OVERRUN 0X01
00232 #define ADXL345_INT_WATERMARK 0X02
00233 #define ADXL345_INT_FREEFALL 0X04
00234 #define ADXL345_INT_INACTIVITY 0X08
00235 #define ADXL345_INT_ACTIVITY 0X10
00236 #define ADXL345_INT_DOUBLETAP 0X20
00237 #define ADXL345_INT_TAP 0X40
00238 #define ADXL345_INT_DATAREADY 0X80
00239
00240
00241 #define ADXL345_DIR P1DIR
00242 #define ADXL345_PIN P1PIN
00243 #define ADXL345_REN P1REN
00244 #define ADXL345_SEL P1SEL
00245 #define ADXL345_SEL2 P1SEL2
00246 #define ADXL345_INT1_PIN (1<<6) // P1.6
00247 #define ADXL345_INT2_PIN (1<<7) // P1.7
00248 #define ADXL345_IES P1IES
00249 #define ADXL345_IE P1IE
00250 #define ADXL345_IFG P1IFG
00251 #define ADXL345_VECTOR PORT1_VECTOR
00252
00253
00254 #define ADXL345_RANGE_2G 0x00
00255 #define ADXL345_RANGE_4G 0x01
00256 #define ADXL345_RANGE_8G 0x02
00257 #define ADXL345_RANGE_16G 0x03
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269 #define ADXL345_SRATE_3200 0x0F // XXX NB don't use at all as I2C data rate<= 400kHz (see datasheet)
00270 #define ADXL345_SRATE_1600 0x0E // XXX NB don't use at all as I2C data rate<= 400kHz (see datasheet)
00271 #define ADXL345_SRATE_800 0x0D // when I2C data rate == 400 kHz
00272 #define ADXL345_SRATE_400 0x0C // when I2C data rate == 400 kHz
00273 #define ADXL345_SRATE_200 0x0B // when I2C data rate >= 100 kHz
00274 #define ADXL345_SRATE_100 0x0A // when I2C data rate >= 100 kHz
00275 #define ADXL345_SRATE_50 0x09 // when I2C data rate >= 100 kHz
00276 #define ADXL345_SRATE_25 0x08 // when I2C data rate >= 100 kHz
00277 #define ADXL345_SRATE_12_5 0x07 // 12.5 Hz, when I2C data rate >= 100 kHz
00278 #define ADXL345_SRATE_6_25 0x06 // when I2C data rate >= 100 kHz
00279 #define ADXL345_SRATE_3_13 0x05 // when I2C data rate >= 100 kHz
00280 #define ADXL345_SRATE_1_56 0x04 // when I2C data rate >= 100 kHz
00281 #define ADXL345_SRATE_0_78 0x03 // when I2C data rate >= 100 kHz
00282 #define ADXL345_SRATE_0_39 0x02 // when I2C data rate >= 100 kHz
00283 #define ADXL345_SRATE_0_20 0x01 // when I2C data rate >= 100 kHz
00284 #define ADXL345_SRATE_0_10 0x00 // 0.10 Hz, when I2C data rate >= 100 kHz
00285
00286
00287 void (*accm_int1_cb)(u8_t reg);
00288 void (*accm_int2_cb)(u8_t reg);
00289
00290
00291
00292 process_event_t int1_event, int2_event;
00293
00294 #define ACCM_INT1 0x01
00295 #define ACCM_INT2 0x02
00296
00297
00298
00299 #endif
00300