thermo19  2.0.0.0
thermo19.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 THERMO19_H
29 #define THERMO19_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_one_wire.h"
48 
69 #define THERMO19_CMD_CONVERT_TEMPERATURE 0x44
70 #define THERMO19_CMD_WRITE_SCRATCHPAD 0x4E
71 #define THERMO19_CMD_READ_SCRATCHPAD 0xBE
72 #define THERMO19_CMD_DETECT_ADDRESS 0x88
73 #define THERMO19_CMD_SELECT_ADDRESS 0x70
74  // thermo19_cmd
76 
91 #define THERMO19_CONFIG_FORMAT_NORMAL 0x00
92 #define THERMO19_CONFIG_FORMAT_EXTEND 0x80
93 #define THERMO19_CONFIG_FORMAT_BIT_MASK 0x80
94 #define THERMO19_CONFIG_RESOLUTION_8BIT 0x00
95 #define THERMO19_CONFIG_RESOLUTION_9BIT 0x20
96 #define THERMO19_CONFIG_RESOLUTION_10BIT 0x40
97 #define THERMO19_CONFIG_RESOLUTION_12BIT 0x60
98 #define THERMO19_CONFIG_RESOLUTION_BIT_MASK 0x60
99 #define THERMO19_CONFIG_COMP_INT_COMPARATOR 0x00
100 #define THERMO19_CONFIG_COMP_INT_INTERRUPT 0x10
101 #define THERMO19_CONFIG_COMP_INT_BIT_MASK 0x10
102 #define THERMO19_CONFIG_FAULT_QUEUE_SINGLE 0x00
103 #define THERMO19_CONFIG_FAULT_QUEUE_MULTIPLE 0x08
104 #define THERMO19_CONFIG_FAULT_QUEUE_BIT_MASK 0x08
105 #define THERMO19_CONFIG_CONVERSION_RATE_0 0x00
106 #define THERMO19_CONFIG_CONVERSION_RATE_1_64 0x01
107 #define THERMO19_CONFIG_CONVERSION_RATE_1_32 0x02
108 #define THERMO19_CONFIG_CONVERSION_RATE_1_16 0x03
109 #define THERMO19_CONFIG_CONVERSION_RATE_1_4 0x04
110 #define THERMO19_CONFIG_CONVERSION_RATE_1_1 0x05
111 #define THERMO19_CONFIG_CONVERSION_RATE_4_1 0x06
112 #define THERMO19_CONFIG_CONVERSION_RATE_8_1 0x07
113 #define THERMO19_CONFIG_CONVERSION_RATE_BIT_MASK 0x07
114 
119 #define THERMO19_STATUS_TH_FAULT_OCCURED 0x80
120 #define THERMO19_STATUS_TH_FAULT_NOT_OCCURED 0x00
121 #define THERMO19_STATUS_TH_FAULT_BIT_MASK 0x80
122 #define THERMO19_STATUS_TL_FAULT_OCCURED 0x40
123 #define THERMO19_STATUS_TL_FAULT_NOT_OCCURED 0x00
124 #define THERMO19_STATUS_TL_FAULT_BIT_MASK 0x40
125 #define THERMO19_STATUS_ADDRRESS_0 0x1A
126 #define THERMO19_STATUS_ADDRRESS_1 0x3A
127 #define THERMO19_STATUS_ADDRRESS_BIT_MASK 0x3F
128 
133 #define THERMO19_ADDRESS_0 0x1A
134 #define THERMO19_ADDRESS_1 0x3A
135 #define THERMO19_ADDRESS_ALL 0xFF
136 #define THERMO19_ADDRESS_BIT_MASK 0x3F
137 
142 #define THERMO19_DATA_RESOLUTION 0.0625
143 
148 #define THERMO19_FAMILY_CODE 0x3B
149 
154 #define THERMO19_DEFAULT_CONFIG ( THERMO19_CONFIG_RESOLUTION_12BIT | THERMO19_CONFIG_COMP_INT_INTERRUPT )
155 #define THERMO19_DEFAULT_ADDRESS THERMO19_ADDRESS_ALL
156 #define THERMO19_DEFAULT_TEMP_HIGH_ALARM 0xFFFF
157 #define THERMO19_DEFAULT_TEMP_LOW_ALARM 0x0000
158  // thermo19_set
160 
176 #define THERMO19_MAP_MIKROBUS( cfg, mikrobus ) \
177  cfg.gp0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
178  cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
179  cfg.alt = MIKROBUS( mikrobus, MIKROBUS_INT );
180  // thermo19_map // thermo19
183 
188 typedef enum
189 {
194 
199 typedef struct
200 {
201  digital_in_t alt;
203  // Modules
204  one_wire_t ow;
206  one_wire_rom_address_t rom_addr;
207  uint8_t config;
208  uint8_t address;
210 } thermo19_t;
211 
216 typedef struct
217 {
218  // Communication gpio pins
219  pin_name_t gp0;
220  pin_name_t gp1;
221  pin_name_t alt;
226 
231 typedef enum
232 {
234  THERMO19_ERROR = -1
235 
237 
254 
270 
286 
301 
314 
327 
339 
351 err_t thermo19_read_scratchpad ( thermo19_t *ctx, uint8_t *scratchpad );
352 
366 err_t thermo19_write_scratchpad ( thermo19_t *ctx, uint16_t temp_high, uint16_t temp_low, uint8_t config );
367 
379 err_t thermo19_read_temperature ( thermo19_t *ctx, float *temperature );
380 
390 
391 #ifdef __cplusplus
392 }
393 #endif
394 #endif // THERMO19_H
395  // thermo19
397 
398 // ------------------------------------------------------------------------ END
thermo19_t::alt
digital_in_t alt
Definition: thermo19.h:201
thermo19_cfg_t::gpio_sel
thermo19_gpio_sel_t gpio_sel
Definition: thermo19.h:223
THERMO19_OK
@ THERMO19_OK
Definition: thermo19.h:233
thermo19_t::config
uint8_t config
Definition: thermo19.h:207
thermo19_gpio_selection
void thermo19_gpio_selection(thermo19_cfg_t *cfg, thermo19_gpio_sel_t gpio_sel)
Thermo 19 driver interface setup function.
thermo19_check_communication
err_t thermo19_check_communication(thermo19_t *ctx)
Thermo 19 check communication function.
thermo19_default_cfg
err_t thermo19_default_cfg(thermo19_t *ctx)
Thermo 19 default configuration function.
THERMO19_GPIO_0
@ THERMO19_GPIO_0
Definition: thermo19.h:190
thermo19_t::ow
one_wire_t ow
Definition: thermo19.h:204
thermo19_cfg_t::gp0
pin_name_t gp0
Definition: thermo19.h:219
thermo19_t
Thermo 19 Click context object.
Definition: thermo19.h:200
thermo19_t::rom_addr
one_wire_rom_address_t rom_addr
Definition: thermo19.h:206
THERMO19_GPIO_1
@ THERMO19_GPIO_1
Definition: thermo19.h:191
thermo19_cfg_t::alt
pin_name_t alt
Definition: thermo19.h:221
thermo19_read_scratchpad
err_t thermo19_read_scratchpad(thermo19_t *ctx, uint8_t *scratchpad)
Thermo 19 read scratchpad function.
thermo19_cfg_setup
void thermo19_cfg_setup(thermo19_cfg_t *cfg)
Thermo 19 configuration object setup function.
thermo19_cfg_t
Thermo 19 Click configuration object.
Definition: thermo19.h:217
thermo19_return_value_t
thermo19_return_value_t
Thermo 19 Click return value data.
Definition: thermo19.h:232
thermo19_write_scratchpad
err_t thermo19_write_scratchpad(thermo19_t *ctx, uint16_t temp_high, uint16_t temp_low, uint8_t config)
Thermo 19 write scratchpad function.
thermo19_start_measurement
err_t thermo19_start_measurement(thermo19_t *ctx)
Thermo 19 start measurement function.
thermo19_read_temperature
err_t thermo19_read_temperature(thermo19_t *ctx, float *temperature)
Thermo 19 read temperature function.
thermo19_gpio_sel_t
thermo19_gpio_sel_t
Thermo 19 Click gpio selector.
Definition: thermo19.h:189
thermo19_get_alert_pin
uint8_t thermo19_get_alert_pin(thermo19_t *ctx)
Thermo 19 get alert pin function.
thermo19_cfg_t::gp1
pin_name_t gp1
Definition: thermo19.h:220
THERMO19_ERROR
@ THERMO19_ERROR
Definition: thermo19.h:234
thermo19_select_device
err_t thermo19_select_device(thermo19_t *ctx)
Thermo 19 select device function.
thermo19_init
err_t thermo19_init(thermo19_t *ctx, thermo19_cfg_t *cfg)
Thermo 19 initialization function.
thermo19_t::address
uint8_t address
Definition: thermo19.h:208