c3dhall11  2.0.0.0
c3dhall11.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 C3DHALL11_H
29 #define C3DHALL11_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define C3DHALL11_REG_DEVICE_CONFIG_1 0x00
70 #define C3DHALL11_REG_DEVICE_CONFIG_2 0x01
71 #define C3DHALL11_REG_SENSOR_CONFIG_1 0x02
72 #define C3DHALL11_REG_SENSOR_CONFIG_2 0x03
73 #define C3DHALL11_REG_X_THR_CONFIG 0x04
74 #define C3DHALL11_REG_Y_THR_CONFIG 0x05
75 #define C3DHALL11_REG_Z_THR_CONFIG 0x06
76 #define C3DHALL11_REG_T_CONFIG 0x07
77 #define C3DHALL11_REG_INT_CONFIG_1 0x08
78 #define C3DHALL11_REG_MAG_GAIN_CONFIG 0x09
79 #define C3DHALL11_REG_MAG_OFFSET_CONFIG_1 0x0A
80 #define C3DHALL11_REG_MAG_OFFSET_CONFIG_2 0x0B
81 #define C3DHALL11_REG_I2C_ADDRESS 0x0C
82 #define C3DHALL11_REG_DEVICE_ID 0x0D
83 #define C3DHALL11_REG_MANUFACTURER_ID_LSB 0x0E
84 #define C3DHALL11_REG_MANUFACTURER_ID_MSB 0x0F
85 #define C3DHALL11_REG_T_MSB_RESULT 0x10
86 #define C3DHALL11_REG_T_LSB_RESULT 0x11
87 #define C3DHALL11_REG_X_MSB_RESULT 0x12
88 #define C3DHALL11_REG_X_LSB_RESULT 0x13
89 #define C3DHALL11_REG_Y_MSB_RESULT 0x14
90 #define C3DHALL11_REG_Y_LSB_RESULT 0x15
91 #define C3DHALL11_REG_Z_MSB_RESULT 0x16
92 #define C3DHALL11_REG_Z_LSB_RESULT 0x17
93 #define C3DHALL11_REG_CONV_STATUS 0x18
94 #define C3DHALL11_REG_ANGLE_RESULT_MSB 0x19
95 #define C3DHALL11_REG_ANGLE_RESULT_LSB 0x1A
96 #define C3DHALL11_REG_MAGNITUDE_RESULT 0x1B
97 #define C3DHALL11_REG_DEVICE_STATUS 0x1C
98  // c3dhall11_reg
100 
115 #define C3DHALL11_CRC_DISABLE 0x00
116 #define C3DHALL11_CRC_ENABLE 0x80
117 #define C3DHALL11_CRC_EN_BIT_MASK 0x80
118 #define C3DHALL11_MAG_TEMPCO_0 0x00
119 #define C3DHALL11_MAG_TEMPCO_0p12 0x20
120 #define C3DHALL11_MAG_TEMPCO_0p2 0x60
121 #define C3DHALL11_MAG_TEMPCO_BIT_MASK 0x60
122 #define C3DHALL11_CONV_AVG_1X 0x00
123 #define C3DHALL11_CONV_AVG_2X 0x04
124 #define C3DHALL11_CONV_AVG_4X 0x08
125 #define C3DHALL11_CONV_AVG_8X 0x0C
126 #define C3DHALL11_CONV_AVG_16X 0x10
127 #define C3DHALL11_CONV_AVG_32X 0x14
128 #define C3DHALL11_CONV_AVG_BIT_MASK 0x1C
129 #define C3DHALL11_I2C_RD_STANDARD 0x00
130 #define C3DHALL11_I2C_RD_1_BYTE_16BIT 0x01
131 #define C3DHALL11_I2C_RD_1_BYTE_8BIT 0x02
132 #define C3DHALL11_I2C_RD_BIT_MASK 0x03
133 
138 #define C3DHALL11_THR_HYST_2S_COMPLEMENT 0x00
139 #define C3DHALL11_THR_HYST_7LSB 0x20
140 #define C3DHALL11_THR_HYST_BIT_MASK 0xE0
141 #define C3DHALL11_LP_LN_ACTUVE_CURRENT_MODE 0x00
142 #define C3DHALL11_LP_LN_NOISE_MODE 0x10
143 #define C3DHALL11_LP_LN_BIT_MASK 0x10
144 #define C3DHALL11_I2C_GLITCH_FILTER_ON 0x00
145 #define C3DHALL11_I2C_GLITCH_FILTER_OFF 0x08
146 #define C3DHALL11_I2C_GLITCH_FILTER_BIT_MASK 0x08
147 #define C3DHALL11_TRIGGER_MODE_CMD 0x00
148 #define C3DHALL11_TRIGGER_MODE_INT 0x04
149 #define C3DHALL11_TRIGGER_MODE_BIT_MASK 0x04
150 #define C3DHALL11_OPERATING_MODE_STANDBY 0x00
151 #define C3DHALL11_OPERATING_MODE_SLEEP 0x01
152 #define C3DHALL11_OPERATING_MODE_CONTINUOUS 0x02
153 #define C3DHALL11_OPERATING_MODE_WS 0x03
154 #define C3DHALL11_OPERATING_MODE_BIT_MASK 0x03
155 
160 #define C3DHALL11_MAG_CH_EN_DISABLE 0x00
161 #define C3DHALL11_MAG_CH_EN_ENABLE_X 0x10
162 #define C3DHALL11_MAG_CH_EN_ENABLE_Y 0x20
163 #define C3DHALL11_MAG_CH_EN_ENABLE_XY 0x30
164 #define C3DHALL11_MAG_CH_EN_ENABLE_Z 0x40
165 #define C3DHALL11_MAG_CH_EN_ENABLE_ZX 0x50
166 #define C3DHALL11_MAG_CH_EN_ENABLE_YZ 0x60
167 #define C3DHALL11_MAG_CH_EN_ENABLE_XYZ 0x70
168 #define C3DHALL11_MAG_CH_EN_ENABLE_XYX 0x80
169 #define C3DHALL11_MAG_CH_EN_ENABLE_YXY 0x90
170 #define C3DHALL11_MAG_CH_EN_ENABLE_YZY 0xA0
171 #define C3DHALL11_MAG_CH_EN_ENABLE_XZX 0xB0
172 #define C3DHALL11_MAG_CH_EN_BIT_MASK 0xF0
173 #define C3DHALL11_SLEEPTIME_1MS 0x00
174 #define C3DHALL11_SLEEPTIME_5MS 0x01
175 #define C3DHALL11_SLEEPTIME_10MS 0x02
176 #define C3DHALL11_SLEEPTIME_15MS 0x03
177 #define C3DHALL11_SLEEPTIME_20MS 0x04
178 #define C3DHALL11_SLEEPTIME_30MS 0x05
179 #define C3DHALL11_SLEEPTIME_50MS 0x06
180 #define C3DHALL11_SLEEPTIME_100MS 0x07
181 #define C3DHALL11_SLEEPTIME_500MS 0x08
182 #define C3DHALL11_SLEEPTIME_1000MS 0x09
183 #define C3DHALL11_SLEEPTIME_2000MS 0x0A
184 #define C3DHALL11_SLEEPTIME_5000MS 0x0B
185 #define C3DHALL11_SLEEPTIME_20000MS 0x0C
186 #define C3DHALL11_SLEEPTIME_BIT_MASK 0x0F
187 
192 #define C3DHALL11_THRX_COUNT_1 0x00
193 #define C3DHALL11_THRX_COUNT_4 0x40
194 #define C3DHALL11_THRX_COUNT_BIT_MASK 0x40
195 #define C3DHALL11_MAG_THR_DIR_ABOVE 0x00
196 #define C3DHALL11_MAG_THR_DIR_BELOW 0x20
197 #define C3DHALL11_MAG_THR_DIR_BIT_MASK 0x20
198 #define C3DHALL11_MAG_GAIN_CH_1 0x00
199 #define C3DHALL11_MAG_GAIN_CH_2 0x10
200 #define C3DHALL11_MAG_GAIN_CH_BIT_MASK 0x10
201 #define C3DHALL11_ANGLE_EN_NO_ANGLE 0x00
202 #define C3DHALL11_ANGLE_EN_XY_ANGLE 0x04
203 #define C3DHALL11_ANGLE_EN_YZ_ANGLE 0x08
204 #define C3DHALL11_ANGLE_EN_XZ_ANGLE 0x0C
205 #define C3DHALL11_ANGLE_EN_BIT_MASK 0x0C
206 #define C3DHALL11_X_Y_RANGE_40mT 0x00
207 #define C3DHALL11_X_Y_RANGE_80mT 0x02
208 #define C3DHALL11_X_Y_RANGE_BIT_MASK 0x02
209 #define C3DHALL11_Z_RANGE_40mT 0x00
210 #define C3DHALL11_Z_RANGE_80mT 0x01
211 #define C3DHALL11_Z_RANGE_BIT_MASK 0x01
212 
217 #define C3DHALL11_T_THR_CONFIG_BIT_MASK 0xFE
218 #define C3DHALL11_T_CH_EN_DISABLE 0x00
219 #define C3DHALL11_T_CH_EN_ENABLE 0x01
220 #define C3DHALL11_T_CH_EN_BIT_MASK 0x01
221 
226 #define C3DHALL11_RSLT_INT_NO_ASSERT 0x00
227 #define C3DHALL11_RSLT_INT_ASSERT 0x80
228 #define C3DHALL11_RSLT_INT_BIT_MASK 0x80
229 #define C3DHALL11_THRSLD_INT_NO_ASSERT 0x00
230 #define C3DHALL11_THRSLD_INT_ASSERT 0x40
231 #define C3DHALL11_THRSLD_INT_BIT_MASK 0x40
232 #define C3DHALL11_INT_STATE_LATCHED 0x00
233 #define C3DHALL11_INT_STATE_PULSE_10US 0x20
234 #define C3DHALL11_INT_STATE_BIT_MASK 0x20
235 #define C3DHALL11_INT_MODE_NO_INT 0x00
236 #define C3DHALL11_INT_MODE_INT 0x04
237 #define C3DHALL11_INT_MODE_INT_WO_I2C_BUSY 0x08
238 #define C3DHALL11_INT_MODE_SCL 0x0C
239 #define C3DHALL11_INT_MODE_SCL_WO_I2C_BUSY 0x10
240 #define C3DHALL11_INT_MODE_BIT_MASK 0x1C
241 #define C3DHALL11_MASK_INTB_ENABLE 0x00
242 #define C3DHALL11_MASK_INTB_DISABLE 0x01
243 #define C3DHALL11_MASK_INTB_BIT_MASK 0x01
244 
249 #define C3DHALL11_DEVICE_ID 0x01
250 #define C3DHALL11_MANUFACTURER_ID_LSB 0x49
251 #define C3DHALL11_MANUFACTURER_ID_MSB 0x54
252 
257 #define C3DHALL11_CONV_STATUS_SET_COUNT 0xE0
258 #define C3DHALL11_CONV_STATUS_DIAG_STATUS 0x02
259 #define C3DHALL11_CONV_STATUS_DATA_READY 0x01
260 
265 #define C3DHALL11_DEVICE_STATUS_INTB_RB 0x10
266 #define C3DHALL11_DEVICE_STATUS_OSC_ER 0x08
267 #define C3DHALL11_DEVICE_STATUS_INT_ER 0x04
268 #define C3DHALL11_DEVICE_STATUS_OTP_CRC_ER 0x02
269 #define C3DHALL11_DEVICE_STATUS_VCC_UV_ER 0x01
270 
275 #define C3DHALL11_TEMP_SENS_T0 25.0
276 #define C3DHALL11_TEMP_ADC_T0 17508
277 #define C3DHALL11_TEMP_ADC_RESOLUTION 60.1
278 #define C3DHALL11_ANGLE_RESOLUTION 16.0
279 #define C3DHALL11_XYZ_SENSITIVITY_40mT 820.0
280 #define C3DHALL11_XYZ_SENSITIVITY_80mT 410.0
281 
287 #define C3DHALL11_DEVICE_ADDRESS 0x35
288  // c3dhall11_set
290 
305 #define C3DHALL11_MAP_MIKROBUS( cfg, mikrobus ) \
306  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
307  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
308  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
309  // c3dhall11_map // c3dhall11
312 
317 typedef struct
318 {
319  float x_axis;
320  float y_axis;
321  float z_axis;
322  float angle;
323  float temperature;
324  uint8_t magnitude;
325 
327 
332 typedef struct
333 {
334  // Input pins
335  digital_in_t int_pin;
337  // Modules
338  i2c_master_t i2c;
340  // I2C slave address
341  uint8_t slave_address;
343 } c3dhall11_t;
344 
349 typedef struct
350 {
351  pin_name_t scl;
352  pin_name_t sda;
354  pin_name_t int_pin;
356  uint32_t i2c_speed;
357  uint8_t i2c_address;
360 
365 typedef enum
366 {
368  C3DHALL11_ERROR = -1
369 
371 
388 
403 
417 
432 err_t c3dhall11_generic_write ( c3dhall11_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
433 
448 err_t c3dhall11_generic_read ( c3dhall11_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
449 
462 err_t c3dhall11_write_register ( c3dhall11_t *ctx, uint8_t reg, uint8_t data_in );
463 
476 err_t c3dhall11_read_register ( c3dhall11_t *ctx, uint8_t reg, uint8_t *data_out );
477 
487 
499 
515 
516 #ifdef __cplusplus
517 }
518 #endif
519 #endif // C3DHALL11_H
520  // c3dhall11
522 
523 // ------------------------------------------------------------------------ END
c3dhall11_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c3dhall11.h:356
c3dhall11_t::slave_address
uint8_t slave_address
Definition: c3dhall11.h:341
c3dhall11_cfg_setup
void c3dhall11_cfg_setup(c3dhall11_cfg_t *cfg)
3D Hall 11 configuration object setup function.
c3dhall11_generic_write
err_t c3dhall11_generic_write(c3dhall11_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
3D Hall 11 I2C writing function.
c3dhall11_default_cfg
err_t c3dhall11_default_cfg(c3dhall11_t *ctx)
3D Hall 11 default configuration function.
c3dhall11_generic_read
err_t c3dhall11_generic_read(c3dhall11_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
3D Hall 11 I2C reading function.
c3dhall11_t::i2c
i2c_master_t i2c
Definition: c3dhall11.h:338
c3dhall11_write_register
err_t c3dhall11_write_register(c3dhall11_t *ctx, uint8_t reg, uint8_t data_in)
3D Hall 11 write register function.
c3dhall11_data_t::angle
float angle
Definition: c3dhall11.h:322
c3dhall11_cfg_t::i2c_address
uint8_t i2c_address
Definition: c3dhall11.h:357
C3DHALL11_ERROR
@ C3DHALL11_ERROR
Definition: c3dhall11.h:368
c3dhall11_t::int_pin
digital_in_t int_pin
Definition: c3dhall11.h:335
c3dhall11_data_t::x_axis
float x_axis
Definition: c3dhall11.h:319
C3DHALL11_OK
@ C3DHALL11_OK
Definition: c3dhall11.h:367
c3dhall11_cfg_t::int_pin
pin_name_t int_pin
Definition: c3dhall11.h:354
c3dhall11_init
err_t c3dhall11_init(c3dhall11_t *ctx, c3dhall11_cfg_t *cfg)
3D Hall 11 initialization function.
c3dhall11_read_register
err_t c3dhall11_read_register(c3dhall11_t *ctx, uint8_t reg, uint8_t *data_out)
3D Hall 11 read register function.
c3dhall11_get_int_pin
uint8_t c3dhall11_get_int_pin(c3dhall11_t *ctx)
3D Hall 11 get int pin function.
c3dhall11_check_communication
err_t c3dhall11_check_communication(c3dhall11_t *ctx)
3D Hall 11 check communication function.
c3dhall11_data_t
3D Hall 11 Click data object.
Definition: c3dhall11.h:318
c3dhall11_cfg_t
3D Hall 11 Click configuration object.
Definition: c3dhall11.h:350
c3dhall11_t
3D Hall 11 Click context object.
Definition: c3dhall11.h:333
c3dhall11_data_t::magnitude
uint8_t magnitude
Definition: c3dhall11.h:324
c3dhall11_data_t::y_axis
float y_axis
Definition: c3dhall11.h:320
c3dhall11_cfg_t::scl
pin_name_t scl
Definition: c3dhall11.h:351
c3dhall11_read_data
err_t c3dhall11_read_data(c3dhall11_t *ctx, c3dhall11_data_t *data_out)
3D Hall 11 read data function.
c3dhall11_return_value_t
c3dhall11_return_value_t
3D Hall 11 Click return value data.
Definition: c3dhall11.h:366
c3dhall11_cfg_t::sda
pin_name_t sda
Definition: c3dhall11.h:352
c3dhall11_data_t::z_axis
float z_axis
Definition: c3dhall11.h:321
c3dhall11_data_t::temperature
float temperature
Definition: c3dhall11.h:323