-
Notifications
You must be signed in to change notification settings - Fork 0
/
ADXL345.h
80 lines (71 loc) · 2.57 KB
/
ADXL345.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef ADXL345_H
#define ADXL345_H
char adxl345_read(char address);
void adxl345_write(char address, char value);
void adxl345_getxyz(int16_t *x, int16_t *y, int16_t *z);
//*******************************************************
// ADXL345 Definitions
//*******************************************************
#define READ 0x8000
//ADXL Register Map
#define DEVID 0x00 //Device ID Register
#define THRESH_TAP 0x1D //Tap Threshold
#define OFSX 0x1E //X-axis offset
#define OFSY 0x1F //Y-axis offset
#define OFSZ 0x20 //Z-axis offset
#define DUR 0x21 //Tap Duration
#define Latent 0x22 //Tap latency
#define Window 0x23 //Tap window
#define THRESH_ACT 0x24 //Activity Threshold
#define THRESH_INACT 0x25 //Inactivity Threshold
#define TIME_INACT 0x26 //Inactivity Time
#define ACT_INACT_CTL 0x27 //Axis enable control for activity and inactivity detection
#define THRESH_FF 0x28 //free-fall threshold
#define TIME_FF 0x29 //Free-Fall Time
#define TAP_AXES 0x2A //Axis control for tap/double tap
#define ACT_TAP_STATUS 0x2B //Source of tap/double tap
#define BW_RATE 0x2C //Data rate and power mode control
#define POWER_CTL 0x2D //Power Control Register
#define INT_ENABLE 0x2E //Interrupt Enable Control
#define INT_MAP 0x2F //Interrupt Mapping Control
#define INT_SOURCE 0x30 //Source of interrupts
#define DATA_FORMAT 0x31 //Data format control
#define DATAX0 0x32 //X-Axis Data 0
#define DATAX1 0x33 //X-Axis Data 1
#define DATAY0 0x34 //Y-Axis Data 0
#define DATAY1 0x35 //Y-Axis Data 1
#define DATAZ0 0x36 //Z-Axis Data 0
#define DATAZ1 0x37 //Z-Axis Data 1
#define FIFO_CTL 0x38 //FIFO control
#define FIFO_STATUS 0x39 //FIFO status
//Power Control Register Bits
#define WU_0 (1<<0) //Wake Up Mode - Bit 0
#define WU_1 (1<<1) //Wake Up mode - Bit 1
#define SLEEP (1<<2) //Sleep Mode
#define MEASURE (1<<3) //Measurement Mode
#define AUTO_SLP (1<<4) //Auto Sleep Mode bit
#define LINK (1<<5) //Link bit
//Interrupt Enable/Interrupt Map/Interrupt Source Register Bits
#define OVERRUN (1<<0)
#define WATERMARK (1<<1)
#define FREE_FALL (1<<2)
#define INACTIVITY (1<<3)
#define ACTIVITY (1<<4)
#define DOUBLE_TAP (1<<5)
#define SINGLE_TAP (1<<6)
#define DATA_READY (1<<7)
//Data Format Bits
#define RANGE_0 (1<<0)
#define RANGE_1 (1<<1)
#define JUSTIFY (1<<2)
#define FULL_RES (1<<3)
#define INT_INVERT (1<<5)
#define SPI (1<<6)
#define SELF_TEST (1<<7)
#define RATE_100HZ 10
#define RATE_50HZ 9
#define RATE_25HZ 8
#define RATE_12HZ 7
#define RATE_6HZ 6
#define RATE_3HZ 5
#endif