inclinometer 2.0.0.0
inclinometer.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 INCLINOMETER_H
29#define INCLINOMETER_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
73#define INCLINOMETER_REG_ACC_X 0x01
74#define INCLINOMETER_REG_ACC_Y 0x02
75#define INCLINOMETER_REG_ACC_Z 0x03
76#define INCLINOMETER_REG_STO 0x04
77#define INCLINOMETER_REG_TEMP 0x05
78#define INCLINOMETER_REG_STATUS 0x06
79#define INCLINOMETER_REG_ERR_FLAG1 0x07
80#define INCLINOMETER_REG_ERR_FLAG2 0x08
81#define INCLINOMETER_REG_ANG_X 0x09
82#define INCLINOMETER_REG_ANG_Y 0x0A
83#define INCLINOMETER_REG_ANG_Z 0x0B
84#define INCLINOMETER_REG_ANG_CTRL 0x0C
85#define INCLINOMETER_REG_MODE 0x0D
86#define INCLINOMETER_REG_WHOAMI 0x10
87#define INCLINOMETER_REG_SERIAL1 0x19
88#define INCLINOMETER_REG_SERIAL2 0x1A
89#define INCLINOMETER_REG_SELBANK 0x1F
90
91 // inclinometer_reg
92
107#define INCLINOMETER_CMD_READ_ACC_X 0x040000F7
108#define INCLINOMETER_CMD_READ_ACC_Y 0x080000FD
109#define INCLINOMETER_CMD_READ_ACC_Z 0x0C0000FB
110#define INCLINOMETER_CMD_READ_STO 0x100000E9
111#define INCLINOMETER_CMD_EN_ANGLE_OUT 0xB0001F6F
112#define INCLINOMETER_CMD_READ_ANG_X 0x240000C7
113#define INCLINOMETER_CMD_READ_ANG_Y 0x280000CD
114#define INCLINOMETER_CMD_READ_ANG_Z 0x2C0000CB
115#define INCLINOMETER_CMD_READ_TEMP 0x140000EF
116#define INCLINOMETER_CMD_READ_STATUS 0x180000E5
117#define INCLINOMETER_CMD_READ_ERR_FLAG1 0x1C0000E3
118#define INCLINOMETER_CMD_READ_ERR_FLAG2 0x200000C1
119#define INCLINOMETER_CMD_READ_MODE 0x340000DF
120#define INCLINOMETER_CMD_CHANGE_TO_MODE1 0xB400001F
121#define INCLINOMETER_CMD_CHANGE_TO_MODE2 0xB4000102
122#define INCLINOMETER_CMD_CHANGE_TO_MODE3 0xB4000225
123#define INCLINOMETER_CMD_CHANGE_TO_MODE4 0xB4000338
124#define INCLINOMETER_CMD_POWER_DOWN 0xB400046B
125#define INCLINOMETER_CMD_WAKE_UP 0xB400001F
126#define INCLINOMETER_CMD_SW_RESET 0xB4002098
127#define INCLINOMETER_CMD_READ_WHOAMI 0x40000091
128#define INCLINOMETER_CMD_READ_SERIAL1 0x640000A7
129#define INCLINOMETER_CMD_READ_SERIAL2 0x680000AD
130#define INCLINOMETER_CMD_READ_CURRENT_BANK 0x7C0000B3
131#define INCLINOMETER_CMD_SWITCH_TO_BANK0 0xFC000073
132#define INCLINOMETER_CMD_SWITCH_TO_BANK1 0xFC00016E
133
134 // inclinometer_cmd
135
150#define INCLINOMETER_MAP_MIKROBUS( cfg, mikrobus ) \
151 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
152 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
153 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
154 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
155
156 // inclinometer_map
157 // inclinometer
158
163typedef struct
164{
165 // Modules
166 spi_master_t spi;
168 pin_name_t chip_select;
170 uint8_t rs;
174
179typedef struct
180{
181 // Communication gpio pins
182 pin_name_t miso;
183 pin_name_t mosi;
184 pin_name_t sck;
185 pin_name_t cs;
187 // static variable
188 uint32_t spi_speed;
189 spi_master_mode_t spi_mode;
190 spi_master_chip_select_polarity_t cs_polarity;
193
198typedef struct
199{
200 float x;
201 float y;
202 float z;
205
217
234
250
265
278err_t inclinometer_generic_write ( inclinometer_t *ctx, uint8_t reg, uint16_t data_in );
279
292err_t inclinometer_generic_read ( inclinometer_t *ctx, uint8_t reg, uint16_t *data_out );
293
306err_t inclinometer_cmd_write ( inclinometer_t *ctx, uint32_t cmd );
307
321err_t inclinometer_cmd_read ( inclinometer_t *ctx, uint32_t cmd, uint16_t *cmd_data );
322
334err_t inclinometer_get_temperature ( inclinometer_t *ctx, float *temperature );
335
349
363
364#ifdef __cplusplus
365}
366#endif
367#endif // INCLINOMETER_H
368
369 // inclinometer
370
371// ------------------------------------------------------------------------ END
err_t inclinometer_cmd_write(inclinometer_t *ctx, uint32_t cmd)
CMD writing function.
err_t inclinometer_init(inclinometer_t *ctx, inclinometer_cfg_t *cfg)
Inclinometer initialization function.
err_t inclinometer_get_angle(inclinometer_t *ctx, inclinometer_accel_t *angle_data)
Angle reading.
err_t inclinometer_generic_read(inclinometer_t *ctx, uint8_t reg, uint16_t *data_out)
Data reading function.
err_t inclinometer_default_cfg(inclinometer_t *ctx)
Inclinometer default configuration function.
err_t inclinometer_generic_write(inclinometer_t *ctx, uint8_t reg, uint16_t data_in)
Data writing function.
void inclinometer_cfg_setup(inclinometer_cfg_t *cfg)
Inclinometer configuration object setup function.
err_t inclinometer_cmd_read(inclinometer_t *ctx, uint32_t cmd, uint16_t *cmd_data)
CMD reading function.
err_t inclinometer_get_temperature(inclinometer_t *ctx, float *temperature)
Temperature reading.
err_t inclinometer_get_axes(inclinometer_t *ctx, inclinometer_accel_t *axes_data)
Axes reading.
inclinometer_return_value_t
Inclinometer Click return value data.
Definition inclinometer.h:211
@ INCLINOMETER_CRC_ERROR
Definition inclinometer.h:214
@ INCLINOMETER_ERROR
Definition inclinometer.h:213
@ INCLINOMETER_OK
Definition inclinometer.h:212
Inclinometer Click axis/angle data object.
Definition inclinometer.h:199
float y
Definition inclinometer.h:201
float x
Definition inclinometer.h:200
float z
Definition inclinometer.h:202
Inclinometer Click configuration object.
Definition inclinometer.h:180
spi_master_chip_select_polarity_t cs_polarity
Definition inclinometer.h:190
pin_name_t sck
Definition inclinometer.h:184
spi_master_mode_t spi_mode
Definition inclinometer.h:189
pin_name_t mosi
Definition inclinometer.h:183
uint32_t spi_speed
Definition inclinometer.h:188
pin_name_t miso
Definition inclinometer.h:182
pin_name_t cs
Definition inclinometer.h:185
Inclinometer Click context object.
Definition inclinometer.h:164
spi_master_t spi
Definition inclinometer.h:166
uint8_t rs
Definition inclinometer.h:170
float resolution
Definition inclinometer.h:171
pin_name_t chip_select
Definition inclinometer.h:168