accel24  2.1.0.0
accel24.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef ACCEL24_H
29 #define ACCEL24_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define ACCEL24_REG_INT_SRC0 0x00
60 #define ACCEL24_REG_INT_CLR0 0x00
61 #define ACCEL24_REG_INT_SRC1 0x01
62 #define ACCEL24_REG_INT_CLR1 0x01
63 #define ACCEL24_REG_STATUS 0x02
64 #define ACCEL24_REG_XOUT_MSB 0x03
65 #define ACCEL24_REG_XOUT_LSB 0x04
66 #define ACCEL24_REG_YOUT_MSB 0x05
67 #define ACCEL24_REG_YOUT_LSB 0x06
68 #define ACCEL24_REG_ZOUT_MSB 0x07
69 #define ACCEL24_REG_ZOUT_LSB 0x08
70 #define ACCEL24_REG_TOUT 0x09
71 #define ACCEL24_REG_INT_MASK0 0x0A
72 #define ACCEL24_REG_INT_MASK1 0x0B
73 #define ACCEL24_REG_DETECTION 0x0C
74 #define ACCEL24_REG_CONTROL 0x0D
75 #define ACCEL24_REG_WHO_AM_I 0x0F
76  // accel24_reg
78 
93 #define ACCEL24_INT_SRC0_CHORZ 0x80
94 #define ACCEL24_INT_SRC0_CHORXY 0x40
95 #define ACCEL24_INT_SRC0_SHYM 0x08
96 #define ACCEL24_INT_SRC0_SHYP 0x04
97 #define ACCEL24_INT_SRC0_SHXM 0x02
98 #define ACCEL24_INT_SRC0_SHXP 0x01
99 
104 #define ACCEL24_INT_CLR0_ORZC 0x80
105 #define ACCEL24_INT_CLR0_ORXYC 0x40
106 #define ACCEL24_INT_CLR0_SHYMC 0x08
107 #define ACCEL24_INT_CLR0_SHYPC 0x04
108 #define ACCEL24_INT_CLR0_SHXMC 0x02
109 #define ACCEL24_INT_CLR0_SHXPC 0x01
110 #define ACCEL24_INT_CLR0_ALL 0xCF
111 
116 #define ACCEL24_INT_SRC1_TILT 0x80
117 #define ACCEL24_INT_SRC1_ORZ 0x40
118 #define ACCEL24_INT_SRC1_ORXY_X_PLUS 0x00
119 #define ACCEL24_INT_SRC1_ORXY_Y_PLUS 0x10
120 #define ACCEL24_INT_SRC1_ORXY_X_MINUS 0x20
121 #define ACCEL24_INT_SRC1_ORXY_Y_MINUS 0x30
122 #define ACCEL24_INT_SRC1_ORXY_MASK 0x30
123 #define ACCEL24_INT_SRC1_DRDY 0x01
124 
129 #define ACCEL24_INT_CLR1_SW_RST 0x10
130 #define ACCEL24_INT_CLR1_DRDYC 0x01
131 
136 #define ACCEL24_STATUS_ORD 0x10
137 #define ACCEL24_STATUS_ORIZ_MSB 0x08
138 #define ACCEL24_STATUS_ORIZ_LSB 0x04
139 #define ACCEL24_STATUS_ORIXY_MSB 0x02
140 #define ACCEL24_STATUS_ORIXY_LSB 0x01
141 
146 #define ACCEL24_INT_MASK0_ORZE 0x80
147 #define ACCEL24_INT_MASK0_ORXYE 0x40
148 #define ACCEL24_INT_MASK0_SHYME 0x08
149 #define ACCEL24_INT_MASK0_SHYPE 0x04
150 #define ACCEL24_INT_MASK0_SHXME 0x02
151 #define ACCEL24_INT_MASK0_SHXPE 0x01
152 #define ACCEL24_INT_MASK0_NONE 0x00
153 #define ACCEL24_INT_MASK0_ALL 0xCF
154 
159 #define ACCEL24_INT_MASK1_TC 0x80
160 #define ACCEL24_INT_MASK1_DRDYE 0x01
161 
166 #define ACCEL24_DETECTION_SHM 0x80
167 #define ACCEL24_DETECTION_SHTH_0p25G 0x00
168 #define ACCEL24_DETECTION_SHTH_0p5G 0x10
169 #define ACCEL24_DETECTION_SHTH_0p75G 0x20
170 #define ACCEL24_DETECTION_SHTH_1G 0x30
171 #define ACCEL24_DETECTION_SHTH_1p25G 0x40
172 #define ACCEL24_DETECTION_SHTH_1p5G 0x50
173 #define ACCEL24_DETECTION_SHTH_1p75G 0x60
174 #define ACCEL24_DETECTION_SHTH_2G 0x70
175 #define ACCEL24_DETECTION_SHTH_MASK 0x70
176 #define ACCEL24_DETECTION_SHC_8 0x00
177 #define ACCEL24_DETECTION_SHC_16 0x04
178 #define ACCEL24_DETECTION_SHC_32 0x08
179 #define ACCEL24_DETECTION_SHC_64 0x0C
180 #define ACCEL24_DETECTION_SHC_MASK 0x0C
181 #define ACCEL24_DETECTION_ORC_16 0x00
182 #define ACCEL24_DETECTION_ORC_32 0x01
183 #define ACCEL24_DETECTION_ORC_64 0x02
184 #define ACCEL24_DETECTION_ORC_128 0x03
185 #define ACCEL24_DETECTION_ORC_MASK 0x03
186 #define ACCEL24_DETECTION_NONE 0x00
187 
192 #define ACCEL24_CONTROL_ST 0x80
193 #define ACCEL24_CONTROL_FSR_2G 0x00
194 #define ACCEL24_CONTROL_FSR_4G 0x20
195 #define ACCEL24_CONTROL_FSR_8G 0x40
196 #define ACCEL24_CONTROL_FSR_UNDEFINED 0x60
197 #define ACCEL24_CONTROL_FSR_MASK 0x60
198 #define ACCEL24_CONTROL_PD 0x01
199 
204 #define ACCEL24_ACCEL_RESOLUTION 2048.0f
205 #define ACCEL24_TEMP_SENSITIVITY 0.586f
206 #define ACCEL24_TEMP_NOMINAL 25.0f
207 
212 #define ACCEL24_FSR_2G 0
213 #define ACCEL24_FSR_4G 1
214 #define ACCEL24_FSR_8G 2
215 
220 #define ACCEL24_WHO_AM_I 0x05
221 #define ACCEL24_WHO_AM_I_MASK 0x0F
222 
228 #define ACCEL24_DEVICE_ADDRESS 0x15
229  // accel24_set
231 
246 #define ACCEL24_MAP_MIKROBUS( cfg, mikrobus ) \
247  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
248  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
249  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
250  // accel24_map // accel24
253 
258 typedef struct
259 {
260  // Input pins
261  digital_in_t int_pin;
263  // Modules
264  i2c_master_t i2c;
266  // I2C slave address
267  uint8_t slave_address;
269  float fsr_sens;
271 } accel24_t;
272 
277 typedef struct
278 {
279  pin_name_t scl;
280  pin_name_t sda;
282  pin_name_t int_pin;
284  uint32_t i2c_speed;
285  uint8_t i2c_address;
287 } accel24_cfg_t;
288 
293 typedef struct
294 {
295  float x;
296  float y;
297  float z;
298  float temperature;
301 
306 typedef enum
307 {
309  ACCEL24_ERROR = -1
310 
312 
329 
343 err_t accel24_init ( accel24_t *ctx, accel24_cfg_t *cfg );
344 
358 
373 err_t accel24_generic_write ( accel24_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
374 
389 err_t accel24_generic_read ( accel24_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
390 
403 err_t accel24_write_register ( accel24_t *ctx, uint8_t reg, uint8_t data_in );
404 
417 err_t accel24_read_register ( accel24_t *ctx, uint8_t reg, uint8_t *data_out );
418 
430 
440 
452 
466 err_t accel24_set_full_scale_range ( accel24_t *ctx, uint8_t fsr );
467 
481 err_t accel24_read_data ( accel24_t *ctx, accel24_data_t *data_out );
482 
483 #ifdef __cplusplus
484 }
485 #endif
486 #endif // ACCEL24_H
487  // accel24
489 
490 // ------------------------------------------------------------------------ END
accel24_default_cfg
err_t accel24_default_cfg(accel24_t *ctx)
Accel 24 default configuration function.
accel24_return_value_t
accel24_return_value_t
Accel 24 Click return value data.
Definition: accel24.h:307
accel24_cfg_setup
void accel24_cfg_setup(accel24_cfg_t *cfg)
Accel 24 configuration object setup function.
ACCEL24_ERROR
@ ACCEL24_ERROR
Definition: accel24.h:309
accel24_t
Accel 24 Click context object.
Definition: accel24.h:259
accel24_check_communication
err_t accel24_check_communication(accel24_t *ctx)
Accel 24 check communication function.
accel24_data_t::z
float z
Definition: accel24.h:297
accel24_soft_reset
err_t accel24_soft_reset(accel24_t *ctx)
Accel 24 soft reset function.
accel24_read_data
err_t accel24_read_data(accel24_t *ctx, accel24_data_t *data_out)
Accel 24 read data function.
accel24_get_int_pin
uint8_t accel24_get_int_pin(accel24_t *ctx)
Accel 24 get int pin function.
accel24_cfg_t::sda
pin_name_t sda
Definition: accel24.h:280
accel24_cfg_t
Accel 24 Click configuration object.
Definition: accel24.h:278
accel24_data_t::x
float x
Definition: accel24.h:295
accel24_cfg_t::i2c_address
uint8_t i2c_address
Definition: accel24.h:285
accel24_init
err_t accel24_init(accel24_t *ctx, accel24_cfg_t *cfg)
Accel 24 initialization function.
accel24_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: accel24.h:284
accel24_t::slave_address
uint8_t slave_address
Definition: accel24.h:267
accel24_t::int_pin
digital_in_t int_pin
Definition: accel24.h:261
accel24_cfg_t::scl
pin_name_t scl
Definition: accel24.h:279
accel24_data_t
Accel 24 Click data structure.
Definition: accel24.h:294
accel24_set_full_scale_range
err_t accel24_set_full_scale_range(accel24_t *ctx, uint8_t fsr)
Accel 24 set full scale range function.
accel24_read_register
err_t accel24_read_register(accel24_t *ctx, uint8_t reg, uint8_t *data_out)
Accel 24 read register function.
accel24_t::fsr_sens
float fsr_sens
Definition: accel24.h:269
accel24_write_register
err_t accel24_write_register(accel24_t *ctx, uint8_t reg, uint8_t data_in)
Accel 24 write register function.
accel24_generic_read
err_t accel24_generic_read(accel24_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Accel 24 I2C reading function.
accel24_cfg_t::int_pin
pin_name_t int_pin
Definition: accel24.h:282
accel24_t::i2c
i2c_master_t i2c
Definition: accel24.h:264
ACCEL24_OK
@ ACCEL24_OK
Definition: accel24.h:308
accel24_data_t::y
float y
Definition: accel24.h:296
accel24_data_t::temperature
float temperature
Definition: accel24.h:298
accel24_generic_write
err_t accel24_generic_write(accel24_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Accel 24 I2C writing function.