accel16 2.0.0.0
accel16.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 ACCEL16_H
29#define ACCEL16_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
52#include "spi_specifics.h"
53
74#define ACCEL16_CMD_WRITE_REG 0x0A
75#define ACCEL16_CMD_READ_REG 0x0B
76#define ACCEL16_CMD_READ_FIFO 0x0D
77
82#define ACCEL16_REG_DEVID_AD 0x00
83#define ACCEL16_REG_DEVID_MST 0x01
84#define ACCEL16_REG_DEVID 0x02
85#define ACCEL16_REG_REVID 0x03
86#define ACCEL16_REG_XDATA 0x08
87#define ACCEL16_REG_YDATA 0x09
88#define ACCEL16_REG_ZDATA 0x0A
89#define ACCEL16_REG_STATUS 0x0B
90#define ACCEL16_REG_FIFO_ENTRIES_L 0x0C
91#define ACCEL16_REG_FIFO_ENTRIES_H 0x0D
92#define ACCEL16_REG_XDATA_L 0x0E
93#define ACCEL16_REG_XDATA_H 0x0F
94#define ACCEL16_REG_YDATA_L 0x10
95#define ACCEL16_REG_YDATA_H 0x11
96#define ACCEL16_REG_ZDATA_L 0x12
97#define ACCEL16_REG_ZDATA_H 0x13
98#define ACCEL16_REG_TEMP_L 0x14
99#define ACCEL16_REG_TEMP_H 0x15
100#define ACCEL16_REG_ADC_DATA_L 0x16
101#define ACCEL16_REG_ADC_DATA_H 0x17
102#define ACCEL16_REG_SOFT_RESET 0x1F
103#define ACCEL16_REG_THRESH_ACT_L 0x20
104#define ACCEL16_REG_THRESH_ACT_H 0x21
105#define ACCEL16_REG_TIME_ACT 0x22
106#define ACCEL16_REG_THRESH_INACT_L 0x23
107#define ACCEL16_REG_THRESH_INACT_H 0x24
108#define ACCEL16_REG_TIME_INACT_L 0x25
109#define ACCEL16_REG_TIME_INACT_H 0x26
110#define ACCEL16_REG_ACT_INACT_CTL 0x27
111#define ACCEL16_REG_FIFO_CONTROL 0x28
112#define ACCEL16_REG_FIFO_SAMPLES 0x29
113#define ACCEL16_REG_INTMAP1 0x2A
114#define ACCEL16_REG_INTMAP2 0x2B
115#define ACCEL16_REG_FILTER_CTL 0x2C
116#define ACCEL16_REG_POWER_CTL 0x2D
117#define ACCEL16_REG_SELF_CTL 0x2E
118
119 // accel16_reg
120
135#define ACCEL16_APPLICATION_FIFO 0xAA
136#define ACCEL16_APPLICATION_REG 0xBB
137
142#define ACCEL16_ROOM_TEMPERATURE 25.0
143#define ACCEL16_TEMPERATURE_BIAS 350
144#define ACCEL16_TEMPERATURE_RES 0.065
145#define ACCEL16_TEMPERATURE_CAL_SAMPLE_NUM 100
146
155#define ACCEL16_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
156#define ACCEL16_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
157
158 // accel16_set
159
174#define ACCEL16_MAP_MIKROBUS( cfg, mikrobus ) \
175 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
176 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
177 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
178 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
179 cfg.int2 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
180 cfg.int1 = MIKROBUS( mikrobus, MIKROBUS_INT )
181
182 // accel16_map
183 // accel16
184
189typedef struct
190{
191 // Input pins
192 digital_in_t int2;
193 digital_in_t int1;
195 // Modules
196 spi_master_t spi;
198 pin_name_t chip_select;
203} accel16_t;
204
209typedef struct
210{
211 // Communication gpio pins
212 pin_name_t miso;
213 pin_name_t mosi;
214 pin_name_t sck;
215 pin_name_t cs;
217 // Additional gpio pins
218 pin_name_t int2;
219 pin_name_t int1;
221 // static variable
222 uint32_t spi_speed;
223 spi_master_mode_t spi_mode;
224 spi_master_chip_select_polarity_t cs_polarity;
227
232typedef struct
233{
234 float x;
235 float y;
236 float z;
239
244typedef enum
245{
247 ACCEL16_ERROR = -1
248
250
255typedef enum
256{
259 ACCEL16_8G = 2
260
262
277
294
309
323
337err_t accel16_multiple_reg_write ( accel16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
338
350err_t accel16_single_reg_write ( accel16_t *ctx, uint8_t reg, uint8_t data_in );
351
365err_t accel16_multiple_reg_read ( accel16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
366
378err_t accel16_single_reg_read ( accel16_t *ctx, uint8_t reg, uint8_t *data_out );
379
393err_t accel16_fifo_read ( accel16_t *ctx, uint8_t *data_out, uint16_t len );
394
403
412
426
439
451err_t accel16_get_temperature ( accel16_t *ctx, float *temperature );
452
465err_t accel16_get_adc ( accel16_t *ctx, float *v_adc );
466
478err_t accel16_calibrate_temperature ( accel16_t *ctx, float room_temperature );
479
480#ifdef __cplusplus
481}
482#endif
483#endif // ACCEL16_H
484
485 // accel16
486
487// ------------------------------------------------------------------------ END
accel16_gain_t
Accel 16 Click gain.
Definition accel16.h:256
@ ACCEL16_4G
Definition accel16.h:258
@ ACCEL16_8G
Definition accel16.h:259
@ ACCEL16_2G
Definition accel16.h:257
accel16_return_value_t
Accel 16 Click return value data.
Definition accel16.h:245
@ ACCEL16_ERROR
Definition accel16.h:247
@ ACCEL16_OK
Definition accel16.h:246
accel16_output_rate_t
Accel 16 Click output data rate.
Definition accel16.h:268
@ ACCEL16_12p5HZ
Definition accel16.h:269
@ ACCEL16_200HZ
Definition accel16.h:273
@ ACCEL16_400HZ
Definition accel16.h:274
@ ACCEL16_50HZ
Definition accel16.h:271
@ ACCEL16_100HZ
Definition accel16.h:272
@ ACCEL16_25HZ
Definition accel16.h:270
err_t accel16_calibrate_temperature(accel16_t *ctx, float room_temperature)
Accel 16 calibrate temperature function.
uint8_t accel16_get_interrupt_1(accel16_t *ctx)
Get interrupt 1 state.
err_t accel16_get_temperature(accel16_t *ctx, float *temperature)
Get temperature data.
err_t accel16_init(accel16_t *ctx, accel16_cfg_t *cfg)
Accel 16 initialization function.
err_t accel16_get_axes(accel16_t *ctx, accel16_axes_t *axes)
Get axes data.
err_t accel16_filter_configuration(accel16_t *ctx, accel16_gain_t gain, accel16_output_rate_t odr)
Filter configuration.
err_t accel16_single_reg_write(accel16_t *ctx, uint8_t reg, uint8_t data_in)
Write single register.
void accel16_cfg_setup(accel16_cfg_t *cfg)
Accel 16 configuration object setup function.
err_t accel16_get_adc(accel16_t *ctx, float *v_adc)
Get adc data.
err_t accel16_single_reg_read(accel16_t *ctx, uint8_t reg, uint8_t *data_out)
Read single registers.
err_t accel16_default_cfg(accel16_t *ctx)
Accel 16 default configuration function.
err_t accel16_multiple_reg_write(accel16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Write multiple registers.
uint8_t accel16_get_interrupt_2(accel16_t *ctx)
Get interrupt 2 state.
err_t accel16_multiple_reg_read(accel16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Read multiple registers.
err_t accel16_fifo_read(accel16_t *ctx, uint8_t *data_out, uint16_t len)
Read fifo.
This file contains SPI specific macros, functions, etc.
Accel 16 Click axes data.
Definition accel16.h:233
float y
Definition accel16.h:235
float x
Definition accel16.h:234
float z
Definition accel16.h:236
Accel 16 Click configuration object.
Definition accel16.h:210
pin_name_t int1
Definition accel16.h:219
pin_name_t int2
Definition accel16.h:218
spi_master_chip_select_polarity_t cs_polarity
Definition accel16.h:224
pin_name_t sck
Definition accel16.h:214
spi_master_mode_t spi_mode
Definition accel16.h:223
pin_name_t mosi
Definition accel16.h:213
uint32_t spi_speed
Definition accel16.h:222
pin_name_t miso
Definition accel16.h:212
pin_name_t cs
Definition accel16.h:215
Accel 16 Click context object.
Definition accel16.h:190
digital_in_t int2
Definition accel16.h:192
spi_master_t spi
Definition accel16.h:196
float resolution
Definition accel16.h:199
uint8_t application_type
Definition accel16.h:201
digital_in_t int1
Definition accel16.h:193
float room_temp_offset
Definition accel16.h:200
pin_name_t chip_select
Definition accel16.h:198