templog7  2.1.0.0
templog7.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 TEMPLOG7_H
29 #define TEMPLOG7_H
30 
31 #ifdef __cplusplus
32 extern "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 TEMPLOG7_CMD_CONVERT_TEMP 0x44
74 #define TEMPLOG7_CMD_ALERT_SEARCH 0xEC
75 #define TEMPLOG7_CMD_WRITE_SCRATCHPAD_1 0x4E
76 #define TEMPLOG7_CMD_READ_SCRATCHPAD_1 0xBE
77 #define TEMPLOG7_CMD_COPY_SCRATCHPAD_1 0x48
78 #define TEMPLOG7_CMD_WRITE_SCRATCHPAD_2 0x0F
79 #define TEMPLOG7_CMD_READ_SCRATCHPAD_2 0xAA
80 #define TEMPLOG7_CMD_COPY_SCRATCHPAD_2 0x55
81 #define TEMPLOG7_CMD_READ_EEPROM 0xF0
82 #define TEMPLOG7_CMD_GPIO_WRITE 0xA5
83 #define TEMPLOG7_CMD_GPIO_READ 0xF5
84  // templog7_cmd
86 
101 #define TEMPLOG7_TEMP_RES_16BIT 0.0078125f
102 #define TEMPLOG7_TEMP_RES_12BIT 0.0625f
103 
108 #define TEMPLOG7_STATUS_ALERT_HIGH 0x80
109 #define TEMPLOG7_STATUS_ALERT_LOW 0x40
110 #define TEMPLOG7_STATUS_RESERVED 0x30
111 #define TEMPLOG7_STATUS_DATA_VALID 0x08
112 #define TEMPLOG7_STATUS_POWER_MODE 0x04
113 #define TEMPLOG7_STATUS_ARB_DONE 0x02
114 #define TEMPLOG7_STATUS_LOCK_STATUS 0x01
115 
120 #define TEMPLOG7_CFG1_TEMP_FMT_12_BIT 0x00
121 #define TEMPLOG7_CFG1_TEMP_FMT_16_BIT 0x80
122 #define TEMPLOG7_CFG1_TEMP_FMT_MASK 0x80
123 #define TEMPLOG7_CFG1_RESERVED 0x40
124 #define TEMPLOG7_CFG1_CONV_TIME_SEL_3MS 0x00
125 #define TEMPLOG7_CFG1_CONV_TIME_SEL_5p5MS 0x20
126 #define TEMPLOG7_CFG1_CONV_TIME_SEL_MASK 0x20
127 #define TEMPLOG7_CFG1_ALERT_MODE_ALERT 0x00
128 #define TEMPLOG7_CFG1_ALERT_MODE_COMPARATOR 0x10
129 #define TEMPLOG7_CFG1_ALERT_MODE_MASK 0x10
130 #define TEMPLOG7_CFG1_AVG_SEL_NO_AVG 0x00
131 #define TEMPLOG7_CFG1_AVG_SEL_8_B2B_CONV 0x08
132 #define TEMPLOG7_CFG1_AVG_SEL_MASK 0x08
133 #define TEMPLOG7_CFG1_CONV_MODE_SEL_ONE_SHOT 0x00
134 #define TEMPLOG7_CFG1_CONV_MODE_SEL_STACKED 0x01
135 #define TEMPLOG7_CFG1_CONV_MODE_SEL_AUTO 0x02
136 #define TEMPLOG7_CFG1_CONV_MODE_SEL_MASK 0x07
137 
142 #define TEMPLOG7_CFG2_OD_DIS 0x00
143 #define TEMPLOG7_CFG2_OD_EN 0x80
144 #define TEMPLOG7_CFG2_OD_MASK 0x80
145 #define TEMPLOG7_CFG2_FLEX_ADDR_MODE_HOST 0x00
146 #define TEMPLOG7_CFG2_FLEX_ADDR_MODE_IO 0x20
147 #define TEMPLOG7_CFG2_FLEX_ADDR_MODE_RES 0x40
148 #define TEMPLOG7_CFG2_FLEX_ADDR_MODE_IO_RES 0x60
149 #define TEMPLOG7_CFG2_FLEX_ADDR_MODE_MASK 0x60
150 #define TEMPLOG7_CFG2_ARB_MODE_DIS 0x00
151 #define TEMPLOG7_CFG2_ARB_MODE_SOFT_EN 0x10
152 #define TEMPLOG7_CFG2_ARB_MODE_FAST_EN 0x18
153 #define TEMPLOG7_CFG2_ARB_MODE_MASK 0x18
154 #define TEMPLOG7_CFG2_HYSTERESIS_5_C 0x00
155 #define TEMPLOG7_CFG2_HYSTERESIS_10_C 0x02
156 #define TEMPLOG7_CFG2_HYSTERESIS_15_C 0x04
157 #define TEMPLOG7_CFG2_HYSTERESIS_20_C 0x06
158 #define TEMPLOG7_CFG2_HYSTERESIS_MASK 0x06
159 #define TEMPLOG7_CFG2_LOCK_DIS 0x00
160 #define TEMPLOG7_CFG2_LOCK_EN 0x01
161 #define TEMPLOG7_CFG2_LOCK_MASK 0x01
162 
167 #define TEMPLOG7_TEMP_ALERT_LOW 5.0f
168 #define TEMPLOG7_TEMP_ALERT_HIGH 40.0f
169 #define TEMPLOG7_TEMP_OFFSET 0.0f
170 
175 #define TEMPLOG7_IO_READ_NIO3_STATE 0x80
176 #define TEMPLOG7_IO_READ_NIO2_STATE 0x40
177 #define TEMPLOG7_IO_READ_NIO1_STATE 0x20
178 #define TEMPLOG7_IO_READ_NIO0_STATE 0x10
179 #define TEMPLOG7_IO_READ_IO3_STATE 0x08
180 #define TEMPLOG7_IO_READ_IO2_STATE 0x04
181 #define TEMPLOG7_IO_READ_IO1_STATE 0x02
182 #define TEMPLOG7_IO_READ_IO0_STATE 0x01
183 
188 #define TEMPLOG7_IO_CFG_IO3_SEL_INPUT 0x00
189 #define TEMPLOG7_IO_CFG_IO3_SEL_OUTPUT_LOW 0x80
190 #define TEMPLOG7_IO_CFG_IO3_SEL_OUTPUT_HIGH 0xC0
191 #define TEMPLOG7_IO_CFG_IO3_SEL_MASK 0xC0
192 #define TEMPLOG7_IO_CFG_IO2_SEL_INPUT 0x00
193 #define TEMPLOG7_IO_CFG_IO2_SEL_ALERT 0x10
194 #define TEMPLOG7_IO_CFG_IO2_SEL_OUTPUT_LOW 0x20
195 #define TEMPLOG7_IO_CFG_IO2_SEL_OUTPUT_HIGH 0x30
196 #define TEMPLOG7_IO_CFG_IO2_SEL_MASK 0x30
197 #define TEMPLOG7_IO_CFG_IO1_SEL_INPUT 0x00
198 #define TEMPLOG7_IO_CFG_IO1_SEL_OUTPUT_LOW 0x08
199 #define TEMPLOG7_IO_CFG_IO1_SEL_OUTPUT_HIGH 0x0C
200 #define TEMPLOG7_IO_CFG_IO1_SEL_MASK 0x0C
201 #define TEMPLOG7_IO_CFG_IO0_SEL_INPUT 0x00
202 #define TEMPLOG7_IO_CFG_IO0_SEL_OUTPUT_LOW 0x02
203 #define TEMPLOG7_IO_CFG_IO0_SEL_OUTPUT_HIGH 0x03
204 #define TEMPLOG7_IO_CFG_IO0_SEL_MASK 0x03
205 #define TEMPLOG7_IO_CHECK_CODE_OK 0xAA
206 
211 #define TEMPLOG7_EEPROM_ADDR_MIN 0x00
212 #define TEMPLOG7_EEPROM_ADDR_MAX 0xFF
213 #define TEMPLOG7_EEPROM_ADDR_BLOCK 8
214 #define TEMPLOG7_EEPROM_ADDR_MASK 0xFFF8u
215 
220 #define TEMPLOG7_COPY_SCRATCHPAD_2_QUALIFIER 0xA5
221 
226 #define TEMPLOG7_FAMILY_CODE 0x26
227 
232 #define TEMPLOG7_ADDRESS_0 0x00
233 #define TEMPLOG7_ADDRESS_ALL 0xFF
234  // templog7_set
236 
251 #define TEMPLOG7_MAP_MIKROBUS( cfg, mikrobus ) \
252  cfg.gp0 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
253  cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
254  cfg.alert = MIKROBUS( mikrobus, MIKROBUS_INT );
255  // templog7_map // templog7
258 
263 typedef enum
264 {
269 
274 typedef struct
275 {
276  int16_t temperature;
277  uint8_t status;
278  uint8_t config_1;
279  uint8_t config_2;
280  uint8_t short_addr;
281  int16_t temp_limit_low;
282  int16_t temp_limit_high;
283  int16_t temp_offset;
286 
291 typedef struct
292 {
293  uint16_t address;
294  uint8_t data_buf[ TEMPLOG7_EEPROM_ADDR_BLOCK ];
297 
302 typedef struct
303 {
304  // Input pins
305  digital_in_t alert;
307  // Modules
308  one_wire_t ow;
310  one_wire_rom_address_t rom_addr;
311  uint8_t address;
313 } templog7_t;
314 
319 typedef struct
320 {
321  // Communication gpio pins
322  pin_name_t gp0;
323  pin_name_t gp1;
325  // Additional gpio pins
326  pin_name_t alert;
331 
336 typedef enum
337 {
339  TEMPLOG7_ERROR = -1
340 
342 
359 
375 
390 
404 
417 
430 
444 
458 
470 
484 
498 
510 
522 
534 err_t templog7_read_temperature ( templog7_t *ctx, float *temperature );
535 
549 err_t templog7_write_eeprom ( templog7_t *ctx, uint16_t address, uint8_t *data_in, uint16_t len );
550 
564 err_t templog7_read_eeprom ( templog7_t *ctx, uint16_t address, uint8_t *data_out, uint16_t len );
565 
577 
589 err_t templog7_write_gpio ( templog7_t *ctx, uint8_t data_in );
590 
602 err_t templog7_read_gpio ( templog7_t *ctx, uint8_t *data_out );
603 
613 
614 #ifdef __cplusplus
615 }
616 #endif
617 #endif // TEMPLOG7_H
618  // templog7
620 
621 // ------------------------------------------------------------------------ END
templog7_cfg_t::alert
pin_name_t alert
Definition: templog7.h:326
templog7_select_device
err_t templog7_select_device(templog7_t *ctx)
Temp-Log 7 select device function.
TEMPLOG7_OK
@ TEMPLOG7_OK
Definition: templog7.h:338
templog7_check_communication
err_t templog7_check_communication(templog7_t *ctx)
Temp-Log 7 check communication function.
templog7_t::rom_addr
one_wire_rom_address_t rom_addr
Definition: templog7.h:310
templog7_read_gpio
err_t templog7_read_gpio(templog7_t *ctx, uint8_t *data_out)
Temp-Log 7 read gpio function.
templog7_read_eeprom
err_t templog7_read_eeprom(templog7_t *ctx, uint16_t address, uint8_t *data_out, uint16_t len)
Temp-Log 7 read EEPROM function.
templog7_cfg_t::gp0
pin_name_t gp0
Definition: templog7.h:322
templog7_default_cfg
err_t templog7_default_cfg(templog7_t *ctx)
Temp-Log 7 default configuration function.
TEMPLOG7_ERROR
@ TEMPLOG7_ERROR
Definition: templog7.h:339
templog7_read_temperature
err_t templog7_read_temperature(templog7_t *ctx, float *temperature)
Temp-Log 7 read temperature function.
templog7_scratchpad_2_t::address
uint16_t address
Definition: templog7.h:293
TEMPLOG7_GPIO_0
@ TEMPLOG7_GPIO_0
Definition: templog7.h:265
templog7_cfg_setup
void templog7_cfg_setup(templog7_cfg_t *cfg)
Temp-Log 7 configuration object setup function.
templog7_write_gpio
err_t templog7_write_gpio(templog7_t *ctx, uint8_t data_in)
Temp-Log 7 write gpio function.
TEMPLOG7_EEPROM_ADDR_BLOCK
#define TEMPLOG7_EEPROM_ADDR_BLOCK
Definition: templog7.h:213
templog7_gpio_sel_t
templog7_gpio_sel_t
Temp-Log 7 Click gpio selector.
Definition: templog7.h:264
templog7_cfg_t::gp1
pin_name_t gp1
Definition: templog7.h:323
templog7_scratchpad_1_t::status
uint8_t status
Definition: templog7.h:277
templog7_start_measurement
err_t templog7_start_measurement(templog7_t *ctx)
Temp-Log 7 start measurement function.
templog7_scratchpad_1_t::temp_limit_low
int16_t temp_limit_low
Definition: templog7.h:281
templog7_scratchpad_1_t::temperature
int16_t temperature
Definition: templog7.h:276
templog7_clear_eeprom
err_t templog7_clear_eeprom(templog7_t *ctx)
Temp-Log 7 clear EEPROM function.
templog7_copy_scratchpad_2
err_t templog7_copy_scratchpad_2(templog7_t *ctx)
Temp-Log 7 copy scratchpad 2 function.
templog7_cfg_t::gpio_sel
templog7_gpio_sel_t gpio_sel
Definition: templog7.h:328
templog7_write_scratchpad_2
err_t templog7_write_scratchpad_2(templog7_t *ctx, templog7_scratchpad_2_t *scratchpad)
Temp-Log 7 write scratchpad 2 function.
templog7_scratchpad_1_t::config_1
uint8_t config_1
Definition: templog7.h:278
templog7_init
err_t templog7_init(templog7_t *ctx, templog7_cfg_t *cfg)
Temp-Log 7 initialization function.
templog7_scratchpad_1_t
Temp-Log 7 scratchpad 1 object.
Definition: templog7.h:275
templog7_get_alert_pin
uint8_t templog7_get_alert_pin(templog7_t *ctx)
Temp-Log 7 get alert pin function.
templog7_t
Temp-Log 7 Click context object.
Definition: templog7.h:303
templog7_t::alert
digital_in_t alert
Definition: templog7.h:305
templog7_scratchpad_1_t::temp_offset
int16_t temp_offset
Definition: templog7.h:283
templog7_scratchpad_1_t::short_addr
uint8_t short_addr
Definition: templog7.h:280
templog7_scratchpad_1_t::temp_limit_high
int16_t temp_limit_high
Definition: templog7.h:282
templog7_return_value_t
templog7_return_value_t
Temp-Log 7 Click return value data.
Definition: templog7.h:337
templog7_gpio_selection
void templog7_gpio_selection(templog7_cfg_t *cfg, templog7_gpio_sel_t gpio_sel)
Temp-Log 7 driver interface setup function.
templog7_write_eeprom
err_t templog7_write_eeprom(templog7_t *ctx, uint16_t address, uint8_t *data_in, uint16_t len)
Temp-Log 7 write EEPROM function.
templog7_read_scratchpad_2
err_t templog7_read_scratchpad_2(templog7_t *ctx, templog7_scratchpad_2_t *scratchpad)
Temp-Log 7 read scratchpad 2 function.
templog7_read_scratchpad_1
err_t templog7_read_scratchpad_1(templog7_t *ctx, templog7_scratchpad_1_t *scratchpad)
Temp-Log 7 read scratchpad 1 function.
TEMPLOG7_GPIO_1
@ TEMPLOG7_GPIO_1
Definition: templog7.h:266
templog7_t::address
uint8_t address
Definition: templog7.h:311
templog7_t::ow
one_wire_t ow
Definition: templog7.h:308
templog7_scratchpad_1_t::config_2
uint8_t config_2
Definition: templog7.h:279
templog7_scratchpad_2_t
Temp-Log 7 scratchpad 2 object.
Definition: templog7.h:292
templog7_copy_scratchpad_1
err_t templog7_copy_scratchpad_1(templog7_t *ctx)
Temp-Log 7 copy scratchpad 1 function.
templog7_write_scratchpad_1
err_t templog7_write_scratchpad_1(templog7_t *ctx, templog7_scratchpad_1_t *scratchpad)
Temp-Log 7 write scratchpad 1 function.
templog7_cfg_t
Temp-Log 7 Click configuration object.
Definition: templog7.h:320