base program for tilt measurement

Dependencies:   COG4050_ADT7420 ADXL362

Fork of COG4050_adxl355_adxl357-ver2 by ADI_CAC

Committer:
vtoffoli
Date:
Tue Aug 14 06:49:07 2018 +0000
Revision:
6:45d2393ef468
Parent:
4:23b53636b576
Child:
7:5aaa09c40283
update 14.08.2018

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vtoffoli 2:14dc1ec57f3b 1
vtoffoli 2:14dc1ec57f3b 2 #ifndef ADXL355_H_
vtoffoli 2:14dc1ec57f3b 3 #define ADXL355_H_
vtoffoli 2:14dc1ec57f3b 4
vtoffoli 2:14dc1ec57f3b 5 class ADXL355
vtoffoli 2:14dc1ec57f3b 6 {
vtoffoli 2:14dc1ec57f3b 7 public:
vtoffoli 6:45d2393ef468 8 const static float t_sens = -9.05;
vtoffoli 6:45d2393ef468 9 const static float t_bias = 1852;
vtoffoli 6:45d2393ef468 10 float axis355_sens;
vtoffoli 6:45d2393ef468 11 float axis357_sens;
vtoffoli 6:45d2393ef468 12
vtoffoli 2:14dc1ec57f3b 13 // -------------------------- //
vtoffoli 2:14dc1ec57f3b 14 // REGISTERS //
vtoffoli 2:14dc1ec57f3b 15 // -------------------------- //
vtoffoli 2:14dc1ec57f3b 16 typedef enum {
vtoffoli 2:14dc1ec57f3b 17 DEVID_AD = 0x00,
vtoffoli 2:14dc1ec57f3b 18 DEVID_MST = 0x01,
vtoffoli 2:14dc1ec57f3b 19 PARTID = 0x02,
vtoffoli 2:14dc1ec57f3b 20 REVID = 0x03,
vtoffoli 2:14dc1ec57f3b 21 STATUS = 0x04,
vtoffoli 2:14dc1ec57f3b 22 FIFO_ENTRIES = 0x05,
vtoffoli 2:14dc1ec57f3b 23 TEMP2 = 0x06,
vtoffoli 2:14dc1ec57f3b 24 TEMP1 = 0x07,
vtoffoli 2:14dc1ec57f3b 25 XDATA3 = 0x08,
vtoffoli 2:14dc1ec57f3b 26 XDATA2 = 0x09,
vtoffoli 2:14dc1ec57f3b 27 XDATA1 = 0x0A,
vtoffoli 2:14dc1ec57f3b 28 YDATA3 = 0x0B,
vtoffoli 2:14dc1ec57f3b 29 YDATA2 = 0x0C,
vtoffoli 2:14dc1ec57f3b 30 YDATA1 = 0x0D,
vtoffoli 2:14dc1ec57f3b 31 ZDATA3 = 0x0E,
vtoffoli 2:14dc1ec57f3b 32 ZDATA2 = 0x0F,
vtoffoli 2:14dc1ec57f3b 33 ZDATA1 = 0x10,
vtoffoli 2:14dc1ec57f3b 34 FIFO_DATA = 0x11,
vtoffoli 2:14dc1ec57f3b 35 OFFSET_X_H = 0x1E,
vtoffoli 2:14dc1ec57f3b 36 OFFSET_X_L = 0x1F,
vtoffoli 2:14dc1ec57f3b 37 OFFSET_Y_H = 0x20,
vtoffoli 2:14dc1ec57f3b 38 OFFSET_Y_L = 0x21,
vtoffoli 2:14dc1ec57f3b 39 OFFSET_Z_H = 0x22,
vtoffoli 2:14dc1ec57f3b 40 OFFSET_Z_L = 0x23,
vtoffoli 2:14dc1ec57f3b 41 ACT_EN = 0x24,
vtoffoli 2:14dc1ec57f3b 42 ACT_THRESH_H = 0x25,
vtoffoli 2:14dc1ec57f3b 43 ACT_THRESH_L = 0x26,
vtoffoli 2:14dc1ec57f3b 44 ACT_COUNT = 0x27,
vtoffoli 2:14dc1ec57f3b 45 FILTER = 0x28,
vtoffoli 2:14dc1ec57f3b 46 FIFO_SAMPLES = 0x29,
vtoffoli 2:14dc1ec57f3b 47 INT_MAP = 0x2A,
vtoffoli 2:14dc1ec57f3b 48 SYNC = 0x2B,
vtoffoli 2:14dc1ec57f3b 49 RANGE = 0x2C,
vtoffoli 2:14dc1ec57f3b 50 POWER_CTL = 0x2D,
vtoffoli 2:14dc1ec57f3b 51 SELF_TEST = 0x2E,
vtoffoli 2:14dc1ec57f3b 52 RESET = 0x2F
vtoffoli 2:14dc1ec57f3b 53 } ADXL355_register_t;
vtoffoli 2:14dc1ec57f3b 54 // -------------------------- //
vtoffoli 2:14dc1ec57f3b 55 // REGISTERS - DEFAULT VALUES //
vtoffoli 2:14dc1ec57f3b 56 // -------------------------- //
vtoffoli 2:14dc1ec57f3b 57 // Modes - POWER_CTL
vtoffoli 2:14dc1ec57f3b 58 typedef enum {
vtoffoli 2:14dc1ec57f3b 59 DRDY_OFF = 0x04,
vtoffoli 2:14dc1ec57f3b 60 TEMP_OFF = 0x02,
vtoffoli 4:23b53636b576 61 STANDBY = 0x01,
vtoffoli 4:23b53636b576 62 MEASUREMENT = 0x00
vtoffoli 2:14dc1ec57f3b 63 } ADXL355_modes_t;
vtoffoli 2:14dc1ec57f3b 64 // Activate Threshold - ACT_EN
vtoffoli 2:14dc1ec57f3b 65 typedef enum {
vtoffoli 2:14dc1ec57f3b 66 ACT_Z = 0x04,
vtoffoli 2:14dc1ec57f3b 67 ACT_Y = 0x02,
vtoffoli 2:14dc1ec57f3b 68 ACT_X = 0x01
vtoffoli 2:14dc1ec57f3b 69 } ADXL355_act_ctl_t;
vtoffoli 2:14dc1ec57f3b 70 // High-Pass and Low-Pass Filter - FILTER
vtoffoli 2:14dc1ec57f3b 71 typedef enum {
vtoffoli 2:14dc1ec57f3b 72 HPFOFF = 0x00,
vtoffoli 2:14dc1ec57f3b 73 HPF247 = 0x10,
vtoffoli 2:14dc1ec57f3b 74 HPF62 = 0x20,
vtoffoli 2:14dc1ec57f3b 75 HPF15 = 0x30,
vtoffoli 2:14dc1ec57f3b 76 HPF3 = 0x40,
vtoffoli 2:14dc1ec57f3b 77 HPF09 = 0x50,
vtoffoli 2:14dc1ec57f3b 78 HPF02 = 0x60,
vtoffoli 2:14dc1ec57f3b 79 ODR4000HZ = 0x00,
vtoffoli 2:14dc1ec57f3b 80 ODR2000HZ = 0x01,
vtoffoli 2:14dc1ec57f3b 81 ODR1000HZ = 0x02,
vtoffoli 2:14dc1ec57f3b 82 ODR500HZ = 0x03,
vtoffoli 2:14dc1ec57f3b 83 ODR250HZ = 0x04,
vtoffoli 2:14dc1ec57f3b 84 ODR125Hz = 0x05,
vtoffoli 2:14dc1ec57f3b 85 ODR62HZ = 0x06,
vtoffoli 2:14dc1ec57f3b 86 ODR31Hz = 0x07,
vtoffoli 2:14dc1ec57f3b 87 ODR15Hz = 0x08,
vtoffoli 2:14dc1ec57f3b 88 ODR7Hz = 0x09,
vtoffoli 2:14dc1ec57f3b 89 ODR3HZ = 0x0A
vtoffoli 2:14dc1ec57f3b 90 } ADXL355_filter_ctl_t;
vtoffoli 2:14dc1ec57f3b 91 // External timing register - INT_MAP
vtoffoli 2:14dc1ec57f3b 92 typedef enum {
vtoffoli 2:14dc1ec57f3b 93 OVR_EN = 0x04,
vtoffoli 2:14dc1ec57f3b 94 FULL_EN = 0x02,
vtoffoli 2:14dc1ec57f3b 95 RDY_EN = 0x01
vtoffoli 2:14dc1ec57f3b 96 } ADXL355_intmap_ctl_t;
vtoffoli 2:14dc1ec57f3b 97 // External timing register - SYNC
vtoffoli 2:14dc1ec57f3b 98 typedef enum {
vtoffoli 2:14dc1ec57f3b 99 EXT_CLK = 0x04,
vtoffoli 2:14dc1ec57f3b 100 INT_SYNC = 0x00,
vtoffoli 2:14dc1ec57f3b 101 EXT_SYNC_NO_INT = 0x01,
vtoffoli 2:14dc1ec57f3b 102 EXT_SYNC_INT = 0x02
vtoffoli 2:14dc1ec57f3b 103 } ADXL355_sync_ctl_t;
vtoffoli 2:14dc1ec57f3b 104 // polarity and range - RANGE
vtoffoli 2:14dc1ec57f3b 105 typedef enum {
vtoffoli 2:14dc1ec57f3b 106 RANGE2G = 0x01,
vtoffoli 2:14dc1ec57f3b 107 RANGE4G = 0x02,
vtoffoli 2:14dc1ec57f3b 108 RANGE8G = 0x03,
vtoffoli 6:45d2393ef468 109 RANGE10 = 0x01,
vtoffoli 2:14dc1ec57f3b 110 RANGE20 = 0x02,
vtoffoli 2:14dc1ec57f3b 111 RANGE40 = 0x03
vtoffoli 2:14dc1ec57f3b 112 } ADXL355_range_ctl_t;
vtoffoli 2:14dc1ec57f3b 113 // self test interrupt - INT
vtoffoli 2:14dc1ec57f3b 114 typedef enum {
vtoffoli 2:14dc1ec57f3b 115 ST2 = 0x02,
vtoffoli 2:14dc1ec57f3b 116 ST1 = 0x01
vtoffoli 2:14dc1ec57f3b 117 } ADXL355_int_ctl_t;
vtoffoli 2:14dc1ec57f3b 118
vtoffoli 2:14dc1ec57f3b 119 // -------------------------- //
vtoffoli 2:14dc1ec57f3b 120 // FUNCTIONS //
vtoffoli 2:14dc1ec57f3b 121 // -------------------------- //
vtoffoli 2:14dc1ec57f3b 122 // SPI configuration & constructor
vtoffoli 2:14dc1ec57f3b 123 ADXL355(PinName cs_pin , PinName MOSI , PinName MISO , PinName SCK );
vtoffoli 2:14dc1ec57f3b 124 void frequency(int hz);
vtoffoli 2:14dc1ec57f3b 125 // Low level SPI bus comm methods
vtoffoli 2:14dc1ec57f3b 126 void reset(void);
vtoffoli 2:14dc1ec57f3b 127 void write_reg(ADXL355_register_t reg, uint8_t data);
vtoffoli 2:14dc1ec57f3b 128 void write_reg_u16(ADXL355_register_t reg, uint16_t data);
vtoffoli 2:14dc1ec57f3b 129 uint8_t read_reg(ADXL355_register_t reg);
vtoffoli 2:14dc1ec57f3b 130 uint16_t read_reg_u16(ADXL355_register_t reg);
vtoffoli 6:45d2393ef468 131 uint32_t read_reg_u20(ADXL355_register_t reg);
vtoffoli 2:14dc1ec57f3b 132 // ADXL general register R/W methods
vtoffoli 2:14dc1ec57f3b 133 void set_power_ctl_reg(uint8_t data);
vtoffoli 2:14dc1ec57f3b 134 void set_filter_ctl_reg(ADXL355_filter_ctl_t hpf, ADXL355_filter_ctl_t odr);
vtoffoli 2:14dc1ec57f3b 135 void set_clk(ADXL355_sync_ctl_t data);
vtoffoli 2:14dc1ec57f3b 136 void set_device(ADXL355_range_ctl_t range);
vtoffoli 2:14dc1ec57f3b 137 uint8_t read_status();
vtoffoli 2:14dc1ec57f3b 138 // ADXL X/Y/Z/T scanning methods
vtoffoli 2:14dc1ec57f3b 139 uint32_t scanx();
vtoffoli 2:14dc1ec57f3b 140 uint32_t scany();
vtoffoli 2:14dc1ec57f3b 141 uint32_t scanz();
vtoffoli 2:14dc1ec57f3b 142 uint16_t scant();
vtoffoli 2:14dc1ec57f3b 143 // ADXL activity methods
vtoffoli 2:14dc1ec57f3b 144 void set_activity_axis(ADXL355_act_ctl_t axis);
vtoffoli 2:14dc1ec57f3b 145 void set_activity_cnt(uint8_t count);
vtoffoli 3:ee052fdb4331 146 void set_activity_threshold(uint8_t data_h, uint8_t data_l);
vtoffoli 2:14dc1ec57f3b 147 void set_inactivity();
vtoffoli 2:14dc1ec57f3b 148 // ADXL interrupt methods
vtoffoli 2:14dc1ec57f3b 149 void set_interrupt1_pin(PinName in, ADXL355_intmap_ctl_t mode);
vtoffoli 2:14dc1ec57f3b 150 void set_interrupt2_pin(PinName in, ADXL355_intmap_ctl_t mode);
vtoffoli 2:14dc1ec57f3b 151 void enable_interrupt1();
vtoffoli 2:14dc1ec57f3b 152 void enable_interrupt2();
vtoffoli 2:14dc1ec57f3b 153 void disable_interrupt1();
vtoffoli 2:14dc1ec57f3b 154 void disable_interrupt2();
vtoffoli 2:14dc1ec57f3b 155 void set_polling_interrupt1_pin(uint8_t data);
vtoffoli 2:14dc1ec57f3b 156 void set_polling_interrupt2_pin(uint8_t data);
vtoffoli 2:14dc1ec57f3b 157 bool get_int1();
vtoffoli 2:14dc1ec57f3b 158 bool get_int2();
vtoffoli 2:14dc1ec57f3b 159 // ADXL FIFO methods
vtoffoli 3:ee052fdb4331 160 uint8_t fifo_read_nr_of_entries();
vtoffoli 2:14dc1ec57f3b 161 void fifo_setup(uint8_t nr_of_entries);
vtoffoli 2:14dc1ec57f3b 162 uint32_t fifo_read_u32();
vtoffoli 2:14dc1ec57f3b 163 uint64_t fifo_scan();
vtoffoli 3:ee052fdb4331 164 // ADXL tilt methods and calibration
vtoffoli 2:14dc1ec57f3b 165 // TBD
vtoffoli 2:14dc1ec57f3b 166 private:
vtoffoli 2:14dc1ec57f3b 167 // SPI adxl355; ///< SPI instance of the ADXL
vtoffoli 2:14dc1ec57f3b 168 SPI adxl355; DigitalOut cs;
vtoffoli 2:14dc1ec57f3b 169 const static uint8_t _DEVICE_AD = 0xAD; // contect of DEVID_AD (only-read) register
vtoffoli 2:14dc1ec57f3b 170 const static uint8_t _RESET = 0x52; // reset code
vtoffoli 2:14dc1ec57f3b 171 const static uint8_t _DUMMY_BYTE = 0xAA; // 10101010
vtoffoli 2:14dc1ec57f3b 172 const static uint8_t _WRITE_REG_CMD = 0x00; // write register
vtoffoli 2:14dc1ec57f3b 173 const static uint8_t _READ_REG_CMD = 0x01; // read register
vtoffoli 2:14dc1ec57f3b 174 const static uint8_t _READ_FIFO_CMD = 0x23; // read FIFO
vtoffoli 2:14dc1ec57f3b 175 const static uint8_t _SPI_MODE = 0; // timing scheme
vtoffoli 2:14dc1ec57f3b 176 };
vtoffoli 2:14dc1ec57f3b 177
vtoffoli 2:14dc1ec57f3b 178 #endif