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
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_out.h"
50#include "drv_digital_in.h"
51#include "drv_one_wire.h"
52
73#define THERMO2_CMD_CONVERT_TEMPERATURE 0x44
74#define THERMO2_CMD_WRITE_SCRATCHPAD 0x4E
75#define THERMO2_CMD_READ_SCRATCHPAD 0xBE
76#define THERMO2_CMD_COPY_SCRATCHPAD 0x48
77#define THERMO2_CMD_RECALL_SCRATCHPAD 0xB8
78#define THERMO2_CMD_READ_POWER_SUPPLY 0xB4
79
80 // thermo2_cmd
81
96#define THERMO2_CONFIG_ADDRESS_0 0x00
97#define THERMO2_CONFIG_ADDRESS_1 0x01
98#define THERMO2_CONFIG_ADDRESS_2 0x02
99#define THERMO2_CONFIG_ADDRESS_3 0x03
100#define THERMO2_CONFIG_ADDRESS_4 0x04
101#define THERMO2_CONFIG_ADDRESS_5 0x05
102#define THERMO2_CONFIG_ADDRESS_6 0x06
103#define THERMO2_CONFIG_ADDRESS_7 0x07
104#define THERMO2_CONFIG_ADDRESS_8 0x08
105#define THERMO2_CONFIG_ADDRESS_9 0x09
106#define THERMO2_CONFIG_ADDRESS_10 0x0A
107#define THERMO2_CONFIG_ADDRESS_11 0x0B
108#define THERMO2_CONFIG_ADDRESS_12 0x0C
109#define THERMO2_CONFIG_ADDRESS_13 0x0D
110#define THERMO2_CONFIG_ADDRESS_14 0x0E
111#define THERMO2_CONFIG_ADDRESS_15 0x0F
112#define THERMO2_CONFIG_ADDRESS_ALL 0x10
113#define THERMO2_CONFIG_ADDRESS_BIT_MASK 0x1F
114#define THERMO2_CONFIG_RESOLUTION_9BIT 0x00
115#define THERMO2_CONFIG_RESOLUTION_10BIT 0x20
116#define THERMO2_CONFIG_RESOLUTION_11BIT 0x40
117#define THERMO2_CONFIG_RESOLUTION_12BIT 0x60
118#define THERMO2_CONFIG_RESOLUTION_BIT_MASK 0x60
119#define THERMO2_CONFIG_RESERVED_BITS 0x10
120
125#define THERMO2_DATA_RESOLUTION 0.0625
126
131#define THERMO2_FAMILY_CODE 0x3B
132
137#define THERMO2_DEFAULT_ADDRESS THERMO2_CONFIG_ADDRESS_ALL
138#define THERMO2_DEFAULT_RESOLUTION THERMO2_CONFIG_RESOLUTION_12BIT
139#define THERMO2_DEFAULT_TEMP_HIGH_ALARM 0xFF
140#define THERMO2_DEFAULT_TEMP_LOW_ALARM 0x00
141
142 // thermo2_set
143
158#define THERMO2_MAP_MIKROBUS( cfg, mikrobus ) \
159 cfg.gp0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
160 cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_AN );
161
162 // thermo2_map
163 // thermo2
164
175
180typedef struct
181{
182 // Modules
183 one_wire_t ow;
185 one_wire_rom_address_t rom_addr;
186 uint8_t config;
188} thermo2_t;
189
194typedef struct
195{
196 // Communication gpio pins
197 pin_name_t gp0;
198 pin_name_t gp1;
203
208typedef enum
209{
211 THERMO2_ERROR = -1
212
214
231
247
263
278
291
304
316
328err_t thermo2_read_scratchpad ( thermo2_t *ctx, uint8_t *scratchpad );
329
343err_t thermo2_write_scratchpad ( thermo2_t *ctx, uint8_t temp_high, uint8_t temp_low, uint8_t config );
344
356err_t thermo2_read_temperature ( thermo2_t *ctx, float *temperature );
357
358#ifdef __cplusplus
359}
360#endif
361#endif // THERMO2_H
362
363 // thermo2
364
365// ------------------------------------------------------------------------ END
err_t thermo2_init(thermo2_t *ctx, thermo2_cfg_t *cfg)
Thermo 2 initialization function.
err_t thermo2_write_scratchpad(thermo2_t *ctx, uint8_t temp_high, uint8_t temp_low, uint8_t config)
Thermo 2 write scratchpad function.
err_t thermo2_read_scratchpad(thermo2_t *ctx, uint8_t *scratchpad)
Thermo 2 read scratchpad function.
void thermo2_gpio_selection(thermo2_cfg_t *cfg, thermo2_gpio_sel_t gpio_sel)
Thermo 2 driver interface setup function.
err_t thermo2_read_temperature(thermo2_t *ctx, float *temperature)
Thermo 2 read temperature function.
err_t thermo2_start_measurement(thermo2_t *ctx)
Thermo 2 start measurement function.
err_t thermo2_check_communication(thermo2_t *ctx)
Thermo 2 check communication function.
err_t thermo2_default_cfg(thermo2_t *ctx)
Thermo 2 default configuration function.
err_t thermo2_select_device(thermo2_t *ctx)
Thermo 2 select device function.
void thermo2_cfg_setup(thermo2_cfg_t *cfg)
Thermo 2 configuration object setup function.
Thermo 2 Click configuration object.
Definition thermo2.h:195
thermo2_gpio_sel_t gpio_sel
Definition thermo2.h:200
pin_name_t gp0
Definition thermo2.h:197
pin_name_t gp1
Definition thermo2.h:198
Thermo 2 Click context object.
Definition thermo2.h:181
one_wire_rom_address_t rom_addr
Definition thermo2.h:185
uint8_t config
Definition thermo2.h:186
one_wire_t ow
Definition thermo2.h:183
thermo2_gpio_sel_t
Thermo 2 Click gpio selector.
Definition thermo2.h:170
@ THERMO2_GPIO_0
Definition thermo2.h:171
@ THERMO2_GPIO_1
Definition thermo2.h:172
thermo2_return_value_t
Thermo 2 Click return value data.
Definition thermo2.h:209
@ THERMO2_OK
Definition thermo2.h:210
@ THERMO2_ERROR
Definition thermo2.h:211