thermo28 2.1.0.0
thermo28.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 THERMO28_H
29#define THERMO28_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_in.h"
50#include "drv_i2c_master.h"
51
72#define THERMO28_REG_TVAL 0x00
73#define THERMO28_REG_CONFIG 0x01
74#define THERMO28_REG_TLOW 0x02
75#define THERMO28_REG_THIGH 0x03
76
77 // thermo28_reg
78
93#define THERMO28_CFG_DEFAULT_CONFIG 0x40A0
94#define THERMO28_CFG_SINGLE_SHOT 0x8000
95#define THERMO28_CONV_RATE_BIT_MASK 0x00C0
96#define THERMO28_STATE_BIT_MASK 0x0100
97#define THERMO28_CONSEC_FAULTS_BIT_MASK 0x3000
98#define THERMO28_ALERT_BIT_MASK 0x0200
99#define THERMO28_SINGLE_SHOT_BIT_MASK 0x8000
100
106#define THERMO28_DEVICE_ADDRESS_VSS 0x48
107#define THERMO28_DEVICE_ADDRESS_VDD 0x49
108#define THERMO28_DEVICE_ADDRESS_SDA 0x4A
109#define THERMO28_DEVICE_ADDRESS_SCL 0x4B
110
111 // thermo28_set
112
127#define THERMO28_MAP_MIKROBUS( cfg, mikrobus ) \
128 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
129 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
130 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
131
132 // thermo28_map
133 // thermo28
134
139typedef enum
140{
142 THERMO28_ERROR = -1
143
145
158
163typedef enum
164{
166 THERMO28_STATE_ACTIVE = 0x0000
167
169
180
181
192
205
216
221typedef struct
222{
223 // Input pins
224 digital_in_t int_pin;
226 // Modules
227 i2c_master_t i2c;
229 // I2C slave address
232} thermo28_t;
233
238typedef struct
239{
240 pin_name_t scl;
241 pin_name_t sda;
243 pin_name_t int_pin;
245 uint32_t i2c_speed;
246 uint8_t i2c_address;
249
264
281
296
310
325err_t thermo28_generic_write ( thermo28_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
326
341err_t thermo28_generic_read ( thermo28_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
342
354err_t thermo28_get_temperature ( thermo28_t *ctx, float *temperature );
355
368err_t thermo28_set_alert_limits ( thermo28_t *ctx, float alert_min, float alert_max );
369
383
396
409
422
434
435#ifdef __cplusplus
436}
437#endif
438#endif // THERMO28_H
439
440 // thermo28
441
442// ------------------------------------------------------------------------ END
err_t thermo28_set_sleep_mode(thermo28_t *ctx)
Thermo 28 set device working mode function.
err_t thermo28_generic_read(thermo28_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Thermo 28 I2C reading function.
uint8_t thermo28_get_int_pin(thermo28_t *ctx)
Thermo 28 set alert status function.
err_t thermo28_set_continuous_conversion(thermo28_t *ctx)
Thermo 28 set continuous conversion function.
err_t thermo28_init(thermo28_t *ctx, thermo28_cfg_t *cfg)
Thermo 28 initialization function.
err_t thermo28_generic_write(thermo28_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Thermo 28 I2C writing function.
err_t thermo28_set_alert_limits(thermo28_t *ctx, float alert_min, float alert_max)
Thermo 28 set alert limits function.
err_t thermo28_set_config(thermo28_t *ctx, thermo28_config_t config)
Thermo 28 set configuration function.
err_t thermo28_get_temperature(thermo28_t *ctx, float *temperature)
Thermo 28 get temperature function.
void thermo28_cfg_setup(thermo28_cfg_t *cfg)
Thermo 28 configuration object setup function.
err_t thermo28_default_cfg(thermo28_t *ctx)
Thermo 28 default configuration function.
err_t thermo28_set_trigger_single_shot(thermo28_t *ctx)
Thermo 28 set trigger single-shot function.
Thermo 28 Click configuration object.
Definition thermo28.h:239
uint32_t i2c_speed
Definition thermo28.h:245
pin_name_t scl
Definition thermo28.h:240
pin_name_t int_pin
Definition thermo28.h:243
pin_name_t sda
Definition thermo28.h:241
uint8_t i2c_address
Definition thermo28.h:246
Thermo 28 Click configuration object.
Definition thermo28.h:255
thermo28_conv_rate_t conv_rate
Definition thermo28.h:256
thermo28_device_mode_t device_mode
Definition thermo28.h:257
thermo28_alert_mode_t alert_mode
Definition thermo28.h:258
thermo28_single_shot_t single_shot
Definition thermo28.h:261
thermo28_alert_polarity_t alert_polarity
Definition thermo28.h:259
thermo28_consec_faults_t consecutive_faults
Definition thermo28.h:260
Thermo 28 Click context object.
Definition thermo28.h:222
digital_in_t int_pin
Definition thermo28.h:224
i2c_master_t i2c
Definition thermo28.h:227
uint8_t slave_address
Definition thermo28.h:230
thermo28_alert_mode_t
Thermo 28 Click interrupt mode value data.
Definition thermo28.h:175
@ THERMO28_ALERT_COMPARATOR
Definition thermo28.h:177
@ THERMO28_ALERT_INTERRUPT
Definition thermo28.h:176
thermo28_device_mode_t
Thermo 28 Click sleep mode value data.
Definition thermo28.h:164
@ THERMO28_STATE_ACTIVE
Definition thermo28.h:166
@ THERMO28_STATE_SLEEP
Definition thermo28.h:165
thermo28_conv_rate_t
Thermo 28 Click conversion rate value data.
Definition thermo28.h:151
@ THERMO28_CONV_RATE8
Definition thermo28.h:155
@ THERMO28_CONV_RATE025
Definition thermo28.h:152
@ THERMO28_CONV_RATE4
Definition thermo28.h:154
@ THERMO28_CONV_RATE1
Definition thermo28.h:153
thermo28_single_shot_t
Thermo 28 Click measurement mode value data.
Definition thermo28.h:211
@ THERMO28_SINGLE_SHOT_NO_CONVERSION
Definition thermo28.h:212
@ THERMO28_SINGLE_SHOT_START_CONVERSION
Definition thermo28.h:213
thermo28_consec_faults_t
Thermo 28 Click consecutive faults value data.
Definition thermo28.h:198
@ THERMO28_CONSEC_FAULTS1
Definition thermo28.h:199
@ THERMO28_CONSEC_FAULTS2
Definition thermo28.h:200
@ THERMO28_CONSEC_FAULTS4
Definition thermo28.h:202
@ THERMO28_CONSEC_FAULTS3
Definition thermo28.h:201
thermo28_alert_polarity_t
Thermo 28 Click polarity of the alert output value data.
Definition thermo28.h:187
@ THERMO28_ALERT_ACTIVE_HIGH
Definition thermo28.h:189
@ THERMO28_ALERT_ACTIVE_LOW
Definition thermo28.h:188
thermo28_return_value_t
Thermo 28 Click return value data.
Definition thermo28.h:140
@ THERMO28_ERROR
Definition thermo28.h:142
@ THERMO28_OK
Definition thermo28.h:141