loadcell8  2.1.0.0
loadcell8.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 LOADCELL8_H
29 #define LOADCELL8_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 
78 #define LOADCELL8_DATA_NO_DATA 0
79 #define LOADCELL8_DATA_OK 1
80 #define LOADCELL8_WEIGHT_100G 100u
81 #define LOADCELL8_WEIGHT_500G 500u
82 #define LOADCELL8_WEIGHT_1000G 1000u
83 #define LOADCELL8_WEIGHT_5000G 5000u
84 #define LOADCELL8_WEIGHT_10000G 10000u
85 #define LOADCELL8_WEIGHT_ZERO 0.0f
86 #define LOADCELL8_AVG_MEASURE_100 100.0
87 #define LOADCELL8_MEASURE_DATA_RES 0x3FFF
88 
94 #define LOADCELL8_DEVICE_ADDRESS 0x78
95  // loadcell8_set
97 
112 #define LOADCELL8_MAP_MIKROBUS( cfg, mikrobus ) \
113  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
114  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
115  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
116  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST )
117  // loadcell8_map // loadcell8
120 
125 typedef struct
126 {
127  // Output pins
128  digital_out_t en;
130  // Input pins
131  digital_in_t an;
133  // Modules
134  i2c_master_t i2c;
136  // I2C slave address
137  uint8_t slave_address;
139 } loadcell8_t;
140 
145 typedef struct
146 {
147  pin_name_t scl;
148  pin_name_t sda;
150  pin_name_t an;
151  pin_name_t en;
153  uint32_t i2c_speed;
154  uint8_t i2c_address;
157 
162 typedef struct
163 {
164  float tare;
165  uint8_t tare_ok;
176 
178 
183 typedef enum
184 {
186  LOADCELL8_ERROR = -1
187 
189 
206 
221 
235 
250 err_t loadcell8_generic_write ( loadcell8_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
251 
266 err_t loadcell8_generic_read ( loadcell8_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
267 
277 
289 err_t loadcell8_read_raw_adc ( loadcell8_t *ctx, uint32_t *raw_adc );
290 
305 
320 err_t loadcell8_calibration_weight ( loadcell8_t *ctx, uint16_t cal_val, loadcell8_data_t *cell_data );
321 
335 err_t loadcell8_get_weight ( loadcell8_t *ctx, loadcell8_data_t *cell_data, float *weight_g );
336 
337 #ifdef __cplusplus
338 }
339 #endif
340 #endif // LOADCELL8_H
341  // loadcell8
343 
344 // ------------------------------------------------------------------------ END
loadcell8_cfg_t::sda
pin_name_t sda
Definition: loadcell8.h:148
loadcell8_data_t
Load Cell 8 Click data object.
Definition: loadcell8.h:163
loadcell8_read_raw_adc
err_t loadcell8_read_raw_adc(loadcell8_t *ctx, uint32_t *raw_adc)
Load Cell 8 read raw ADC value function.
loadcell8_t::slave_address
uint8_t slave_address
Definition: loadcell8.h:137
loadcell8_hw_reset
void loadcell8_hw_reset(loadcell8_t *ctx)
Load Cell 8 HW reset function.
loadcell8_generic_read
err_t loadcell8_generic_read(loadcell8_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Load Cell 8 I2C reading function.
loadcell8_t
Load Cell 8 Click context object.
Definition: loadcell8.h:126
loadcell8_data_t::weight_coeff_100g
float weight_coeff_100g
Definition: loadcell8.h:166
loadcell8_tare_scale
err_t loadcell8_tare_scale(loadcell8_t *ctx, loadcell8_data_t *cell_data)
Load Cell 8 read raw ADC value function.
loadcell8_data_t::weight_data_1000g_ok
uint8_t weight_data_1000g_ok
Definition: loadcell8.h:171
loadcell8_data_t::weight_coeff_500g
float weight_coeff_500g
Definition: loadcell8.h:168
loadcell8_data_t::weight_data_100g_ok
uint8_t weight_data_100g_ok
Definition: loadcell8.h:167
loadcell8_t::an
digital_in_t an
Definition: loadcell8.h:131
loadcell8_cfg_t::i2c_address
uint8_t i2c_address
Definition: loadcell8.h:154
LOADCELL8_ERROR
@ LOADCELL8_ERROR
Definition: loadcell8.h:186
loadcell8_get_weight
err_t loadcell8_get_weight(loadcell8_t *ctx, loadcell8_data_t *cell_data, float *weight_g)
Load Cell 8 get weight function.
loadcell8_default_cfg
err_t loadcell8_default_cfg(loadcell8_t *ctx)
Load Cell 8 default configuration function.
loadcell8_data_t::tare
float tare
Definition: loadcell8.h:164
loadcell8_t::i2c
i2c_master_t i2c
Definition: loadcell8.h:134
loadcell8_data_t::weight_data_5000g_ok
uint8_t weight_data_5000g_ok
Definition: loadcell8.h:173
loadcell8_data_t::weight_data_10000g_ok
uint8_t weight_data_10000g_ok
Definition: loadcell8.h:175
loadcell8_data_t::weight_coeff_5000g
float weight_coeff_5000g
Definition: loadcell8.h:172
loadcell8_data_t::weight_data_500g_ok
uint8_t weight_data_500g_ok
Definition: loadcell8.h:169
loadcell8_t::en
digital_out_t en
Definition: loadcell8.h:128
loadcell8_cfg_t::en
pin_name_t en
Definition: loadcell8.h:151
loadcell8_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: loadcell8.h:153
loadcell8_calibration_weight
err_t loadcell8_calibration_weight(loadcell8_t *ctx, uint16_t cal_val, loadcell8_data_t *cell_data)
Load Cell 8 calibrate weight function.
loadcell8_data_t::weight_coeff_1000g
float weight_coeff_1000g
Definition: loadcell8.h:170
loadcell8_return_value_t
loadcell8_return_value_t
Load Cell 8 Click return value data.
Definition: loadcell8.h:184
loadcell8_cfg_setup
void loadcell8_cfg_setup(loadcell8_cfg_t *cfg)
Load Cell 8 configuration object setup function.
loadcell8_generic_write
err_t loadcell8_generic_write(loadcell8_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Load Cell 8 I2C writing function.
loadcell8_cfg_t::an
pin_name_t an
Definition: loadcell8.h:150
loadcell8_cfg_t::scl
pin_name_t scl
Definition: loadcell8.h:147
loadcell8_data_t::tare_ok
uint8_t tare_ok
Definition: loadcell8.h:165
loadcell8_data_t::weight_coeff_10000g
float weight_coeff_10000g
Definition: loadcell8.h:174
loadcell8_init
err_t loadcell8_init(loadcell8_t *ctx, loadcell8_cfg_t *cfg)
Load Cell 8 initialization function.
LOADCELL8_OK
@ LOADCELL8_OK
Definition: loadcell8.h:185
loadcell8_cfg_t
Load Cell 8 Click configuration object.
Definition: loadcell8.h:146