loadcell5 2.0.0.0
loadcell5.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 LOADCELL5_H
29#define LOADCELL5_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_spi_master.h"
52
53
80#define LOADCELL5_MODE_POWER_DOWN 0x00
81#define LOADCELL5_MODE_POWER_UP 0x01
82
83 // pwr_mode
84
95#define LOADCELL5_UPDATE_RATE_16_7_Hz 0x00
96#define LOADCELL5_UPDATE_RATE_10_Hz 0x01
97
98 // fil_sel
99
110#define LOADCELL5_GAIN_1 1
111#define LOADCELL5_GAIN_128 128
112
113 // gain
114
115
116 // loadcell5_set
117
138#define LOADCELL5_NEW_DATA_IS_AVAILABLE 0
139#define LOADCELL5_NO_DATA 1
140
141 // check_data_ready
142
153#define LOADCELL5_STATUS_PAT_ADC_PERFORMED_NOT_CORRECTLY 0x00
154#define LOADCELL5_STATUS_PAT_ADC_PERFORMED_CORRECTLY 0x01
155#define LOADCELL5_STATUS_GAIN_128 0x00
156#define LOADCELL5_STATUS_GAIN_1 0x04
157#define LOADCELL5_STATUS_BITS_ID_0 0x08
158#define LOADCELL5_STATUS_BITS_ID_1 0x10
159#define LOADCELL5_STATUS_ERROR 0x20
160#define LOADCELL5_STATUS_FILTER_UPDATE_RATE_16_7_HZ 0x00
161#define LOADCELL5_STATUS_FILTER_UPDATE_RATE_10_HZ 0x40
162#define LOADCELL5_STATUS_CONVERSION_NOT_AVAILABLE 0x80
163#define LOADCELL5_STATUS_CONVERSION_IS_AVAILABLE 0x00
164#define LOADCELL5_STATUS_CONVERSION_NOT_AVAILABLE 0x80
165
171#define LOADCELL5_DATA_NO_DATA 0
172#define LOADCELL5_DATA_OK 1
173
174 // status
175
176
177 // loadcell5_get
178
193#define LOADCELL5_WEIGHT_ZERO 0
194#define LOADCELL5_WEIGHT_100G 100
195#define LOADCELL5_WEIGHT_500G 500
196#define LOADCELL5_WEIGHT_1000G 1000
197#define LOADCELL5_WEIGHT_5000G 5000
198#define LOADCELL5_WEIGHT_10000G 10000
199
200 // weight
201
212#define LOADCELL5_STATUS_PAT_ADC_PERFORMED_NOT_CORRECTLY 0x00
213#define LOADCELL5_STATUS_PAT_ADC_PERFORMED_CORRECTLY 0x01
214#define LOADCELL5_STATUS_GAIN_128 0x00
215#define LOADCELL5_STATUS_GAIN_1 0x04
216#define LOADCELL5_STATUS_BITS_ID_0 0x08
217#define LOADCELL5_STATUS_BITS_ID_1 0x10
218#define LOADCELL5_STATUS_ERROR 0x20
219#define LOADCELL5_STATUS_FILTER_UPDATE_RATE_16_7_HZ 0x00
220#define LOADCELL5_STATUS_FILTER_UPDATE_RATE_10_HZ 0x40
221#define LOADCELL5_STATUS_CONVERSION_NOT_AVAILABLE 0x80
222#define LOADCELL5_STATUS_CONVERSION_IS_AVAILABLE 0x00
223#define LOADCELL5_STATUS_CONVERSION_NOT_AVAILABLE 0x80
224
225 // status
226
227
228 // loadcell5_cfg_data
229
244#define LOADCELL5_MAP_MIKROBUS( cfg, mikrobus ) \
245 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
246 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
247 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
248 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
249 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
250 cfg.gn = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
251 cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT );
252
253 // loadcell5_map
254 // loadcell5
255
260typedef struct
261{
262 // Output pins
263
264 digital_out_t rst;
265 digital_out_t gn;
267 // Input pins
268
269 digital_in_t rdy;
271 // Modules
272
273 spi_master_t spi;
275 pin_name_t chip_select;
278
283typedef struct
284{
285 // Communication gpio pins
286
287 pin_name_t miso;
288 pin_name_t mosi;
289 pin_name_t sck;
290 pin_name_t cs;
292 // Additional gpio pins
293
294 pin_name_t rst;
295 pin_name_t gn;
296 pin_name_t rdy;
298 // static variable
299
300 uint32_t spi_speed;
301 spi_master_mode_t spi_mode;
302 spi_master_chip_select_polarity_t cs_polarity;
305
326
337
354
370
385
402err_t loadcell5_set_power_mode ( loadcell5_t *ctx, uint8_t pwr_mode );
403
415
432err_t loadcell5_filter_select ( loadcell5_t *ctx, uint8_t fil_sel );
433
450err_t loadcell5_set_gain ( loadcell5_t *ctx, uint8_t gain );
451
467err_t loadcell5_get_data ( loadcell5_t *ctx, uint8_t *status, uint32_t *adc_data );
468
481
495
517err_t loadcell5_calibration ( loadcell5_t *ctx, uint16_t cal_val, loadcell5_data_t *cell_data );
518
532
545
546#ifdef __cplusplus
547}
548#endif
549#endif // LOADCELL5_H
550
551 // loadcell5
552
553// ------------------------------------------------------------------------ END
void loadcell5_hw_reset(loadcell5_t *ctx)
Load Cell 5 set hardware reset function.
err_t loadcell5_calibration(loadcell5_t *ctx, uint16_t cal_val, loadcell5_data_t *cell_data)
Load Cell 5 calibration function.
err_t loadcell5_get_data(loadcell5_t *ctx, uint8_t *status, uint32_t *adc_data)
Load Cell 5 data reading function.
void loadcell5_cfg_setup(loadcell5_cfg_t *cfg)
Load Cell 5 configuration object setup function.
err_t loadcell5_default_cfg(loadcell5_t *ctx)
Load Cell 5 default configuration function.
err_t loadcell5_set_gain(loadcell5_t *ctx, uint8_t gain)
Load Cell 5 set gain function.
err_t loadcell5_set_power_mode(loadcell5_t *ctx, uint8_t pwr_mode)
Load Cell 5 set power mode function.
void loadcell5_tare(loadcell5_t *ctx, loadcell5_data_t *cell_data)
Load Cell 5 tare the scales function.
uint8_t loadcell5_check_data_ready(loadcell5_t *ctx)
Load Cell 5 get error function.
err_t loadcell5_filter_select(loadcell5_t *ctx, uint8_t fil_sel)
Load Cell 5 filter select function.
float loadcell5_get_weight(loadcell5_t *ctx, loadcell5_data_t *cell_data)
Load Cell 5 get weight function.
uint32_t loadcell5_read_adc(loadcell5_t *ctx)
Load Cell 5 reading ADC data function.
err_t loadcell5_init(loadcell5_t *ctx, loadcell5_cfg_t *cfg)
Load Cell 5 initialization function.
loadcell5_return_value_t
Load Cell 5 Click return value data.
Definition loadcell5.h:332
@ LOADCELL5_OK
Definition loadcell5.h:333
@ LOADCELL5_ERROR
Definition loadcell5.h:334
Load Cell 5 Click configuration object.
Definition loadcell5.h:284
spi_master_chip_select_polarity_t cs_polarity
Definition loadcell5.h:302
pin_name_t sck
Definition loadcell5.h:289
spi_master_mode_t spi_mode
Definition loadcell5.h:301
pin_name_t mosi
Definition loadcell5.h:288
uint32_t spi_speed
Definition loadcell5.h:300
pin_name_t rdy
Definition loadcell5.h:296
pin_name_t miso
Definition loadcell5.h:287
pin_name_t gn
Definition loadcell5.h:295
pin_name_t rst
Definition loadcell5.h:294
pin_name_t cs
Definition loadcell5.h:290
Load Cell 5 Click data structure definition.
Definition loadcell5.h:311
float tare
Definition loadcell5.h:312
float weight_coeff_10000g
Definition loadcell5.h:322
uint8_t weight_data_1000g_ok
Definition loadcell5.h:319
uint8_t weight_data_500g_ok
Definition loadcell5.h:317
float weight_coeff_100g
Definition loadcell5.h:314
float weight_coeff_5000g
Definition loadcell5.h:320
uint8_t weight_data_10000g_ok
Definition loadcell5.h:323
float weight_coeff_500g
Definition loadcell5.h:316
uint8_t weight_data_5000g_ok
Definition loadcell5.h:321
uint8_t tare_ok
Definition loadcell5.h:313
uint8_t weight_data_100g_ok
Definition loadcell5.h:315
float weight_coeff_1000g
Definition loadcell5.h:318
Load Cell 5 Click context object.
Definition loadcell5.h:261
spi_master_t spi
Definition loadcell5.h:273
digital_out_t gn
Definition loadcell5.h:265
digital_out_t rst
Definition loadcell5.h:264
pin_name_t chip_select
Definition loadcell5.h:275
digital_in_t rdy
Definition loadcell5.h:269