thermo2  2.0.0.0
thermo2.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 THERMO2_H
29 #define THERMO2_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_one_wire.h"
38 
59 #define THERMO2_CMD_CONVERT_TEMPERATURE 0x44
60 #define THERMO2_CMD_WRITE_SCRATCHPAD 0x4E
61 #define THERMO2_CMD_READ_SCRATCHPAD 0xBE
62 #define THERMO2_CMD_COPY_SCRATCHPAD 0x48
63 #define THERMO2_CMD_RECALL_SCRATCHPAD 0xB8
64 #define THERMO2_CMD_READ_POWER_SUPPLY 0xB4
65  // thermo2_cmd
67 
82 #define THERMO2_CONFIG_ADDRESS_0 0x00
83 #define THERMO2_CONFIG_ADDRESS_1 0x01
84 #define THERMO2_CONFIG_ADDRESS_2 0x02
85 #define THERMO2_CONFIG_ADDRESS_3 0x03
86 #define THERMO2_CONFIG_ADDRESS_4 0x04
87 #define THERMO2_CONFIG_ADDRESS_5 0x05
88 #define THERMO2_CONFIG_ADDRESS_6 0x06
89 #define THERMO2_CONFIG_ADDRESS_7 0x07
90 #define THERMO2_CONFIG_ADDRESS_8 0x08
91 #define THERMO2_CONFIG_ADDRESS_9 0x09
92 #define THERMO2_CONFIG_ADDRESS_10 0x0A
93 #define THERMO2_CONFIG_ADDRESS_11 0x0B
94 #define THERMO2_CONFIG_ADDRESS_12 0x0C
95 #define THERMO2_CONFIG_ADDRESS_13 0x0D
96 #define THERMO2_CONFIG_ADDRESS_14 0x0E
97 #define THERMO2_CONFIG_ADDRESS_15 0x0F
98 #define THERMO2_CONFIG_ADDRESS_ALL 0x10
99 #define THERMO2_CONFIG_ADDRESS_BIT_MASK 0x1F
100 #define THERMO2_CONFIG_RESOLUTION_9BIT 0x00
101 #define THERMO2_CONFIG_RESOLUTION_10BIT 0x20
102 #define THERMO2_CONFIG_RESOLUTION_11BIT 0x40
103 #define THERMO2_CONFIG_RESOLUTION_12BIT 0x60
104 #define THERMO2_CONFIG_RESOLUTION_BIT_MASK 0x60
105 #define THERMO2_CONFIG_RESERVED_BITS 0x10
106 
111 #define THERMO2_DATA_RESOLUTION 0.0625
112 
117 #define THERMO2_FAMILY_CODE 0x3B
118 
123 #define THERMO2_DEFAULT_ADDRESS THERMO2_CONFIG_ADDRESS_ALL
124 #define THERMO2_DEFAULT_RESOLUTION THERMO2_CONFIG_RESOLUTION_12BIT
125 #define THERMO2_DEFAULT_TEMP_HIGH_ALARM 0xFF
126 #define THERMO2_DEFAULT_TEMP_LOW_ALARM 0x00
127  // thermo2_set
129 
144 #define THERMO2_MAP_MIKROBUS( cfg, mikrobus ) \
145  cfg.gp0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
146  cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_AN );
147  // thermo2_map // thermo2
150 
155 typedef enum
156 {
161 
166 typedef struct
167 {
168  // Modules
169  one_wire_t ow;
171  one_wire_rom_address_t rom_addr;
172  uint8_t config;
174 } thermo2_t;
175 
180 typedef struct
181 {
182  // Communication gpio pins
183  pin_name_t gp0;
184  pin_name_t gp1;
188 } thermo2_cfg_t;
189 
194 typedef enum
195 {
197  THERMO2_ERROR = -1
198 
200 
217 
233 
248 err_t thermo2_init ( thermo2_t *ctx, thermo2_cfg_t *cfg );
249 
264 
277 
290 
302 
314 err_t thermo2_read_scratchpad ( thermo2_t *ctx, uint8_t *scratchpad );
315 
329 err_t thermo2_write_scratchpad ( thermo2_t *ctx, uint8_t temp_high, uint8_t temp_low, uint8_t config );
330 
342 err_t thermo2_read_temperature ( thermo2_t *ctx, float *temperature );
343 
344 #ifdef __cplusplus
345 }
346 #endif
347 #endif // THERMO2_H
348  // thermo2
350 
351 // ------------------------------------------------------------------------ END
thermo2_cfg_t::gpio_sel
thermo2_gpio_sel_t gpio_sel
Definition: thermo2.h:186
thermo2_start_measurement
err_t thermo2_start_measurement(thermo2_t *ctx)
Thermo 2 start measurement function.
thermo2_cfg_t::gp1
pin_name_t gp1
Definition: thermo2.h:184
thermo2_cfg_setup
void thermo2_cfg_setup(thermo2_cfg_t *cfg)
Thermo 2 configuration object setup function.
thermo2_cfg_t::gp0
pin_name_t gp0
Definition: thermo2.h:183
thermo2_init
err_t thermo2_init(thermo2_t *ctx, thermo2_cfg_t *cfg)
Thermo 2 initialization function.
thermo2_read_scratchpad
err_t thermo2_read_scratchpad(thermo2_t *ctx, uint8_t *scratchpad)
Thermo 2 read scratchpad function.
THERMO2_ERROR
@ THERMO2_ERROR
Definition: thermo2.h:197
thermo2_cfg_t
Thermo 2 Click configuration object.
Definition: thermo2.h:181
THERMO2_GPIO_1
@ THERMO2_GPIO_1
Definition: thermo2.h:158
thermo2_t
Thermo 2 Click context object.
Definition: thermo2.h:167
thermo2_gpio_sel_t
thermo2_gpio_sel_t
Thermo 2 Click gpio selector.
Definition: thermo2.h:156
thermo2_t::ow
one_wire_t ow
Definition: thermo2.h:169
thermo2_check_communication
err_t thermo2_check_communication(thermo2_t *ctx)
Thermo 2 check communication function.
thermo2_t::config
uint8_t config
Definition: thermo2.h:172
thermo2_t::rom_addr
one_wire_rom_address_t rom_addr
Definition: thermo2.h:171
THERMO2_GPIO_0
@ THERMO2_GPIO_0
Definition: thermo2.h:157
thermo2_read_temperature
err_t thermo2_read_temperature(thermo2_t *ctx, float *temperature)
Thermo 2 read temperature function.
thermo2_return_value_t
thermo2_return_value_t
Thermo 2 Click return value data.
Definition: thermo2.h:195
thermo2_write_scratchpad
err_t thermo2_write_scratchpad(thermo2_t *ctx, uint8_t temp_high, uint8_t temp_low, uint8_t config)
Thermo 2 write scratchpad function.
thermo2_select_device
err_t thermo2_select_device(thermo2_t *ctx)
Thermo 2 select device function.
thermo2_gpio_selection
void thermo2_gpio_selection(thermo2_cfg_t *cfg, thermo2_gpio_sel_t gpio_sel)
Thermo 2 driver interface setup function.
thermo2_default_cfg
err_t thermo2_default_cfg(thermo2_t *ctx)
Thermo 2 default configuration function.
THERMO2_OK
@ THERMO2_OK
Definition: thermo2.h:196