thermo18  2.0.0.0
thermo18.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 THERMO18_H
29 #define THERMO18_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define THERMO18_REG_DEVICE_ID 0x1
70 #define THERMO18_REG_T_H_LIMIT 0x2
71 #define THERMO18_REG_T_L_LIMIT 0x3
72 #define THERMO18_REG_CTRL 0x4
73 #define THERMO18_REG_STATUS 0x5
74 #define THERMO18_REG_DATA_T_L 0x6
75 #define THERMO18_REG_DATA_T_H 0x7
76 #define THERMO18_REG_SOFT_RESET 0xC
77  // thermo18_reg
79 
94 #define THERMO18_CONTROL_ONESHOT_ENABLED 0x01
95 #define THERMO18_CONTROL_CONTINOUS_ENABLED 0x04
96 
101 #define THERMO18_STATUS_DATA_READY 0x00
102 #define THERMO18_STATUS_DATA_BUSY 0x01
103 #define THERMO18_STATUS_OVERTEMPERATURE 0x02
104 #define THERMO18_STATUS_UNDERTEMPERATURE 0x04
105 
110 #define THERMO18_DEVICE_ID 0xA0
111 
117 #define THERMO18_SET_DEV_ADDR 0x3F
118  // thermo18_set
120 
135 #define THERMO18_MAP_MIKROBUS( cfg, mikrobus ) \
136  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
137  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
138  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
139  // thermo18_map // thermo18
142 
147 typedef struct
148 {
149  // Input pins
150  digital_in_t int_pin;
152  // Modules
153  i2c_master_t i2c;
155  // I2C slave address
156  uint8_t slave_address;
158 } thermo18_t;
159 
164 typedef struct
165 {
166  pin_name_t scl;
167  pin_name_t sda;
169  pin_name_t int_pin;
171  uint32_t i2c_speed;
172  uint8_t i2c_address;
175 
180 typedef enum
181 {
183  THERMO18_ERROR = -1
184 
186 
203 
218 
233 
246 err_t thermo18_generic_write ( thermo18_t *ctx, uint8_t reg, uint8_t tx_data ) ;
247 
260 err_t thermo18_generic_read ( thermo18_t *ctx, uint8_t reg, uint8_t *rx_data );
261 
274 err_t thermo18_read_temperature ( thermo18_t *ctx, float *temperature );
275 
286 err_t thermo18_reset ( thermo18_t *ctx );
287 
296 
311 err_t thermo18_set_temperature_threshold ( thermo18_t *ctx, uint8_t threshold_reg, float threshold_limit );
312 
313 #ifdef __cplusplus
314 }
315 #endif
316 #endif // THERMO18_H
317  // thermo18
319 
320 // ------------------------------------------------------------------------ END
thermo18_cfg_t::int_pin
pin_name_t int_pin
Definition: thermo18.h:169
thermo18_generic_write
err_t thermo18_generic_write(thermo18_t *ctx, uint8_t reg, uint8_t tx_data)
Thermo 18 I2C writing function.
thermo18_cfg_t::i2c_address
uint8_t i2c_address
Definition: thermo18.h:172
thermo18_default_cfg
err_t thermo18_default_cfg(thermo18_t *ctx)
Thermo 18 default configuration function.
thermo18_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: thermo18.h:171
THERMO18_ERROR
@ THERMO18_ERROR
Definition: thermo18.h:183
thermo18_read_temperature
err_t thermo18_read_temperature(thermo18_t *ctx, float *temperature)
Reads and calculates temperature value.
thermo18_t
Thermo 18 Click context object.
Definition: thermo18.h:148
thermo18_t::i2c
i2c_master_t i2c
Definition: thermo18.h:153
thermo18_get_interrupt
uint8_t thermo18_get_interrupt(thermo18_t *ctx)
Get interrput status.
thermo18_t::slave_address
uint8_t slave_address
Definition: thermo18.h:156
thermo18_cfg_t::scl
pin_name_t scl
Definition: thermo18.h:166
thermo18_cfg_setup
void thermo18_cfg_setup(thermo18_cfg_t *cfg)
Thermo 18 configuration object setup function.
thermo18_cfg_t
Thermo 18 Click configuration object.
Definition: thermo18.h:165
THERMO18_OK
@ THERMO18_OK
Definition: thermo18.h:182
thermo18_cfg_t::sda
pin_name_t sda
Definition: thermo18.h:167
thermo18_t::int_pin
digital_in_t int_pin
Definition: thermo18.h:150
thermo18_return_value_t
thermo18_return_value_t
Thermo 18 Click return value data.
Definition: thermo18.h:181
thermo18_generic_read
err_t thermo18_generic_read(thermo18_t *ctx, uint8_t reg, uint8_t *rx_data)
Thermo 18 I2C reading function.
thermo18_reset
err_t thermo18_reset(thermo18_t *ctx)
Resets device.
thermo18_set_temperature_threshold
err_t thermo18_set_temperature_threshold(thermo18_t *ctx, uint8_t threshold_reg, float threshold_limit)
Sets temperature threshold.
thermo18_init
err_t thermo18_init(thermo18_t *ctx, thermo18_cfg_t *cfg)
Thermo 18 initialization function.