compass7 2.0.0.0
compass7.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 COMPASS7_H
29#define COMPASS7_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_i2c_master.h"
52
73#define COMPASS7_REG_XOUT0 0x00
74#define COMPASS7_REG_XOUT1 0x01
75#define COMPASS7_REG_YOUT0 0x02
76#define COMPASS7_REG_YOUT1 0x03
77#define COMPASS7_REG_ZOUT0 0x04
78#define COMPASS7_REG_ZOUT1 0x05
79#define COMPASS7_REG_XOUT2 0x06
80#define COMPASS7_REG_YOUT2 0x07
81#define COMPASS7_REG_ZOUT2 0x08
82#define COMPASS7_REG_TOUT 0x09
83#define COMPASS7_REG_TPH0 0x0A
84#define COMPASS7_REG_TPH1 0x0B
85#define COMPASS7_REG_TU 0x0C
86#define COMPASS7_REG_STATUS1 0x18
87#define COMPASS7_REG_STATUS0 0x19
88#define COMPASS7_REG_ODR 0x1A
89#define COMPASS7_REG_CONTROL0 0x1B
90#define COMPASS7_REG_CONTROL1 0x1C
91#define COMPASS7_REG_CONTROL2 0x1D
92#define COMPASS7_REG_ST_X_TH 0x1E
93#define COMPASS7_REG_ST_Y_TH 0x1F
94#define COMPASS7_REG_ST_Z_TH 0x20
95#define COMPASS7_REG_ST_X 0x27
96#define COMPASS7_REG_ST_Y 0x28
97#define COMPASS7_REG_ST_Z 0x29
98#define COMPASS7_REG_PRODUCT_ID 0x39
99
100 // compass7_reg
101
116#define COMPASS7_STATUS1_MEAS_T_DONE 0x80
117#define COMPASS7_STATUS1_MEAS_M_DONE 0x40
118#define COMPASS7_STATUS1_SAT_SENSOR 0x20
119#define COMPASS7_STATUS1_OTP_READ_DONE 0x10
120#define COMPASS7_STATUS1_ST_FAIL 0x08
121#define COMPASS7_STATUS1_MDT_FLAG_INT 0x04
122#define COMPASS7_STATUS1_MEAS_T_DONE_INT 0x02
123#define COMPASS7_STATUS1_MEAS_M_DONE_INT 0x01
124
129#define COMPASS7_CONTROL0_CMM_FREQ_EN 0x80
130#define COMPASS7_CONTROL0_AUTO_ST_EN 0x40
131#define COMPASS7_CONTROL0_AUTO_SR_EN 0x20
132#define COMPASS7_CONTROL0_DO_RESET 0x10
133#define COMPASS7_CONTROL0_DO_SET 0x08
134#define COMPASS7_CONTROL0_START_MDT 0x04
135#define COMPASS7_CONTROL0_TAKE_MEAS_T 0x02
136#define COMPASS7_CONTROL0_TAKE_MEAS_M 0x01
137
142#define COMPASS7_CONTROL1_SW_RESET 0x80
143#define COMPASS7_CONTROL1_ST_ENM 0x40
144#define COMPASS7_CONTROL1_ST_ENP 0x20
145#define COMPASS7_CONTROL1_Z_INHIBIT 0x10
146#define COMPASS7_CONTROL1_Y_INHIBIT 0x08
147#define COMPASS7_CONTROL1_X_INHIBIT 0x04
148#define COMPASS7_CONTROL1_BW_6p6MS 0x00
149#define COMPASS7_CONTROL1_BW_3p5MS 0x01
150#define COMPASS7_CONTROL1_BW_2p0MS 0x02
151#define COMPASS7_CONTROL1_BW_1p2MS 0x03
152#define COMPASS7_CONTROL1_BW_BIT_MASK 0x03
153
158#define COMPASS7_CONTROL2_HPOWER 0x80
159#define COMPASS7_CONTROL2_INT_MEAS_DONE_EN 0x40
160#define COMPASS7_CONTROL2_INT_MDT_EN 0x20
161#define COMPASS7_CONTROL2_CMM_EN 0x10
162#define COMPASS7_CONTROL2_EN_PRD_SET 0x08
163#define COMPASS7_CONTROL2_PRD_SET_1_SMPL 0x00
164#define COMPASS7_CONTROL2_PRD_SET_25_SMPL 0x01
165#define COMPASS7_CONTROL2_PRD_SET_75_SMPL 0x02
166#define COMPASS7_CONTROL2_PRD_SET_100_SMPL 0x03
167#define COMPASS7_CONTROL2_PRD_SET_250_SMPL 0x04
168#define COMPASS7_CONTROL2_PRD_SET_500_SMPL 0x05
169#define COMPASS7_CONTROL2_PRD_SET_1000_SMPL 0x06
170#define COMPASS7_CONTROL2_PRD_SET_2000_SMPL 0x07
171#define COMPASS7_CONTROL2_PRD_SET_BIT_MASK 0x07
172
177#define COMPASS7_ODR_DISABLE 0
178#define COMPASS7_ODR_1HZ 1
179#define COMPASS7_ODR_2HZ 2
180#define COMPASS7_ODR_5HZ 5
181#define COMPASS7_ODR_10HZ 10
182#define COMPASS7_ODR_25HZ 25
183#define COMPASS7_ODR_50HZ 50
184#define COMPASS7_ODR_100HZ 100
185
190#define COMPASS7_MAGNETIC_OFFSET 0x080000l
191#define COMPASS7_MAGNETIC_RESOLUTION 0.0625
192#define COMPASS7_MILLIGAUSS_TO_GAUSS 0.001
193#define COMPASS7_TEMPERATURE_OFFSET 75
194#define COMPASS7_TEMPERATURE_RESOLUTION 0.8
195#define COMPASS7_TIMEOUT 2000
196
201#define COMPASS7_MEAS_SINGLE_T 0
202#define COMPASS7_MEAS_SINGLE_M 1
203#define COMPASS7_MEAS_CONTINUOUS_M_1HZ 2
204#define COMPASS7_MEAS_CONTINUOUS_M_2HZ 3
205#define COMPASS7_MEAS_CONTINUOUS_M_5HZ 4
206#define COMPASS7_MEAS_CONTINUOUS_M_10HZ 5
207#define COMPASS7_MEAS_CONTINUOUS_M_25HZ 6
208#define COMPASS7_MEAS_CONTINUOUS_M_50HZ 7
209#define COMPASS7_MEAS_CONTINUOUS_M_100HZ 8
210
215#define COMPASS7_PRODUCT_ID 0x10
216
222#define COMPASS7_DEVICE_ADDRESS 0x30
223
224 // compass7_set
225
240#define COMPASS7_MAP_MIKROBUS( cfg, mikrobus ) \
241 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
242 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
243
244 // compass7_map
245 // compass7
246
251typedef struct
252{
253 // Modules
254 i2c_master_t i2c;
256 // I2C slave address
259} compass7_t;
260
265typedef struct
266{
267 pin_name_t scl;
268 pin_name_t sda;
270 uint32_t i2c_speed;
271 uint8_t i2c_address;
274
279typedef struct
280{
281 float x_axis;
282 float y_axis;
283 float z_axis;
284
286
291typedef enum
292{
294 COMPASS7_ERROR = -1
295
297
314
329
343
358err_t compass7_generic_write ( compass7_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
359
374err_t compass7_generic_read ( compass7_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
375
388err_t compass7_write_register ( compass7_t *ctx, uint8_t reg, uint8_t data_in );
389
402err_t compass7_read_register ( compass7_t *ctx, uint8_t reg, uint8_t *data_out );
403
415
427
447err_t compass7_set_measurement_mode ( compass7_t *ctx, uint8_t mode );
448
463
475err_t compass7_get_temperature ( compass7_t *ctx, float *temperature );
476
477#ifdef __cplusplus
478}
479#endif
480#endif // COMPASS7_H
481
482 // compass7
483
484// ------------------------------------------------------------------------ END
compass7_return_value_t
Compass 7 Click return value data.
Definition compass7.h:292
@ COMPASS7_OK
Definition compass7.h:293
@ COMPASS7_ERROR
Definition compass7.h:294
void compass7_cfg_setup(compass7_cfg_t *cfg)
Compass 7 configuration object setup function.
err_t compass7_set_measurement_mode(compass7_t *ctx, uint8_t mode)
Compass 7 set measurement mode function.
err_t compass7_read_register(compass7_t *ctx, uint8_t reg, uint8_t *data_out)
Compass 7 read register function.
err_t compass7_get_magnetic_flux(compass7_t *ctx, compass7_magnetic_flux_t *flux)
Compass 7 get magnetic flux function.
err_t compass7_soft_reset(compass7_t *ctx)
Compass 7 soft reset function.
err_t compass7_check_communication(compass7_t *ctx)
Compass 7 check communication function.
err_t compass7_init(compass7_t *ctx, compass7_cfg_t *cfg)
Compass 7 initialization function.
err_t compass7_write_register(compass7_t *ctx, uint8_t reg, uint8_t data_in)
Compass 7 write register function.
err_t compass7_generic_write(compass7_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Compass 7 I2C writing function.
err_t compass7_get_temperature(compass7_t *ctx, float *temperature)
Compass 7 get temperature function.
err_t compass7_generic_read(compass7_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Compass 7 I2C reading function.
err_t compass7_default_cfg(compass7_t *ctx)
Compass 7 default configuration function.
Compass 7 Click configuration object.
Definition compass7.h:266
uint32_t i2c_speed
Definition compass7.h:270
pin_name_t scl
Definition compass7.h:267
pin_name_t sda
Definition compass7.h:268
uint8_t i2c_address
Definition compass7.h:271
Compass 7 magnetic flux data object.
Definition compass7.h:280
float z_axis
Definition compass7.h:283
float x_axis
Definition compass7.h:281
float y_axis
Definition compass7.h:282
Compass 7 Click context object.
Definition compass7.h:252
i2c_master_t i2c
Definition compass7.h:254
uint8_t slave_address
Definition compass7.h:257