loadcell4 2.0.0.0
loadcell4.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 LOADCELL4_H
29#define LOADCELL4_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 LOADCELL4_GET_RESULT_ERROR 0
74#define LOADCELL4_GET_RESULT_OK 1
75#define LOADCELL4_DATA_NO_DATA 0
76#define LOADCELL4_DATA_OK 1
77#define LOADCELL4_WEIGHT_100G 100
78#define LOADCELL4_WEIGHT_500G 500
79#define LOADCELL4_WEIGHT_1000G 1000
80#define LOADCELL4_WEIGHT_5000G 5000
81#define LOADCELL4_WEIGHT_10000G 10000
82#define LOADCELL4_DEFAULT_WEIGHT_SCALE_COEFFICIENT 0.088495575221
83
88#define LOADCELL4_EEPROM_ID_0 0x00
89#define LOADCELL4_EEPROM_CONFIG_1 0x01
90#define LOADCELL4_EEPROM_CONFIG_2 0x02
91#define LOADCELL4_EEPROM_OFFSET_BRIDGE 0x03
92#define LOADCELL4_EEPROM_GAIN_BRIDGE 0x04
93#define LOADCELL4_EEPROM_TEMP_COF_GAIN 0x05
94#define LOADCELL4_EEPROM_TEMP_COF_OFFSET 0x06
95#define LOADCELL4_EEPROM_2ND_ORDER_TEMP_COF_OFFSET 0x07
96#define LOADCELL4_EEPROM_2ND_ORDER_TEMP_COF_GAIN 0x08
97#define LOADCELL4_EEPROM_2ND_ORDER_BRIDGE 0x09
98#define LOADCELL4_EEPROM_OFFSET_TEMP 0x0A
99#define LOADCELL4_EEPROM_GAINT_TEMP 0x0B
100#define LOADCELL4_EEPROM_2ND_ORDER_TEMP 0x0C
101#define LOADCELL4_EEPROM_TEMP_SETL 0x0D
102#define LOADCELL4_EEPROM_ID_1 0x0E
103#define LOADCELL4_EEPROM_BRIDGE_CONFIG 0x0F
104#define LOADCELL4_EEPROM_TEMP_CONFIG 0x10
105#define LOADCELL4_EEPROM_OSC_TRIM 0x11
106#define LOADCELL4_EEPROM_SIGNATURE 0x12
107#define LOADCELL4_EEPROM_ID_2 0x13
108#define LOADCELL4_EEPROM_WRITE_CMD 0x40
109#define LOADCELL4_EEPROM_STATUS_READ_READY 0x5A
110
115#define LOADCELL4_STATUS_NORMAL 0x00
116#define LOADCELL4_STATUS_CMD_MODE 0x01
117#define LOADCELL4_STATUS_STALE_DATA 0x02
118#define LOADCELL4_STATUS_ERROR 0x03
119#define LOADCELL4_STATUS_BIT_MASK 0x03
120#define LOADCELL4_BRIDGE_RES 0x3FFF
121
126#define LOADCELL4_DUMMY 0x0000
127
132#define LOADCELL4_PWR_OFF 0x00
133#define LOADCELL4_PWR_ON 0x01
134
139#define LOADCELL4_WEIGHT_ZERO 0.000
140
146#define LOADCELL4_NUMB_OF_SUM_AVG_20 20.00
147#define LOADCELL4_NUMB_OF_SUM_AVG_100 100.0
148
153#define LOADCELL4_CMD_MODE_START 0xA0
154#define LOADCELL4_CMD_MODE_STOP 0x80
155
161#define LOADCELL4_SET_DEV_ADDR 0x28
162
163 // loadcell4_set
164
179#define LOADCELL4_MAP_MIKROBUS( cfg, mikrobus ) \
180 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
181 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
182 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
183 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
184
185 // loadcell4_map
186 // loadcell4
187
192typedef struct
193{
194 // Output pins
195 digital_out_t en;
197 // Input pins
198 digital_in_t int_pin;
200 // Modules
201 i2c_master_t i2c;
203 // I2C slave address
207
212typedef struct
213{
214 pin_name_t scl;
215 pin_name_t sda;
217 pin_name_t en;
218 pin_name_t int_pin;
220 uint32_t i2c_speed;
221 uint8_t i2c_address;
224
245
256
273
288
303
319err_t loadcell4_generic_write ( loadcell4_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
320
336err_t loadcell4_generic_read ( loadcell4_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
337
348void loadcell4_read_raw ( loadcell4_t *ctx, uint32_t *rx_data );
349
361uint8_t loadcell4_read_data ( loadcell4_t *ctx, uint16_t *bridge_data, int16_t *temperature_data );
362
374
385
396
407void loadcell4_power_dev ( loadcell4_t *ctx, uint8_t power_state );
408
420void loadcell4_write_eeprom ( loadcell4_t *ctx, uint8_t cmd_byte, uint16_t data_word );
421
432uint16_t loadcell4_read_eeprom ( loadcell4_t *ctx, uint8_t cmd_byte );
433
443
456
474err_t loadcell4_calibration ( loadcell4_t *ctx, uint16_t cal_val, loadcell4_data_t *cell_data );
489
490#ifdef __cplusplus
491}
492#endif
493#endif // LOADCELL4_H
494
495 // loadcell4
496
497// ------------------------------------------------------------------------ END
err_t loadcell4_default_cfg(loadcell4_t *ctx)
Load Cell 4 default configuration function.
void loadcell4_read_raw(loadcell4_t *ctx, uint32_t *rx_data)
Read raw data function.
void loadcell4_end_cmd_mode(loadcell4_t *ctx)
Start command mode function.
void loadcell4_start_cmd_mode(loadcell4_t *ctx)
Start command mode function.
err_t loadcell4_generic_write(loadcell4_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Load Cell 4 I2C writing function.
uint16_t loadcell4_read_bridge_data(loadcell4_t *ctx)
Read bridge data function.
uint8_t loadcell4_get_int(loadcell4_t *ctx)
Get state of the INT pin function.
void loadcell4_write_eeprom(loadcell4_t *ctx, uint8_t cmd_byte, uint16_t data_word)
Write eeprom function.
err_t loadcell4_calibration(loadcell4_t *ctx, uint16_t cal_val, loadcell4_data_t *cell_data)
Calibration function.
err_t loadcell4_generic_read(loadcell4_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Load Cell 4 I2C reading function.
void loadcell4_power_dev(loadcell4_t *ctx, uint8_t power_state)
Enable power function.
uint16_t loadcell4_read_eeprom(loadcell4_t *ctx, uint8_t cmd_byte)
Write eeprom function.
void loadcell4_cfg_setup(loadcell4_cfg_t *cfg)
Load Cell 4 configuration object setup function.
float loadcell4_get_weight(loadcell4_t *ctx, loadcell4_data_t *cell_data)
Get weight function.
void loadcell4_tare(loadcell4_t *ctx, loadcell4_data_t *cell_data)
Tare the scales function.
uint8_t loadcell4_read_data(loadcell4_t *ctx, uint16_t *bridge_data, int16_t *temperature_data)
Read data function.
err_t loadcell4_init(loadcell4_t *ctx, loadcell4_cfg_t *cfg)
Load Cell 4 initialization function.
loadcell4_return_value_t
Load Cell 4 Click return value data.
Definition loadcell4.h:251
@ LOADCELL4_OK
Definition loadcell4.h:252
@ LOADCELL4_ERROR
Definition loadcell4.h:253
Load Cell 4 Click configuration object.
Definition loadcell4.h:213
uint32_t i2c_speed
Definition loadcell4.h:220
pin_name_t scl
Definition loadcell4.h:214
pin_name_t en
Definition loadcell4.h:217
pin_name_t int_pin
Definition loadcell4.h:218
pin_name_t sda
Definition loadcell4.h:215
uint8_t i2c_address
Definition loadcell4.h:221
Load Cell 4 Click data object.
Definition loadcell4.h:230
float tare
Definition loadcell4.h:231
float weight_coeff_10000g
Definition loadcell4.h:241
uint8_t weight_data_1000g_ok
Definition loadcell4.h:238
uint8_t weight_data_500g_ok
Definition loadcell4.h:236
float weight_coeff_100g
Definition loadcell4.h:233
float weight_coeff_5000g
Definition loadcell4.h:239
uint8_t weight_data_10000g_ok
Definition loadcell4.h:242
float weight_coeff_500g
Definition loadcell4.h:235
uint8_t weight_data_5000g_ok
Definition loadcell4.h:240
uint8_t tare_ok
Definition loadcell4.h:232
uint8_t weight_data_100g_ok
Definition loadcell4.h:234
float weight_coeff_1000g
Definition loadcell4.h:237
Load Cell 4 Click context object.
Definition loadcell4.h:193
digital_in_t int_pin
Definition loadcell4.h:198
i2c_master_t i2c
Definition loadcell4.h:201
digital_out_t en
Definition loadcell4.h:195
uint8_t slave_address
Definition loadcell4.h:204