Working version. ADXL355 data saved to microSD.

Committer:
DUR
Date:
Fri Sep 29 12:53:50 2017 +0000
Revision:
0:e2579e8d9b13
Working version.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DUR 0:e2579e8d9b13 1 /**
DUR 0:e2579e8d9b13 2 ******************************************************************************
DUR 0:e2579e8d9b13 3 * @file adxl355.h
DUR 0:e2579e8d9b13 4 * @author DUR
DUR 0:e2579e8d9b13 5 * @version V1.0.0
DUR 0:e2579e8d9b13 6 * @date 01-Aug-2017
DUR 0:e2579e8d9b13 7 * @brief Header file of a library for adxl355 interface.
DUR 0:e2579e8d9b13 8 ******************************************************************************
DUR 0:e2579e8d9b13 9 * @attention
DUR 0:e2579e8d9b13 10 *
DUR 0:e2579e8d9b13 11 * <h2><center>&copy; COPYRIGHT(c) 2014 TD Group</center></h2>
DUR 0:e2579e8d9b13 12 *
DUR 0:e2579e8d9b13 13 * The information contained herein is property of TD Group S.p.A.
DUR 0:e2579e8d9b13 14 *
DUR 0:e2579e8d9b13 15 * Licensees are granted free, non-transferable use of the information. NO
DUR 0:e2579e8d9b13 16 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
DUR 0:e2579e8d9b13 17 * the file.
DUR 0:e2579e8d9b13 18 *
DUR 0:e2579e8d9b13 19 ******************************************************************************
DUR 0:e2579e8d9b13 20 */
DUR 0:e2579e8d9b13 21
DUR 0:e2579e8d9b13 22
DUR 0:e2579e8d9b13 23 /* Define to prevent recursive inclusion -------------------------------------*/
DUR 0:e2579e8d9b13 24 #ifndef __ADXL355_H
DUR 0:e2579e8d9b13 25 #define __ADXL355_H
DUR 0:e2579e8d9b13 26
DUR 0:e2579e8d9b13 27
DUR 0:e2579e8d9b13 28 /* Includes ------------------------------------------------------------------*/
DUR 0:e2579e8d9b13 29 #include <stdint.h>
DUR 0:e2579e8d9b13 30 #include <string.h>
DUR 0:e2579e8d9b13 31
DUR 0:e2579e8d9b13 32
DUR 0:e2579e8d9b13 33
DUR 0:e2579e8d9b13 34 /* Exported define -----------------------------------------------------------*/
DUR 0:e2579e8d9b13 35
DUR 0:e2579e8d9b13 36 /** @brief ID dell'accelerometro
DUR 0:e2579e8d9b13 37 */
DUR 0:e2579e8d9b13 38 #define ADXL355_DEVICE_ID 0xED
DUR 0:e2579e8d9b13 39
DUR 0:e2579e8d9b13 40
DUR 0:e2579e8d9b13 41 /** @brief Codice per effettuare il reset sw dell'accelerometro
DUR 0:e2579e8d9b13 42 */
DUR 0:e2579e8d9b13 43 #define ADXL355_RESET_CODE 0x52
DUR 0:e2579e8d9b13 44
DUR 0:e2579e8d9b13 45
DUR 0:e2579e8d9b13 46 /** @brief Start/stop self-test
DUR 0:e2579e8d9b13 47 */
DUR 0:e2579e8d9b13 48 #define ADXL355_SELF_TEST_ENABLE 0x01
DUR 0:e2579e8d9b13 49 #define ADXL355_SELF_TEST_DISABLE 0x00
DUR 0:e2579e8d9b13 50
DUR 0:e2579e8d9b13 51
DUR 0:e2579e8d9b13 52 /** @brief Indirizzi registri accelerometro
DUR 0:e2579e8d9b13 53 */
DUR 0:e2579e8d9b13 54 #define ADXL355_DEVID_AD 0x00
DUR 0:e2579e8d9b13 55 #define ADXL355_DEVID_MST 0x01
DUR 0:e2579e8d9b13 56 #define ADXL355_PARTID 0x02
DUR 0:e2579e8d9b13 57 #define ADXL355_REVID 0x03
DUR 0:e2579e8d9b13 58 #define ADXL355_STATUS 0x04
DUR 0:e2579e8d9b13 59 #define ADXL355_FIFO_ENTRIES 0x05
DUR 0:e2579e8d9b13 60 #define ADXL355_TEMP2 0x06
DUR 0:e2579e8d9b13 61 #define ADXL355_TEMP1 0x07
DUR 0:e2579e8d9b13 62 #define ADXL355_XDATA3 0x08
DUR 0:e2579e8d9b13 63 #define ADXL355_XDATA2 0x09
DUR 0:e2579e8d9b13 64 #define ADXL355_XDATA1 0x0A
DUR 0:e2579e8d9b13 65 #define ADXL355_YDATA3 0x0B
DUR 0:e2579e8d9b13 66 #define ADXL355_YDATA2 0x0C
DUR 0:e2579e8d9b13 67 #define ADXL355_YDATA1 0x0D
DUR 0:e2579e8d9b13 68 #define ADXL355_ZDATA3 0x0E
DUR 0:e2579e8d9b13 69 #define ADXL355_ZDATA2 0x0F
DUR 0:e2579e8d9b13 70 #define ADXL355_ZDATA1 0x10
DUR 0:e2579e8d9b13 71 #define ADXL355_FIFO_DATA 0x11
DUR 0:e2579e8d9b13 72 #define ADXL355_OFFSET_X_H 0x1E
DUR 0:e2579e8d9b13 73 #define ADXL355_OFFSET_X_L 0x1F
DUR 0:e2579e8d9b13 74 #define ADXL355_OFFSET_Y_H 0x20
DUR 0:e2579e8d9b13 75 #define ADXL355_OFFSET_Y_L 0x21
DUR 0:e2579e8d9b13 76 #define ADXL355_OFFSET_Z_H 0x22
DUR 0:e2579e8d9b13 77 #define ADXL355_OFFSET_Z_L 0x23
DUR 0:e2579e8d9b13 78 #define ADXL355_ACT_EN 0x24
DUR 0:e2579e8d9b13 79 #define ADXL355_ACT_THRESH_H 0x25
DUR 0:e2579e8d9b13 80 #define ADXL355_ACT_THRESH_L 0x26
DUR 0:e2579e8d9b13 81 #define ADXL355_ACT_COUNT 0x27
DUR 0:e2579e8d9b13 82 #define ADXL355_FILTER 0x28
DUR 0:e2579e8d9b13 83 #define ADXL355_FIFO_SAMPLES 0x29
DUR 0:e2579e8d9b13 84 #define ADXL355_INT_MAP 0x2A
DUR 0:e2579e8d9b13 85 #define ADXL355_SYNC 0x2B
DUR 0:e2579e8d9b13 86 #define ADXL355_RANGE 0x2C
DUR 0:e2579e8d9b13 87 #define ADXL355_POWER_CTL 0x2D
DUR 0:e2579e8d9b13 88 #define ADXL355_SELF_TEST 0x2E
DUR 0:e2579e8d9b13 89 #define ADXL355_RESET 0x2F
DUR 0:e2579e8d9b13 90
DUR 0:e2579e8d9b13 91
DUR 0:e2579e8d9b13 92 /** @brief Maschere di bit
DUR 0:e2579e8d9b13 93 */
DUR 0:e2579e8d9b13 94 #define ADXL355_READ_BYTE_MASK 0x01
DUR 0:e2579e8d9b13 95 #define ADXL355_WRITE_BYTE_MASK 0xFE
DUR 0:e2579e8d9b13 96
DUR 0:e2579e8d9b13 97 #define ADXL355_20_BIT_MASK 0x000FFFFF
DUR 0:e2579e8d9b13 98 #define ADXL355_12_BIT_MASK 0x0FFF
DUR 0:e2579e8d9b13 99
DUR 0:e2579e8d9b13 100 #define ADXL355_RANGE_MASK 0x03
DUR 0:e2579e8d9b13 101 #define ADXL355_ODR_MASK 0x0F
DUR 0:e2579e8d9b13 102 #define ADXL355_INT_POL_MASK 0x40
DUR 0:e2579e8d9b13 103 #define ADXL355_INT_1_MASK 0x0F
DUR 0:e2579e8d9b13 104 #define ADXL355_INT_2_MASK 0xF0
DUR 0:e2579e8d9b13 105 #define ADXL355_MEAS_MASK 0x03
DUR 0:e2579e8d9b13 106 #define ADXL355_DRDY_OFF_MASK 0x04
DUR 0:e2579e8d9b13 107 #define ADXL355_SELF_TEST_MASK 0x03
DUR 0:e2579e8d9b13 108
DUR 0:e2579e8d9b13 109
DUR 0:e2579e8d9b13 110 /** @brief Temperature parameters
DUR 0:e2579e8d9b13 111 */
DUR 0:e2579e8d9b13 112 #define ADXL355_TEMP_BIAS (float)1852.0 /* Accelerometer temperature bias(in ADC codes) at 25 Deg C */
DUR 0:e2579e8d9b13 113 #define ADXL355_TEMP_SLOPE (float)-9.05 /* Accelerometer temperature change from datasheet (LSB/degC) */
DUR 0:e2579e8d9b13 114
DUR 0:e2579e8d9b13 115
DUR 0:e2579e8d9b13 116
DUR 0:e2579e8d9b13 117 /* Exported typedef ----------------------------------------------------------*/
DUR 0:e2579e8d9b13 118 /** @brief Enumerativo per le misure attive sul sensore in un determinato momento.
DUR 0:e2579e8d9b13 119 */
DUR 0:e2579e8d9b13 120 typedef enum
DUR 0:e2579e8d9b13 121 {
DUR 0:e2579e8d9b13 122 adxl355_acc = 0u, //Sola misura di accelerazione attiva
DUR 0:e2579e8d9b13 123 adxl355_both, //Entrambe le misure attive (accelerazione e temperatura)
DUR 0:e2579e8d9b13 124 adxl355_none //Nessuna misura attiva
DUR 0:e2579e8d9b13 125 }adxl355_measure_enabled;
DUR 0:e2579e8d9b13 126
DUR 0:e2579e8d9b13 127
DUR 0:e2579e8d9b13 128 /** @brief Enumerativo per valori di range di misura ammissibili.
DUR 0:e2579e8d9b13 129 */
DUR 0:e2579e8d9b13 130 typedef enum
DUR 0:e2579e8d9b13 131 {
DUR 0:e2579e8d9b13 132 adxl355_2g = 1u,
DUR 0:e2579e8d9b13 133 adxl355_4g,
DUR 0:e2579e8d9b13 134 adxl355_8g
DUR 0:e2579e8d9b13 135 }adxl355_range_value;
DUR 0:e2579e8d9b13 136
DUR 0:e2579e8d9b13 137
DUR 0:e2579e8d9b13 138 /** @brief Enumerativo per valori di output data rate ammissibili.
DUR 0:e2579e8d9b13 139 */
DUR 0:e2579e8d9b13 140 typedef enum
DUR 0:e2579e8d9b13 141 {
DUR 0:e2579e8d9b13 142 adxl355_4000hz = 0u,
DUR 0:e2579e8d9b13 143 adxl355_2000hz,
DUR 0:e2579e8d9b13 144 adxl355_1000hz,
DUR 0:e2579e8d9b13 145 adxl355_500hz,
DUR 0:e2579e8d9b13 146 adxl355_250hz,
DUR 0:e2579e8d9b13 147 adxl355_125hz,
DUR 0:e2579e8d9b13 148 adxl355_62p5hz,
DUR 0:e2579e8d9b13 149 adxl355_31p25hz,
DUR 0:e2579e8d9b13 150 adxl355_15p625hz,
DUR 0:e2579e8d9b13 151 adxl355_7p813hz,
DUR 0:e2579e8d9b13 152 adxl355_3p906hz
DUR 0:e2579e8d9b13 153 }adxl355_output_datarate_value;
DUR 0:e2579e8d9b13 154
DUR 0:e2579e8d9b13 155
DUR 0:e2579e8d9b13 156
DUR 0:e2579e8d9b13 157 /** @brief Enumerativo per i differenti eventi associabili ai 2 interrupt ammissibili.
DUR 0:e2579e8d9b13 158 */
DUR 0:e2579e8d9b13 159 typedef enum
DUR 0:e2579e8d9b13 160 {
DUR 0:e2579e8d9b13 161 adxl355_rdy_en = 0u, //DATA_RDY interrupt enable on INT1/2
DUR 0:e2579e8d9b13 162 adxl355_full_en, //FIFO_FULL interrupt enable on INT1/2
DUR 0:e2579e8d9b13 163 adxl355_ovr_en, //FIFO_OVR interrupt enable on INT1/2
DUR 0:e2579e8d9b13 164 adxl355_act_en //Activity interrupt enable on INT1/2
DUR 0:e2579e8d9b13 165 }adxl355_int_event;
DUR 0:e2579e8d9b13 166
DUR 0:e2579e8d9b13 167
DUR 0:e2579e8d9b13 168
DUR 0:e2579e8d9b13 169
DUR 0:e2579e8d9b13 170 /** @brief Struttura che setta i parametri degli interrupt sui 2 pin a disposizione.
DUR 0:e2579e8d9b13 171 */
DUR 0:e2579e8d9b13 172 typedef struct adxl355_gpio_config_t
DUR 0:e2579e8d9b13 173 {
DUR 0:e2579e8d9b13 174 adxl355_int_event int1_evt; //evento che scatena l'interrupt 1
DUR 0:e2579e8d9b13 175 adxl355_int_event int2_evt; //evento che scatena l'interrupt 2
DUR 0:e2579e8d9b13 176 bool int_act_low; // se true gli interrupt sono attivi basso, altrimenti attivi alto
DUR 0:e2579e8d9b13 177 }adxl355_int_config;
DUR 0:e2579e8d9b13 178
DUR 0:e2579e8d9b13 179
DUR 0:e2579e8d9b13 180
DUR 0:e2579e8d9b13 181 /** @brief Struttura che definisce i parametri di configurazione ed utilizzo
DUR 0:e2579e8d9b13 182 * dell'accelerometro
DUR 0:e2579e8d9b13 183 */
DUR 0:e2579e8d9b13 184 typedef struct adxl355_handler_t
DUR 0:e2579e8d9b13 185 {
DUR 0:e2579e8d9b13 186 /* Range di misura */
DUR 0:e2579e8d9b13 187 adxl355_range_value measure_range;
DUR 0:e2579e8d9b13 188 /* Data rate di acquisizione */
DUR 0:e2579e8d9b13 189 adxl355_output_datarate_value out_data_rate;
DUR 0:e2579e8d9b13 190 /* Pin di controllo dell'accelerometro - porre a NULL se non utilizzati */
DUR 0:e2579e8d9b13 191 uint32_t drdy_pin; //output
DUR 0:e2579e8d9b13 192 uint32_t int1_pin; //output
DUR 0:e2579e8d9b13 193 uint32_t int2_pin; //output
DUR 0:e2579e8d9b13 194 /* Configurazione interrupt */
DUR 0:e2579e8d9b13 195 adxl355_int_config int_config;
DUR 0:e2579e8d9b13 196 /* Valori grezzi della accelerazione */
DUR 0:e2579e8d9b13 197 uint32_t raw_acc_x_value;
DUR 0:e2579e8d9b13 198 uint32_t raw_acc_y_value;
DUR 0:e2579e8d9b13 199 uint32_t raw_acc_z_value;
DUR 0:e2579e8d9b13 200 /* Valore grezzo della temperatura */
DUR 0:e2579e8d9b13 201 uint16_t raw_temp_value;
DUR 0:e2579e8d9b13 202 }adxl355_handler;
DUR 0:e2579e8d9b13 203
DUR 0:e2579e8d9b13 204
DUR 0:e2579e8d9b13 205
DUR 0:e2579e8d9b13 206
DUR 0:e2579e8d9b13 207
DUR 0:e2579e8d9b13 208 /* Exported types ------------------------------------------------------------*/
DUR 0:e2579e8d9b13 209
DUR 0:e2579e8d9b13 210 /* Exported constants --------------------------------------------------------*/
DUR 0:e2579e8d9b13 211
DUR 0:e2579e8d9b13 212 /* Exported macro ------------------------------------------------------------*/
DUR 0:e2579e8d9b13 213
DUR 0:e2579e8d9b13 214
DUR 0:e2579e8d9b13 215 /* Exported function prototypes ----------------------------------------------*/
DUR 0:e2579e8d9b13 216 /**< Funzione che restituisce i parametri identificativi del driver */
DUR 0:e2579e8d9b13 217 void adxl355_driver_info(uint8_t * adxl355_driver_version, uint8_t * adxl355_driver_revision, uint8_t * adxl355_driver_patch);
DUR 0:e2579e8d9b13 218 /**< Funzione che restituisce l'ID dell'accelerometro */
DUR 0:e2579e8d9b13 219 uint16_t adxl355_who_am_i(uint8_t * adxl355_device_id);
DUR 0:e2579e8d9b13 220 /**< Funzione di inizializzazione dell'accelerometro */
DUR 0:e2579e8d9b13 221 uint16_t adxl355_init(adxl355_handler *adxl_init_handler);
DUR 0:e2579e8d9b13 222 /**< Funzione di start/stop delle acquisizioni */
DUR 0:e2579e8d9b13 223 uint16_t adxl355_start_acquisition(adxl355_measure_enabled adxl_start);
DUR 0:e2579e8d9b13 224 /**< Funzione per la lettura del/i dato/i acquisito/i */
DUR 0:e2579e8d9b13 225 uint16_t adxl355_get_data(adxl355_handler *adxl_data_handler);
DUR 0:e2579e8d9b13 226 /**< Funzione che restituisce il valore grezzo di accelerazione lungo l'asse X */
DUR 0:e2579e8d9b13 227 uint32_t adxl355_raw_x_acc(adxl355_handler *adxl_xdata_handler);
DUR 0:e2579e8d9b13 228 /**< Funzione che restituisce il valore grezzo di accelerazione lungo l'asse Y */
DUR 0:e2579e8d9b13 229 uint32_t adxl355_raw_y_acc(adxl355_handler *adxl_ydata_handler);
DUR 0:e2579e8d9b13 230 /**< Funzione che restituisce il valore grezzo di accelerazione lungo l'asse Z */
DUR 0:e2579e8d9b13 231 uint32_t adxl355_raw_z_acc(adxl355_handler *adxl_zdata_handler);
DUR 0:e2579e8d9b13 232 /**< Funzione che restituisce il valore grezzo di temperatura */
DUR 0:e2579e8d9b13 233 uint16_t adxl355_raw_temp(adxl355_handler *adxl_tdata_handler);
DUR 0:e2579e8d9b13 234 /**< Funzione per il reset sw */
DUR 0:e2579e8d9b13 235 uint16_t adxl355_sw_reset(void);
DUR 0:e2579e8d9b13 236 /**< Funzione per il self-test */
DUR 0:e2579e8d9b13 237 uint16_t adxl355_self_test(bool adxl_start);
DUR 0:e2579e8d9b13 238
DUR 0:e2579e8d9b13 239
DUR 0:e2579e8d9b13 240 /* Funzione di trasferimento su bus SPI */
DUR 0:e2579e8d9b13 241 extern uint16_t adxl355_spi_transfer(uint8_t * rbuffer, uint32_t rlen);
DUR 0:e2579e8d9b13 242
DUR 0:e2579e8d9b13 243 #endif
DUR 0:e2579e8d9b13 244
DUR 0:e2579e8d9b13 245 /************************ (C) COPYRIGHT TD Group *****END OF FILE****/
DUR 0:e2579e8d9b13 246
DUR 0:e2579e8d9b13 247