loadcell6 2.0.0.0
loadcell6.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 LOADCELL6_H
29#define LOADCELL6_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#include "spi_specifics.h"
53
54/* REGISTERS */
55
56
57
58/* CMD BITS */
59
60
61
62
63
64
85#define LOADCELL6_REG_STAT 0x00
86#define LOADCELL6_REG_CTRL1 0x01
87#define LOADCELL6_REG_CTRL2 0x02
88#define LOADCELL6_REG_CTRL3 0x03
89#define LOADCELL6_REG_CTRL4 0x04
90#define LOADCELL6_REG_CTRL5 0x05
91#define LOADCELL6_REG_DATA 0x06
92#define LOADCELL6_REG_SOC_SPI 0x07
93#define LOADCELL6_REG_SCG_SPI 0x08
94#define LOADCELL6_REG_SCOC_SPI 0x09
95#define LOADCELL6_REG_SCGC_SPI 0x0A
96#define LOADCELL6_REG_RAM 0x0C
97#define LOADCELL6_REG_SYNC_SPI 0x0D
98#define LOADCELL6_REG_SOC_ADC 0x15
99#define LOADCELL6_REG_SCG_ADC 0x16
100#define LOADCELL6_REG_SCOC_ADC 0x17
101#define LOADCELL6_REG_SCGC_ADC 0x18
102
103 // loadcell6_reg
104
124#define LOADCELL6_CMD_RATE0 0x01
125#define LOADCELL6_CMD_RATE1 0x02
126#define LOADCELL6_CMD_RATE2 0x04
127#define LOADCELL6_CMD_RATE3 0x08
128#define LOADCELL6_CMD_IMPD 0x10
129#define LOADCELL6_CMD_CAL 0x20
130#define LOADCELL6_CMD_START 0x80
131#define LOADCELL6_CMD_REG_ACCESS_MODE 0x40
132
137#define LOADCELL6_STAT_RDY 0x0001
138#define LOADCELL6_STAT_MSTAT 0x0002
139#define LOADCELL6_STAT_DOR 0x0004
140#define LOADCELL6_STAT_SYSGOR 0x0008
141#define LOADCELL6_STAT_RATE0 0x0010
142#define LOADCELL6_STAT_RATE1 0x0020
143#define LOADCELL6_STAT_RATE2 0x0040
144#define LOADCELL6_STAT_RATE3 0x0080
145#define LOADCELL6_STAT_AOR 0x0100
146#define LOADCELL6_STAT_RDERR 0x0200
147#define LOADCELL6_STAT_PDSTAT0 0x0400
148#define LOADCELL6_STAT_PDSTAT1 0x0800
149#define LOADCELL6_STAT_ERROR 0x4000
150#define LOADCELL6_STAT_INRESET 0x8000
151
156#define LOADCELL6_CTRL1_CONTSC 0x01
157#define LOADCELL6_CTRL1_SCYCLE 0x02
158#define LOADCELL6_CTRL1_FORMAT 0x04
159#define LOADCELL6_CTRL1_U_B 0x08
160#define LOADCELL6_CTRL1_PD0 0x10
161#define LOADCELL6_CTRL1_PD1 0x20
162#define LOADCELL6_CTRL1_SYNC 0x40
163#define LOADCELL6_CTRL1_EXTCK 0x80
164
169#define LOADCELL6_CTRL2_PGAIN_x1 0x00
170#define LOADCELL6_CTRL2_PGAIN_x2 0x01
171#define LOADCELL6_CTRL2_PGAIN_x4 0x02
172#define LOADCELL6_CTRL2_PGAIN_x8 0x03
173#define LOADCELL6_CTRL2_PGAIN_x16 0x04
174#define LOADCELL6_CTRL2_PGAIN_x32 0x05
175#define LOADCELL6_CTRL2_PGAIN_x64 0x06
176#define LOADCELL6_CTRL2_PGAIN_x128 0x07
177#define LOADCELL6_CTRL2_PGAGEN 0x08
178#define LOADCELL6_CTRL2_LPMODE 0x10
179#define LOADCELL6_CTRL2_BUFEN 0x20
180#define LOADCELL6_CTRL2_DGAIN_x1 0x00
181#define LOADCELL6_CTRL2_DGAIN_x2 0x40
182#define LOADCELL6_CTRL2_DGAIN_x4 0x80
183#define LOADCELL6_CTRL2_DGAIN_x8 0xC0
184#define LOADCELL6_CTRL2_DGAIN0 0x40
185#define LOADCELL6_CTRL2_DGAIN1 0x80
186
191#define LOADCELL6_CTRL3_DATA32 0x08
192#define LOADCELL6_CTRL3_MODBITS 0x10
193#define LOADCELL6_CTRL3_ENMSYNC 0x20
194#define LOADCELL6_CTRL3_RESERVED 0x41
195
200#define LOADCELL6_CTRL4_DIO1 0x01
201#define LOADCELL6_CTRL4_DIO2 0x02
202#define LOADCELL6_CTRL4_DIO3 0x04
203#define LOADCELL6_CTRL4_DIO4 0x08
204#define LOADCELL6_CTRL4_DIR1 0x10
205#define LOADCELL6_CTRL4_DIR2 0x20
206#define LOADCELL6_CTRL4_DIR3 0x40
207#define LOADCELL6_CTRL4_DIR4 0x80
208
213#define LOADCELL6_CTRL5_NOSCO 0x01
214#define LOADCELL6_CTRL5_NOSCG 0x02
215#define LOADCELL6_CTRL5_NOSYSO 0x04
216#define LOADCELL6_CTRL5_NOSYSG 0x08
217#define LOADCELL6_CTRL5_CAL0 0x40
218#define LOADCELL6_CTRL5_CAL1 0x80
219
220
225#define LOADCELL6_DATA_NO_DATA 0
226#define LOADCELL6_DATA_OK 1
227#define LOADCELL6_WEIGHT_ZERO 0
228#define LOADCELL6_WEIGHT_100G 100
229#define LOADCELL6_WEIGHT_200G 200
230#define LOADCELL6_WEIGHT_500G 500
231#define LOADCELL6_WEIGHT_1000G 1000
232#define LOADCELL6_WEIGHT_5000G 5000
233#define LOADCELL6_WEIGHT_10000G 10000
234
243#define LOADCELL6_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
244#define LOADCELL6_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
245
246 // loadcell6_set
247
262#define LOADCELL6_MAP_MIKROBUS( cfg, mikrobus ) \
263 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
264 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
265 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
266 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
267 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
268 cfg.syn = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
269 cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
270
271 // loadcell6_map
272 // loadcell6
273
278typedef struct
279{
280 // Output pins
281 digital_out_t rst;
283 // Input pins
284 digital_in_t syn;
285 digital_in_t rdy;
287 // Modules
288 spi_master_t spi;
290 pin_name_t chip_select;
293
298typedef struct
299{
300 // Communication gpio pins
301 pin_name_t miso;
302 pin_name_t mosi;
303 pin_name_t sck;
304 pin_name_t cs;
306 // Additional gpio pins
307 pin_name_t rst;
308 pin_name_t syn;
309 pin_name_t rdy;
311 // static variable
312 uint32_t spi_speed;
313 spi_master_mode_t spi_mode;
314 spi_master_chip_select_polarity_t cs_polarity;
317
340
351
368
384
399
415err_t loadcell6_generic_write ( loadcell6_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
416
432err_t loadcell6_generic_read ( loadcell6_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
433
448
462
476
492err_t loadcell6_write_reg ( loadcell6_t *ctx, uint8_t reg, uint8_t data_in );
493
509err_t loadcell6_read_reg ( loadcell6_t *ctx, uint8_t reg, uint8_t *data_out );
510
526err_t loadcell6_write_reg_data ( loadcell6_t *ctx, uint8_t reg, uint32_t data_in );
527
543err_t loadcell6_read_reg_data ( loadcell6_t *ctx, uint8_t reg, uint32_t *data_out );
544
559err_t loadcell6_set_command ( loadcell6_t *ctx, uint8_t cmd );
560
575err_t loadcell6_get_status ( loadcell6_t *ctx, uint16_t *status );
576
591err_t loadcell6_read_adc ( loadcell6_t *ctx, uint32_t *data_out );
592
607err_t loadcell6_tare ( loadcell6_t *ctx, loadcell6_data_t *cell_data );
608
630err_t loadcell6_calibration ( loadcell6_t *ctx, uint16_t cal_val, loadcell6_data_t *cell_data );
631
647err_t loadcell6_get_weight ( loadcell6_t *ctx, loadcell6_data_t *cell_data, float *weight_g );
648
649#ifdef __cplusplus
650}
651#endif
652#endif // LOADCELL6_H
653
654 // loadcell6
655
656// ------------------------------------------------------------------------ END
err_t loadcell6_generic_write(loadcell6_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Load Cell 6 data writing function.
err_t loadcell6_init(loadcell6_t *ctx, loadcell6_cfg_t *cfg)
Load Cell 6 initialization function.
err_t loadcell6_write_reg_data(loadcell6_t *ctx, uint8_t reg, uint32_t data_in)
Load Cell 6 read reg data function.
void loadcell6_cfg_setup(loadcell6_cfg_t *cfg)
Load Cell 6 configuration object setup function.
err_t loadcell6_read_adc(loadcell6_t *ctx, uint32_t *data_out)
Load Cell 6 read ADC data function.
err_t loadcell6_hw_reset(loadcell6_t *ctx)
Load Cell 6 hw reset function.
err_t loadcell6_read_reg(loadcell6_t *ctx, uint8_t reg, uint8_t *data_out)
Load Cell 6 read reg function.
uint8_t loadcell6_check_data_ready(loadcell6_t *ctx)
Load Cell 6 check data ready function.
err_t loadcell6_default_cfg(loadcell6_t *ctx)
Load Cell 6 default configuration function.
err_t loadcell6_set_command(loadcell6_t *ctx, uint8_t cmd)
Load Cell 6 set command function.
err_t loadcell6_read_reg_data(loadcell6_t *ctx, uint8_t reg, uint32_t *data_out)
Load Cell 6 read reg data function.
err_t loadcell6_write_reg(loadcell6_t *ctx, uint8_t reg, uint8_t data_in)
Load Cell 6 write reg function.
err_t loadcell6_get_weight(loadcell6_t *ctx, loadcell6_data_t *cell_data, float *weight_g)
Load Cell 6 get weight function.
err_t loadcell6_tare(loadcell6_t *ctx, loadcell6_data_t *cell_data)
Load Cell 6 tare the scales function.
err_t loadcell6_generic_read(loadcell6_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Load Cell 6 data reading function.
uint8_t loadcell6_sync(loadcell6_t *ctx)
Load Cell 6 get sync function.
err_t loadcell6_get_status(loadcell6_t *ctx, uint16_t *status)
Load Cell 6 get status function.
err_t loadcell6_calibration(loadcell6_t *ctx, uint16_t cal_val, loadcell6_data_t *cell_data)
Load Cell 6 calibration function.
loadcell6_return_value_t
Load Cell 6 Click return value data.
Definition loadcell6.h:346
@ LOADCELL6_OK
Definition loadcell6.h:347
@ LOADCELL6_ERROR
Definition loadcell6.h:348
This file contains SPI specific macros, functions, etc.
Load Cell 6 Click configuration object.
Definition loadcell6.h:299
spi_master_chip_select_polarity_t cs_polarity
Definition loadcell6.h:314
pin_name_t sck
Definition loadcell6.h:303
spi_master_mode_t spi_mode
Definition loadcell6.h:313
pin_name_t mosi
Definition loadcell6.h:302
uint32_t spi_speed
Definition loadcell6.h:312
pin_name_t rdy
Definition loadcell6.h:309
pin_name_t miso
Definition loadcell6.h:301
pin_name_t rst
Definition loadcell6.h:307
pin_name_t syn
Definition loadcell6.h:308
pin_name_t cs
Definition loadcell6.h:304
Load Cell 6 Click load cell data object.
Definition loadcell6.h:323
uint8_t weight_data_200g_ok
Definition loadcell6.h:329
float tare
Definition loadcell6.h:324
float weight_coeff_10000g
Definition loadcell6.h:336
uint8_t weight_data_1000g_ok
Definition loadcell6.h:333
uint8_t weight_data_500g_ok
Definition loadcell6.h:331
float weight_coeff_100g
Definition loadcell6.h:326
float weight_coeff_5000g
Definition loadcell6.h:334
uint8_t weight_data_10000g_ok
Definition loadcell6.h:337
float weight_coeff_500g
Definition loadcell6.h:330
uint8_t weight_data_5000g_ok
Definition loadcell6.h:335
uint8_t tare_ok
Definition loadcell6.h:325
float weight_coeff_200g
Definition loadcell6.h:328
uint8_t weight_data_100g_ok
Definition loadcell6.h:327
float weight_coeff_1000g
Definition loadcell6.h:332
Load Cell 6 Click context object.
Definition loadcell6.h:279
spi_master_t spi
Definition loadcell6.h:288
digital_in_t syn
Definition loadcell6.h:284
digital_out_t rst
Definition loadcell6.h:281
pin_name_t chip_select
Definition loadcell6.h:290
digital_in_t rdy
Definition loadcell6.h:285