c3dhall14  2.1.0.0
c3dhall14.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 C3DHALL14_H
29 #define C3DHALL14_H
30 
31 #ifdef __cplusplus
32 extern "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 C3DHALL14_REG_STAT1 0x00
74 #define C3DHALL14_REG_X_LSB 0x01
75 #define C3DHALL14_REG_X_MSB 0x02
76 #define C3DHALL14_REG_Y_LSB 0x03
77 #define C3DHALL14_REG_Y_MSB 0x04
78 #define C3DHALL14_REG_Z_LSB 0x05
79 #define C3DHALL14_REG_Z_MSB 0x06
80 #define C3DHALL14_REG_STAT2 0x07
81 #define C3DHALL14_REG_T_LSB 0x08
82 #define C3DHALL14_REG_T_MSB 0x09
83 #define C3DHALL14_REG_CID 0x0A
84 #define C3DHALL14_REG_DID 0x0B
85 #define C3DHALL14_REG_CTRL1 0x0E
86 #define C3DHALL14_REG_CTRL2 0x0F
87 #define C3DHALL14_REG_RST 0x11
88 #define C3DHALL14_REG_CTRL3 0x14
89 #define C3DHALL14_REG_CTRL4 0x15
90 #define C3DHALL14_REG_X_THR_LSB 0x58
91 #define C3DHALL14_REG_X_THR_MSB 0x59
92 #define C3DHALL14_REG_Y_THR_LSB 0x5A
93 #define C3DHALL14_REG_Y_THR_MSB 0x5B
94 #define C3DHALL14_REG_Z_THR_LSB 0x5C
95 #define C3DHALL14_REG_Z_THR_MSB 0x5D
96  // c3dhall14_reg
98 
113 #define C3DHALL14_MODE_POWER_DOWN_0 0x00
114 #define C3DHALL14_MODE_SINGLE_MEAS_0 0x01
115 #define C3DHALL14_MODE_CONT_MEAS_5HZ 0x02
116 #define C3DHALL14_MODE_CONT_MEAS_10HZ 0x03
117 #define C3DHALL14_MODE_CONT_MEAS_20HZ 0x04
118 #define C3DHALL14_MODE_CONT_MEAS_50HZ 0x05
119 #define C3DHALL14_MODE_CONT_MEAS_100HZ 0x06
120 #define C3DHALL14_MODE_SELF_TEST 0x07
121 #define C3DHALL14_MODE_POWER_DOWN_1 0x08
122 #define C3DHALL14_MODE_SINGLE_MEAS_1 0x09
123 #define C3DHALL14_MODE_CONT_MEAS_200HZ 0x0A
124 #define C3DHALL14_MODE_CONT_MEAS_500HZ 0x0B
125 #define C3DHALL14_MODE_CONT_MEAS_700HZ 0x0C
126 #define C3DHALL14_MODE_CONT_MEAS_1000HZ 0x0D
127 #define C3DHALL14_MODE_CONT_MEAS_1400HZ 0x0E
128 #define C3DHALL14_MODE_POWER_DOWN_2 0x0F
129 #define C3DHALL14_MODE_MASK 0x0F
130 
135 #define C3DHALL14_COMPANY_ID 0x94
136 #define C3DHALL14_DEVICE_ID 0xAA
137 
142 #define C3DHALL14_RESET 0x06
143 
148 #define C3DHALL14_STAT1_INT 0x10
149 #define C3DHALL14_STAT1_RT 0x08
150 #define C3DHALL14_STAT1_DRDY 0x01
151 #define C3DHALL14_STAT2_DOR 0x08
152 #define C3DHALL14_STAT2_HOVF_Z 0x04
153 #define C3DHALL14_STAT2_HOVF_Y 0x02
154 #define C3DHALL14_STAT2_HOVF_X 0x01
155 
160 #define C3DHALL14_DRDY_INT_ENABLE 0x01
161 #define C3DHALL14_DRDY_INT_DISABLE 0x00
162 #define C3DHALL14_DRDY_INT_EN_MASK 0x08
163 
168 #define C3DHALL14_TEMPERATURE_RES 50.0f
169 #define C3DHALL14_TEMPERATURE_ENABLE 0x01
170 #define C3DHALL14_TEMPERATURE_DISABLE 0x00
171 #define C3DHALL14_TEMPERATURE_EN_MASK 0x20
172 
177 #define C3DHALL14_MAG_FLUX_RES_H 1.5f
178 #define C3DHALL14_MAG_FLUX_RES_L 0.15f
179 #define C3DHALL14_RANGE_HIGH_LOW_CURRENT 0x00
180 #define C3DHALL14_RANGE_HIGH_LOW_NOISE 0x01
181 #define C3DHALL14_RANGE_LOW_LOW_NOISE 0x02
182 #define C3DHALL14_RANGE_MASK 0xE0
183 #define C3DHALL14_RANGE_SHIFT 5
184 
190 #define C3DHALL14_DEVICE_ADDRESS 0x60
191  // c3dhall14_set
193 
208 #define C3DHALL14_MAP_MIKROBUS( cfg, mikrobus ) \
209  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
210  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
211  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
212  // c3dhall14_map // c3dhall14
215 
220 typedef struct
221 {
222  // Input pins
223  digital_in_t int_pin;
225  // Modules
226  i2c_master_t i2c;
228  // I2C slave address
229  uint8_t slave_address;
231  float mag_flux_res;
232  uint8_t drdy_int_out;
234 } c3dhall14_t;
235 
240 typedef struct
241 {
242  pin_name_t scl;
243  pin_name_t sda;
245  pin_name_t int_pin;
247  uint32_t i2c_speed;
248  uint8_t i2c_address;
251 
256 typedef enum
257 {
259  C3DHALL14_ERROR = -1
260 
262 
279 
294 
308 
322 err_t c3dhall14_mem_write_single ( c3dhall14_t *ctx, uint8_t reg, uint8_t data_in );
323 
338 err_t c3dhall14_mem_write_multi ( c3dhall14_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
339 
353 err_t c3dhall14_mem_direct_read ( c3dhall14_t *ctx, uint8_t *data_out, uint8_t len );
354 
369 err_t c3dhall14_mem_read ( c3dhall14_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
370 
383 
393 
406 
421 err_t c3dhall14_get_magnetic_flux ( c3dhall14_t *ctx, float *x_axis, float *y_axis, float *z_axis );
422 
434 err_t c3dhall14_get_temperature ( c3dhall14_t *ctx, float *temperature );
435 
447 
460 err_t c3dhall14_set_operating_mode ( c3dhall14_t *ctx, uint8_t mode );
461 
475 err_t c3dhall14_set_range ( c3dhall14_t *ctx, uint8_t range );
476 
489 err_t c3dhall14_enable_temp_sensor ( c3dhall14_t *ctx, uint8_t enable );
490 
503 err_t c3dhall14_enable_drdy_int ( c3dhall14_t *ctx, uint8_t enable );
504 
505 #ifdef __cplusplus
506 }
507 #endif
508 #endif // C3DHALL14_H
509  // c3dhall14
511 
512 // ------------------------------------------------------------------------ END
c3dhall14_t::i2c
i2c_master_t i2c
Definition: c3dhall14.h:226
c3dhall14_mem_direct_read
err_t c3dhall14_mem_direct_read(c3dhall14_t *ctx, uint8_t *data_out, uint8_t len)
3D Hall 14 mem direct read function.
c3dhall14_return_value_t
c3dhall14_return_value_t
3D Hall 14 Click return value data.
Definition: c3dhall14.h:257
c3dhall14_cfg_setup
void c3dhall14_cfg_setup(c3dhall14_cfg_t *cfg)
3D Hall 14 configuration object setup function.
c3dhall14_t::slave_address
uint8_t slave_address
Definition: c3dhall14.h:229
C3DHALL14_OK
@ C3DHALL14_OK
Definition: c3dhall14.h:258
c3dhall14_set_operating_mode
err_t c3dhall14_set_operating_mode(c3dhall14_t *ctx, uint8_t mode)
3D Hall 14 set operating mode function.
c3dhall14_check_communication
err_t c3dhall14_check_communication(c3dhall14_t *ctx)
3D Hall 14 check communication function.
c3dhall14_cfg_t::scl
pin_name_t scl
Definition: c3dhall14.h:242
c3dhall14_mem_write_single
err_t c3dhall14_mem_write_single(c3dhall14_t *ctx, uint8_t reg, uint8_t data_in)
3D Hall 14 mem write single function.
c3dhall14_get_magnetic_flux
err_t c3dhall14_get_magnetic_flux(c3dhall14_t *ctx, float *x_axis, float *y_axis, float *z_axis)
3D Hall 14 get magnetic flux function.
c3dhall14_get_temperature
err_t c3dhall14_get_temperature(c3dhall14_t *ctx, float *temperature)
3D Hall 14 get temperature function.
c3dhall14_t
3D Hall 14 Click context object.
Definition: c3dhall14.h:221
c3dhall14_t::int_pin
digital_in_t int_pin
Definition: c3dhall14.h:223
c3dhall14_mem_write_multi
err_t c3dhall14_mem_write_multi(c3dhall14_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
3D Hall 14 mem write multi function.
c3dhall14_check_data_ready
err_t c3dhall14_check_data_ready(c3dhall14_t *ctx)
3D Hall 14 check data ready function.
C3DHALL14_ERROR
@ C3DHALL14_ERROR
Definition: c3dhall14.h:259
c3dhall14_default_cfg
err_t c3dhall14_default_cfg(c3dhall14_t *ctx)
3D Hall 14 default configuration function.
c3dhall14_set_range
err_t c3dhall14_set_range(c3dhall14_t *ctx, uint8_t range)
3D Hall 14 set range function.
c3dhall14_cfg_t::int_pin
pin_name_t int_pin
Definition: c3dhall14.h:245
c3dhall14_reset
err_t c3dhall14_reset(c3dhall14_t *ctx)
3D Hall 14 reset function.
c3dhall14_cfg_t
3D Hall 14 Click configuration object.
Definition: c3dhall14.h:241
c3dhall14_cfg_t::sda
pin_name_t sda
Definition: c3dhall14.h:243
c3dhall14_t::drdy_int_out
uint8_t drdy_int_out
Definition: c3dhall14.h:232
c3dhall14_enable_drdy_int
err_t c3dhall14_enable_drdy_int(c3dhall14_t *ctx, uint8_t enable)
3D Hall 14 enable drdy int function.
c3dhall14_get_int_pin
uint8_t c3dhall14_get_int_pin(c3dhall14_t *ctx)
3D Hall 14 get int pin function.
c3dhall14_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c3dhall14.h:247
c3dhall14_enable_temp_sensor
err_t c3dhall14_enable_temp_sensor(c3dhall14_t *ctx, uint8_t enable)
3D Hall 14 enable temp sensor function.
c3dhall14_mem_read
err_t c3dhall14_mem_read(c3dhall14_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
3D Hall 14 mem read function.
c3dhall14_cfg_t::i2c_address
uint8_t i2c_address
Definition: c3dhall14.h:248
c3dhall14_t::mag_flux_res
float mag_flux_res
Definition: c3dhall14.h:231
c3dhall14_init
err_t c3dhall14_init(c3dhall14_t *ctx, c3dhall14_cfg_t *cfg)
3D Hall 14 initialization function.