thermo17  2.0.0.0
thermo17.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef THERMO17_H
36 #define THERMO17_H
37 
38 #include "drv_digital_in.h"
39 #include "drv_i2c_master.h"
40 
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define THERMO17_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
56  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
57 
63 #define THERMO17_SLAVE_ADDRESS 0x4C
64 
70 #define THERMO17_REG_R_LOCAL_TEMP_HB 0x00
71 #define THERMO17_REG_R_REMOTE_TEMP_HB 0x01
72 #define THERMO17_REG_R_STATUS 0x02
73 #define THERMO17_REG_R_CFG 0x03
74 #define THERMO17_REG_R_CONVERSION_RATE 0x04
75 #define THERMO17_REG_R_LOCAL_TEMP_LIMIT_H 0x05
76 #define THERMO17_REG_R_LOCAL_TEMP_LIMIT_L 0x06
77 #define THERMO17_REG_R_REMOTE_TEMP_LIMIT_H_HB 0x07
78 #define THERMO17_REG_R_REMOTE_TEMP_LIMIT_L_HB 0x08
79 #define THERMO17_REG_R_REMOTE_TEMP_LB 0x10
80 #define THERMO17_REG_RW_REMOTE_TEMP_OFFSET_HB 0x11
81 #define THERMO17_REG_RW_REMOTE_TEMP_OFFSET_LB 0x12
82 #define THERMO17_REG_RW_REMOTE_TEMP_LIMIT_H_LB 0x13
83 #define THERMO17_REG_RW_REMOTE_TEMP_LIMIT_L_LB 0x14
84 #define THERMO17_REG_R_LOCAL_TEMP_LB 0x15
85 #define THERMO17_REG_RW_REMOTE_TEMP_THERM_LIMIT 0x19
86 #define THERMO17_REG_RW_LOCAL_TEMP_THERM_LIMIT 0x20
87 #define THERMO17_REG_RW_THERMO_HYSTERESIS 0x21
88 #define THERMO17_REG_RW_CONSECUTIVE_ALERT 0x22
89 #define THERMO17_REG_RW_M_FACTOR_CORRECTION 0x23
90 #define THERMO17_REG_RW_DIGITAL_FILTER_CTRL 0x24
91 #define THERMO17_REG_R_ID 0xFE
92 #define THERMO17_REG_W_CFG 0x09
93 #define THERMO17_REG_W_CONVERSION_RATE 0x0A
94 #define THERMO17_REG_W_LOCAL_TEMP_LIMIT_H 0x0B
95 #define THERMO17_REG_W_LOCAL_TEMP_LIMIT_L 0x0C
96 #define THERMO17_REG_W_REMOTE_TEMP_LIMIT_H_HB 0x0D
97 #define THERMO17_REG_W_REMOTE_TEMP_LIMIT_L_HB 0x0E
98 #define THERMO17_REG_W_ONE_SHOT 0x0F
99 
105 #define THERMO17_TEMPERATURE_LOCAL 0xAA
106 #define THERMO17_TEMPERATURE_REMOTE 0xBB
107 #define THERMO17_ERROR 0x00
108 
114 #define THERMO17_DEV_ID 0x55
115 
121 #define THERMO17_STATUS_BUSY 0x80
122 #define THERMO17_STATUS_LOCAL_HIGH_TEMP 0x40
123 #define THERMO17_STATUS_LOCAL_LOW_TEMP 0x20
124 #define THERMO17_STATUS_REMOTE_HIGH_TEMP 0x10
125 #define THERMO17_STATUS_REMOTE_LOW_TEMP 0x08
126 #define THERMO17_STATUS_REMOTE_SENS_OPEN_CIRCUIT 0x04
127 #define THERMO17_STATUS_REMOTE_THERM_TIPPED 0x02
128 #define THERMO17_STATUS_LOCAL_THERM_TIPPED 0x01
129 
135 #define THERMO17_RETVAL uint8_t
136 
137 #define THERMO17_OK 0x00
138 #define THERMO17_INIT_ERROR 0xFF
139  // End group macro
144 // --------------------------------------------------------------- PUBLIC TYPES
153 typedef struct
154 {
155  // Input pins
156 
157  digital_in_t an;
158  digital_in_t int_pin;
159 
160  // Modules
161 
162  i2c_master_t i2c;
163 
164  // ctx variable
165 
166  uint8_t slave_address;
167 
168 } thermo17_t;
169 
173 typedef struct
174 {
175  // Communication gpio pins
176 
177  pin_name_t scl;
178  pin_name_t sda;
179 
180  // Additional gpio pins
181 
182  pin_name_t an;
183  pin_name_t int_pin;
184 
185  // static variable
186 
187  uint32_t i2c_speed;
188  uint8_t i2c_address;
189 
191  // End variable group
193 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
194 
200 #ifdef __cplusplus
201 extern "C"{
202 #endif
203 
213 
223 
233 void thermo17_generic_write ( thermo17_t *ctx, uint8_t reg_adr, uint8_t write_data );
234 
245 uint8_t thermo17_generic_read ( thermo17_t *ctx, uint8_t reg_adr );
246 
258 float thermo17_read_temp ( thermo17_t *ctx, uint8_t temp_macro );
259 
270 
281 
282 #ifdef __cplusplus
283 }
284 #endif
285 #endif // _THERMO17_H_
286  // End public_function group
289 
290 // ------------------------------------------------------------------------- END
thermo17_t::int_pin
digital_in_t int_pin
Definition: thermo17.h:158
thermo17_cfg_t::sda
pin_name_t sda
Definition: thermo17.h:178
thermo17_t::slave_address
uint8_t slave_address
Definition: thermo17.h:166
thermo17_get_an_status
uint8_t thermo17_get_an_status(thermo17_t *ctx)
Checks status of an pin.
thermo17_read_temp
float thermo17_read_temp(thermo17_t *ctx, uint8_t temp_macro)
Function for reading temperature.
thermo17_cfg_t::scl
pin_name_t scl
Definition: thermo17.h:177
thermo17_t
Click ctx object definition.
Definition: thermo17.h:154
thermo17_t::an
digital_in_t an
Definition: thermo17.h:157
THERMO17_RETVAL
#define THERMO17_RETVAL
Definition: thermo17.h:135
thermo17_cfg_t::int_pin
pin_name_t int_pin
Definition: thermo17.h:183
thermo17_init
THERMO17_RETVAL thermo17_init(thermo17_t *ctx, thermo17_cfg_t *cfg)
Initialization function.
thermo17_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: thermo17.h:187
thermo17_cfg_t::an
pin_name_t an
Definition: thermo17.h:182
thermo17_cfg_t
Click configuration structure definition.
Definition: thermo17.h:174
thermo17_t::i2c
i2c_master_t i2c
Definition: thermo17.h:162
thermo17_generic_read
uint8_t thermo17_generic_read(thermo17_t *ctx, uint8_t reg_adr)
Generic read function.
thermo17_cfg_t::i2c_address
uint8_t i2c_address
Definition: thermo17.h:188
thermo17_cfg_setup
void thermo17_cfg_setup(thermo17_cfg_t *cfg)
Config Object Initialization function.
thermo17_generic_write
void thermo17_generic_write(thermo17_t *ctx, uint8_t reg_adr, uint8_t write_data)
Generic write function.
thermo17_get_int_status
uint8_t thermo17_get_int_status(thermo17_t *ctx)
Checks status of int pin.