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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 
40 /* REGISTERS */
41 
42 
43 
44 /* CMD BITS */
45 
46 
47 
48 
49 
50 
71 #define LOADCELL6_REG_STAT 0x00
72 #define LOADCELL6_REG_CTRL1 0x01
73 #define LOADCELL6_REG_CTRL2 0x02
74 #define LOADCELL6_REG_CTRL3 0x03
75 #define LOADCELL6_REG_CTRL4 0x04
76 #define LOADCELL6_REG_CTRL5 0x05
77 #define LOADCELL6_REG_DATA 0x06
78 #define LOADCELL6_REG_SOC_SPI 0x07
79 #define LOADCELL6_REG_SCG_SPI 0x08
80 #define LOADCELL6_REG_SCOC_SPI 0x09
81 #define LOADCELL6_REG_SCGC_SPI 0x0A
82 #define LOADCELL6_REG_RAM 0x0C
83 #define LOADCELL6_REG_SYNC_SPI 0x0D
84 #define LOADCELL6_REG_SOC_ADC 0x15
85 #define LOADCELL6_REG_SCG_ADC 0x16
86 #define LOADCELL6_REG_SCOC_ADC 0x17
87 #define LOADCELL6_REG_SCGC_ADC 0x18
88  // loadcell6_reg
90 
110 #define LOADCELL6_CMD_RATE0 0x01
111 #define LOADCELL6_CMD_RATE1 0x02
112 #define LOADCELL6_CMD_RATE2 0x04
113 #define LOADCELL6_CMD_RATE3 0x08
114 #define LOADCELL6_CMD_IMPD 0x10
115 #define LOADCELL6_CMD_CAL 0x20
116 #define LOADCELL6_CMD_START 0x80
117 #define LOADCELL6_CMD_REG_ACCESS_MODE 0x40
118 
123 #define LOADCELL6_STAT_RDY 0x0001
124 #define LOADCELL6_STAT_MSTAT 0x0002
125 #define LOADCELL6_STAT_DOR 0x0004
126 #define LOADCELL6_STAT_SYSGOR 0x0008
127 #define LOADCELL6_STAT_RATE0 0x0010
128 #define LOADCELL6_STAT_RATE1 0x0020
129 #define LOADCELL6_STAT_RATE2 0x0040
130 #define LOADCELL6_STAT_RATE3 0x0080
131 #define LOADCELL6_STAT_AOR 0x0100
132 #define LOADCELL6_STAT_RDERR 0x0200
133 #define LOADCELL6_STAT_PDSTAT0 0x0400
134 #define LOADCELL6_STAT_PDSTAT1 0x0800
135 #define LOADCELL6_STAT_ERROR 0x4000
136 #define LOADCELL6_STAT_INRESET 0x8000
137 
142 #define LOADCELL6_CTRL1_CONTSC 0x01
143 #define LOADCELL6_CTRL1_SCYCLE 0x02
144 #define LOADCELL6_CTRL1_FORMAT 0x04
145 #define LOADCELL6_CTRL1_U_B 0x08
146 #define LOADCELL6_CTRL1_PD0 0x10
147 #define LOADCELL6_CTRL1_PD1 0x20
148 #define LOADCELL6_CTRL1_SYNC 0x40
149 #define LOADCELL6_CTRL1_EXTCK 0x80
150 
155 #define LOADCELL6_CTRL2_PGAIN_x1 0x00
156 #define LOADCELL6_CTRL2_PGAIN_x2 0x01
157 #define LOADCELL6_CTRL2_PGAIN_x4 0x02
158 #define LOADCELL6_CTRL2_PGAIN_x8 0x03
159 #define LOADCELL6_CTRL2_PGAIN_x16 0x04
160 #define LOADCELL6_CTRL2_PGAIN_x32 0x05
161 #define LOADCELL6_CTRL2_PGAIN_x64 0x06
162 #define LOADCELL6_CTRL2_PGAIN_x128 0x07
163 #define LOADCELL6_CTRL2_PGAGEN 0x08
164 #define LOADCELL6_CTRL2_LPMODE 0x10
165 #define LOADCELL6_CTRL2_BUFEN 0x20
166 #define LOADCELL6_CTRL2_DGAIN_x1 0x00
167 #define LOADCELL6_CTRL2_DGAIN_x2 0x40
168 #define LOADCELL6_CTRL2_DGAIN_x4 0x80
169 #define LOADCELL6_CTRL2_DGAIN_x8 0xC0
170 #define LOADCELL6_CTRL2_DGAIN0 0x40
171 #define LOADCELL6_CTRL2_DGAIN1 0x80
172 
177 #define LOADCELL6_CTRL3_DATA32 0x08
178 #define LOADCELL6_CTRL3_MODBITS 0x10
179 #define LOADCELL6_CTRL3_ENMSYNC 0x20
180 #define LOADCELL6_CTRL3_RESERVED 0x41
181 
186 #define LOADCELL6_CTRL4_DIO1 0x01
187 #define LOADCELL6_CTRL4_DIO2 0x02
188 #define LOADCELL6_CTRL4_DIO3 0x04
189 #define LOADCELL6_CTRL4_DIO4 0x08
190 #define LOADCELL6_CTRL4_DIR1 0x10
191 #define LOADCELL6_CTRL4_DIR2 0x20
192 #define LOADCELL6_CTRL4_DIR3 0x40
193 #define LOADCELL6_CTRL4_DIR4 0x80
194 
199 #define LOADCELL6_CTRL5_NOSCO 0x01
200 #define LOADCELL6_CTRL5_NOSCG 0x02
201 #define LOADCELL6_CTRL5_NOSYSO 0x04
202 #define LOADCELL6_CTRL5_NOSYSG 0x08
203 #define LOADCELL6_CTRL5_CAL0 0x40
204 #define LOADCELL6_CTRL5_CAL1 0x80
205 
206 
211 #define LOADCELL6_DATA_NO_DATA 0
212 #define LOADCELL6_DATA_OK 1
213 #define LOADCELL6_WEIGHT_ZERO 0
214 #define LOADCELL6_WEIGHT_100G 100
215 #define LOADCELL6_WEIGHT_200G 200
216 #define LOADCELL6_WEIGHT_500G 500
217 #define LOADCELL6_WEIGHT_1000G 1000
218 #define LOADCELL6_WEIGHT_5000G 5000
219 #define LOADCELL6_WEIGHT_10000G 10000
220 
229 #define LOADCELL6_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
230 #define LOADCELL6_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
231  // loadcell6_set
233 
248 #define LOADCELL6_MAP_MIKROBUS( cfg, mikrobus ) \
249  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
250  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
251  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
252  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
253  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
254  cfg.syn = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
255  cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
256  // loadcell6_map // loadcell6
259 
264 typedef struct
265 {
266  // Output pins
267  digital_out_t rst;
269  // Input pins
270  digital_in_t syn;
271  digital_in_t rdy;
273  // Modules
274  spi_master_t spi;
276  pin_name_t chip_select;
278 } loadcell6_t;
279 
284 typedef struct
285 {
286  // Communication gpio pins
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  pin_name_t rst;
294  pin_name_t syn;
295  pin_name_t rdy;
297  // static variable
298  uint32_t spi_speed;
299  spi_master_mode_t spi_mode;
300  spi_master_chip_select_polarity_t cs_polarity;
303 
308 typedef struct
309 {
310  float tare;
311  uint8_t tare_ok;
324 }
326 
331 typedef enum
332 {
334  LOADCELL6_ERROR = -1
335 
337 
354 
370 
385 
401 err_t loadcell6_generic_write ( loadcell6_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
402 
418 err_t loadcell6_generic_read ( loadcell6_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
419 
434 
447 uint8_t loadcell6_sync ( loadcell6_t *ctx );
448 
462 
476 err_t loadcell6_write_reg ( loadcell6_t *ctx, uint8_t reg, uint8_t data_in );
477 
493 err_t loadcell6_read_reg ( loadcell6_t *ctx, uint8_t reg, uint8_t *data_out );
494 
510 err_t loadcell6_write_reg_data ( loadcell6_t *ctx, uint8_t reg, uint32_t data_in );
511 
527 err_t loadcell6_read_reg_data ( loadcell6_t *ctx, uint8_t reg, uint32_t *data_out );
528 
543 err_t loadcell6_set_command ( loadcell6_t *ctx, uint8_t cmd );
544 
559 err_t loadcell6_get_status ( loadcell6_t *ctx, uint16_t *status );
560 
575 err_t loadcell6_read_adc ( loadcell6_t *ctx, uint32_t *data_out );
576 
591 err_t loadcell6_tare ( loadcell6_t *ctx, loadcell6_data_t *cell_data );
592 
614 err_t loadcell6_calibration ( loadcell6_t *ctx, uint16_t cal_val, loadcell6_data_t *cell_data );
615 
631 err_t loadcell6_get_weight ( loadcell6_t *ctx, loadcell6_data_t *cell_data, float *weight_g );
632 
633 #ifdef __cplusplus
634 }
635 #endif
636 #endif // LOADCELL6_H
637  // loadcell6
639 
640 // ------------------------------------------------------------------------ END
loadcell6_get_status
err_t loadcell6_get_status(loadcell6_t *ctx, uint16_t *status)
Load Cell 6 get status function.
loadcell6_cfg_t::cs
pin_name_t cs
Definition: loadcell6.h:290
loadcell6_data_t::weight_coeff_10000g
float weight_coeff_10000g
Definition: loadcell6.h:322
loadcell6_generic_write
err_t loadcell6_generic_write(loadcell6_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Load Cell 6 data writing function.
loadcell6_check_data_ready
uint8_t loadcell6_check_data_ready(loadcell6_t *ctx)
Load Cell 6 check data ready function.
loadcell6_data_t
Load Cell 6 Click load cell data object.
Definition: loadcell6.h:309
spi_specifics.h
This file contains SPI specific macros, functions, etc.
loadcell6_read_reg
err_t loadcell6_read_reg(loadcell6_t *ctx, uint8_t reg, uint8_t *data_out)
Load Cell 6 read reg function.
loadcell6_t
Load Cell 6 Click context object.
Definition: loadcell6.h:265
loadcell6_t::syn
digital_in_t syn
Definition: loadcell6.h:270
loadcell6_cfg_t::miso
pin_name_t miso
Definition: loadcell6.h:287
loadcell6_data_t::weight_data_5000g_ok
uint8_t weight_data_5000g_ok
Definition: loadcell6.h:321
loadcell6_generic_read
err_t loadcell6_generic_read(loadcell6_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Load Cell 6 data reading function.
loadcell6_cfg_t::rst
pin_name_t rst
Definition: loadcell6.h:293
loadcell6_tare
err_t loadcell6_tare(loadcell6_t *ctx, loadcell6_data_t *cell_data)
Load Cell 6 tare the scales function.
loadcell6_data_t::weight_coeff_5000g
float weight_coeff_5000g
Definition: loadcell6.h:320
loadcell6_write_reg_data
err_t loadcell6_write_reg_data(loadcell6_t *ctx, uint8_t reg, uint32_t data_in)
Load Cell 6 read reg data function.
loadcell6_return_value_t
loadcell6_return_value_t
Load Cell 6 Click return value data.
Definition: loadcell6.h:332
loadcell6_data_t::weight_coeff_100g
float weight_coeff_100g
Definition: loadcell6.h:312
loadcell6_hw_reset
err_t loadcell6_hw_reset(loadcell6_t *ctx)
Load Cell 6 hw reset function.
LOADCELL6_ERROR
@ LOADCELL6_ERROR
Definition: loadcell6.h:334
loadcell6_t::spi
spi_master_t spi
Definition: loadcell6.h:274
loadcell6_sync
uint8_t loadcell6_sync(loadcell6_t *ctx)
Load Cell 6 get sync function.
loadcell6_data_t::weight_coeff_500g
float weight_coeff_500g
Definition: loadcell6.h:316
loadcell6_cfg_t::spi_speed
uint32_t spi_speed
Definition: loadcell6.h:298
loadcell6_t::rdy
digital_in_t rdy
Definition: loadcell6.h:271
loadcell6_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: loadcell6.h:299
loadcell6_data_t::weight_coeff_1000g
float weight_coeff_1000g
Definition: loadcell6.h:318
LOADCELL6_OK
@ LOADCELL6_OK
Definition: loadcell6.h:333
loadcell6_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: loadcell6.h:300
loadcell6_data_t::weight_data_500g_ok
uint8_t weight_data_500g_ok
Definition: loadcell6.h:317
loadcell6_default_cfg
err_t loadcell6_default_cfg(loadcell6_t *ctx)
Load Cell 6 default configuration function.
loadcell6_cfg_setup
void loadcell6_cfg_setup(loadcell6_cfg_t *cfg)
Load Cell 6 configuration object setup function.
loadcell6_t::chip_select
pin_name_t chip_select
Definition: loadcell6.h:276
loadcell6_init
err_t loadcell6_init(loadcell6_t *ctx, loadcell6_cfg_t *cfg)
Load Cell 6 initialization function.
loadcell6_data_t::weight_data_1000g_ok
uint8_t weight_data_1000g_ok
Definition: loadcell6.h:319
loadcell6_cfg_t::mosi
pin_name_t mosi
Definition: loadcell6.h:288
loadcell6_get_weight
err_t loadcell6_get_weight(loadcell6_t *ctx, loadcell6_data_t *cell_data, float *weight_g)
Load Cell 6 get weight function.
loadcell6_data_t::weight_coeff_200g
float weight_coeff_200g
Definition: loadcell6.h:314
loadcell6_data_t::weight_data_100g_ok
uint8_t weight_data_100g_ok
Definition: loadcell6.h:313
loadcell6_t::rst
digital_out_t rst
Definition: loadcell6.h:267
loadcell6_cfg_t::rdy
pin_name_t rdy
Definition: loadcell6.h:295
loadcell6_write_reg
err_t loadcell6_write_reg(loadcell6_t *ctx, uint8_t reg, uint8_t data_in)
Load Cell 6 write reg function.
loadcell6_cfg_t::syn
pin_name_t syn
Definition: loadcell6.h:294
loadcell6_calibration
err_t loadcell6_calibration(loadcell6_t *ctx, uint16_t cal_val, loadcell6_data_t *cell_data)
Load Cell 6 calibration function.
loadcell6_data_t::tare
float tare
Definition: loadcell6.h:310
loadcell6_cfg_t::sck
pin_name_t sck
Definition: loadcell6.h:289
loadcell6_set_command
err_t loadcell6_set_command(loadcell6_t *ctx, uint8_t cmd)
Load Cell 6 set command function.
loadcell6_data_t::tare_ok
uint8_t tare_ok
Definition: loadcell6.h:311
loadcell6_data_t::weight_data_10000g_ok
uint8_t weight_data_10000g_ok
Definition: loadcell6.h:323
loadcell6_read_adc
err_t loadcell6_read_adc(loadcell6_t *ctx, uint32_t *data_out)
Load Cell 6 read ADC data function.
loadcell6_data_t::weight_data_200g_ok
uint8_t weight_data_200g_ok
Definition: loadcell6.h:315
loadcell6_read_reg_data
err_t loadcell6_read_reg_data(loadcell6_t *ctx, uint8_t reg, uint32_t *data_out)
Load Cell 6 read reg data function.
loadcell6_cfg_t
Load Cell 6 Click configuration object.
Definition: loadcell6.h:285