41#ifdef PREINIT_SUPPORTED
45#ifdef MikroCCoreVersion
46 #if MikroCCoreVersion >= 1
51#include "drv_digital_in.h"
52#include "drv_i2c_master.h"
65#define LOADCELL2_MAP_MIKROBUS( cfg, mikrobus ) \
66 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
67 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
68 cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
75#define LOADCELL2_RETVAL uint8_t
77#define LOADCELL2_OK 0x00
78#define LOADCELL2_INIT_ERROR 0xFF
85#define LOADCELL2_SLAVE_ADDRESS 0x2A
92#define LOADCELL2_REG_PU_CTRL 0x00
93#define LOADCELL2_REG_CTRL1 0x01
94#define LOADCELL2_REG_CTRL2 0x02
95#define LOADCELL2_REG_OCAL1_B2 0x03
96#define LOADCELL2_REG_OCAL1_B1 0x04
97#define LOADCELL2_REG_OCAL1_B0 0x05
98#define LOADCELL2_REG_GCAL1_B3 0x06
99#define LOADCELL2_REG_GCAL1_B2 0x07
100#define LOADCELL2_REG_GCAL1_B1 0x08
101#define LOADCELL2_REG_GCAL1_B0 0x09
102#define LOADCELL2_REG_OCAL2_B2 0x0A
103#define LOADCELL2_REG_OCAL2_B1 0x0B
104#define LOADCELL2_REG_OCAL2_B0 0x0C
105#define LOADCELL2_REG_GCAL2_B3 0x0D
106#define LOADCELL2_REG_GCAL2_B2 0x0E
107#define LOADCELL2_REG_GCAL2_B0 0x0F
108#define LOADCELL2_REG_GCAL2_B1 0x10
109#define LOADCELL2_REG_I2C_CTRL 0x11
110#define LOADCELL2_REG_ADC_B2 0x12
111#define LOADCELL2_REG_ADC_B1 0x13
112#define LOADCELL2_REG_ADC_B0 0x14
113#define LOADCELL2_REG_ADC_REG 0x15
114#define LOADCELL2_REG_OTP_B1 0x16
115#define LOADCELL2_REG_OTP_B0 0x17
116#define LOADCELL2_REG_RES_00 0x18
117#define LOADCELL2_REG_RES_01 0x19
118#define LOADCELL2_REG_RES_02 0x1A
119#define LOADCELL2_REG_PGA_REG 0x1B
120#define LOADCELL2_REG_POW_CTRL 0x1C
121#define LOADCELL2_REG_RES_03 0x1D
122#define LOADCELL2_REG_RES_04 0x1E
123#define LOADCELL2_REG_REV_ID 0x1F
130#define LOADCELL2_ERROR 0x00
131#define LOADCELL2_SUCCESS 0x01
138#define LOADCELL2_AVDDS 0x80
139#define LOADCELL2_OSCS 0x40
140#define LOADCELL2_CR 0x20
141#define LOADCELL2_CS 0x10
142#define LOADCELL2_PUR 0x08
143#define LOADCELL2_PUA 0x04
144#define LOADCELL2_PUD 0x02
145#define LOADCELL2_RR 0x01
157#define LOADCELL2_GAIN_VAL_x128 128
158#define LOADCELL2_GAIN_VAL_x64 64
159#define LOADCELL2_GAIN_VAL_x32 32
160#define LOADCELL2_GAIN_VAL_x16 16
161#define LOADCELL2_GAIN_VAL_x8 8
162#define LOADCELL2_GAIN_VAL_x4 4
163#define LOADCELL2_GAIN_VAL_x2 2
164#define LOADCELL2_GAIN_VAL_x1 1
179#define LOADCELL2_CONV_RATE_SPS_320 320
180#define LOADCELL2_CONV_RATE_SPS_80 80
181#define LOADCELL2_CONV_RATE_SPS_40 40
182#define LOADCELL2_CONV_RATE_SPS_20 20
183#define LOADCELL2_CONV_RATE_SPS_10 10
192#define LOADCELL2_DATA_NO_DATA 0
193#define LOADCELL2_DATA_OK 1
200#define LOADCELL2_GET_RESULT_ERROR 0
201#define LOADCELL2_GET_RESULT_OK 1
208#define LOADCELL2_WEIGHT_100G 100
209#define LOADCELL2_WEIGHT_500G 500
210#define LOADCELL2_WEIGHT_1000G 1000
211#define LOADCELL2_WEIGHT_5000G 5000
212#define LOADCELL2_WEIGHT_10000G 10000
219#define LOADCELL2_DEFAULT_WEIGHT_SCALE_COEFFICIENT 0.088495575221
#define LOADCELL2_RETVAL
Definition loadcell2.h:75
void loadcell2_cfg_setup(loadcell2_cfg_t *cfg)
Config Object Initialization function.
LOADCELL2_RETVAL loadcell2_init(loadcell2_t *ctx, loadcell2_cfg_t *cfg)
Initialization function.
uint8_t loadcell2_calibration(loadcell2_t *ctx, uint16_t cal_val, loadcell2_data_t *cell_data)
Calibration function.
void loadcell2_default_cfg(loadcell2_t *ctx)
Click Default Configuration function.
void loadcell2_set_gain(loadcell2_t *ctx, uint8_t gain_val)
Set gain function.
void loadcell2_tare(loadcell2_t *ctx, loadcell2_data_t *cell_data)
Tare function.
void loadcell2_turn_off_clk_chp(loadcell2_t *ctx)
Turn Off clk chp function.
void loadcell2_generic_write(loadcell2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void loadcell2_calibrate_afe(loadcell2_t *ctx)
Calibrate analog front end of system function.
void loadcell2_generic_read(loadcell2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void loadcell2_enable_dec_cap(loadcell2_t *ctx)
Enables PGA output function.
void loadcell2_set_sample_rate(loadcell2_t *ctx, uint8_t rate_sps)
Set sample rate function.
float loadcell2_get_weight(loadcell2_t *ctx, loadcell2_data_t *cell_data)
Get weight function.
uint8_t loadcell2_check_data_ready(loadcell2_t *ctx)
Check data ready function.
void loadcell2_set_ldo_voltage(loadcell2_t *ctx)
Set LDO Voltage function.
LOADCELL2_RETVAL loadcell2_power_on(loadcell2_t *ctx)
Power On function.
void loadcell2_reset(loadcell2_t *ctx)
Reset function.
uint8_t loadcell2_check_drdy(loadcell2_t *ctx)
Check data ready function.
uint32_t loadcell2_get_result(loadcell2_t *ctx)
Get results function.
Click configuration structure definition.
Definition loadcell2.h:254
uint32_t i2c_speed
Definition loadcell2.h:266
pin_name_t scl
Definition loadcell2.h:257
pin_name_t rdy
Definition loadcell2.h:262
pin_name_t sda
Definition loadcell2.h:258
uint8_t i2c_address
Definition loadcell2.h:267
Click data structure definition.
Definition loadcell2.h:275
float tare
Definition loadcell2.h:276
float weight_coeff_10000g
Definition loadcell2.h:286
uint8_t weight_data_1000g_ok
Definition loadcell2.h:283
uint8_t weight_data_500g_ok
Definition loadcell2.h:281
float weight_coeff_100g
Definition loadcell2.h:278
float weight_coeff_5000g
Definition loadcell2.h:284
uint8_t weight_data_10000g_ok
Definition loadcell2.h:287
float weight_coeff_500g
Definition loadcell2.h:280
uint8_t weight_data_5000g_ok
Definition loadcell2.h:285
uint8_t tare_ok
Definition loadcell2.h:277
uint8_t weight_data_100g_ok
Definition loadcell2.h:279
float weight_coeff_1000g
Definition loadcell2.h:282
Click ctx object definition.
Definition loadcell2.h:233
i2c_master_t i2c
Definition loadcell2.h:242
uint8_t slave_address
Definition loadcell2.h:246
digital_in_t rdy
Definition loadcell2.h:238