thermo27  2.1.0.0
thermo27.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 THERMO27_H
29 #define THERMO27_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_i2c_master.h"
48 
69 #define THERMO27_TEMP_RESULT_REG 0x00
70 #define THERMO27_SLEW_RESULT_REG 0x01
71 #define THERMO27_ALERT_STATUS_REG 0x02
72 #define THERMO27_CONFIGURATION_REG 0x03
73 #define THERMO27_TLOW_LIMIT_REG 0x04
74 #define THERMO27_THIGH_LIMIT_REG 0x05
75 #define THERMO27_HYSTERESIS_REG 0x06
76 #define THERMO27_SLEW_LIMIT_REG 0x07
77 #define THERMO27_UNIQUE_ID1_REG 0x08
78 #define THERMO27_UNIQUE_ID2_REG 0x09
79 #define THERMO27_UNIQUE_ID3_REG 0x0A
80 #define THERMO27_DEVICE_ID_REG 0x0B
81  // thermo27_reg
83 
98 #define THERMO27_CRC_MODE_ENABLED 0x01
99 #define THERMO27_CRC_MODE_DISABLED 0x00
100 #define THERMO27_POLYNOMIAL 0x07
101 #define THERMO27_DEVICE_ID 0x1114
102 #define THERMO27_TEMP_COEF 0.0078125
103 #define THERMO27_LSB_VAL 0.03125
104 #define THERMO27_LOW_TEMP_LIMIT_VAL -25
105 #define THERMO27_HIGH_TEMP_LIMIT_VAL 80
106 #define THERMO27_SW_RESET 0x06
107 
113 #define THERMO27_ADC_TIME_6mS_MODE_CMD 0x0000
114 #define THERMO27_ADC_TIME_4mS_MODE_CMD 0x0200
115 #define THERMO27_ADC_TIME_2mS_MODE_CMD 0x0400
116 #define THERMO27_ADC_TIME_1mS_MODE_CMD 0x0600
117 #define THERMO27_SW_RESET_CMD 0x0100
118 #define THERMO27_ENABLE_AVG_CMD 0x0080
119 #define THERMO27_ENABLE_CRC_CMD 0x0040
120 #define THERMO27_ONE_SHOT_CMD 0x0010
121 #define THERMO27_CONTINUOUS_MODE_CMD 0x0000
122 #define THERMO27_SHOUTDOWN_MODE_CMD 0x0008
123 #define THERMO27_CONVERSION_TIME_7mS_MODE_CMD 0x0000
124 #define THERMO27_CONVERSION_TIME_32mS_MODE_CMD 0x0001
125 #define THERMO27_CONVERSION_TIME_63mS_MODE_CMD 0x0002
126 #define THERMO27_CONVERSION_TIME_125mS_MODE_CMD 0x0003
127 #define THERMO27_CONVERSION_TIME_250mS_MODE_CMD 0x0004
128 #define THERMO27_CONVERSION_TIME_500mS_MODE_CMD 0x0005
129 #define THERMO27_CONVERSION_TIME_1S_MODE_CMD 0x0006
130 #define THERMO27_CONVERSION_TIME_2S_MODE_CMD 0x0007
131 
137 #define THERMO27_CRC_FLAG 0x80
138 #define THERMO27_SLEW_STATUS 0x40
139 #define THERMO27_SLEW_FLAG 0x20
140 #define THERMO27_THIGH_STATUS 0x10
141 #define THERMO27_TLOW_STATUS 0x08
142 #define THERMO27_THIGH_FLAG 0x04
143 #define THERMO27_TLOW_FLAG 0x02
144 #define THERMO27_DATA_READY_FLAG 0x01
145 
146 
152 #define THERMO27_DEVICE_ADDRESS 0x4D
153 #define THERMO27_RESET_DEVICE_ADDRESS 0x00
154  // thermo27_set
156 
171 #define THERMO27_MAP_MIKROBUS( cfg, mikrobus ) \
172  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
173  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
174  // thermo27_map // thermo27
177 
182 typedef struct
183 {
184  // Modules
185  i2c_master_t i2c;
187  // I2C slave address
188  uint8_t slave_address;
190  uint8_t crc_mode;
192 } thermo27_t;
193 
198 typedef struct
199 {
200  pin_name_t scl;
201  pin_name_t sda;
203  uint32_t i2c_speed;
204  uint8_t i2c_address;
207 
212 typedef enum
213 {
215  THERMO27_ERROR = -1
216 
218 
235 
250 
264 
279 err_t thermo27_generic_write ( thermo27_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
280 
295 err_t thermo27_generic_read ( thermo27_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
296 
310 err_t thermo27_write_register ( thermo27_t *ctx, uint8_t reg, uint16_t data_in );
311 
325 err_t thermo27_read_register ( thermo27_t *ctx, uint8_t reg, uint16_t *data_out );
326 
339 err_t thermo27_get_device_id ( thermo27_t *ctx, uint16_t *device_id );
340 
352 
365 err_t thermo27_read_temp ( thermo27_t *ctx, float *temp_out );
366 
379 
391 err_t thermo27_set_low_temp_limit ( thermo27_t *ctx, float low_temp_limit );
392 
404 err_t thermo27_set_high_temp_limit ( thermo27_t *ctx, float high_temp_limit );
405 
418 err_t thermo27_set_hysteresis ( thermo27_t *ctx, uint8_t thigh_hyst, uint8_t tlow_hyst );
419 
431 err_t thermo27_set_slew_limit ( thermo27_t *ctx, float slew_limit );
432 
444 err_t thermo27_get_alert_reg ( thermo27_t *ctx, uint8_t *register_flags );
445 
446 #ifdef __cplusplus
447 }
448 #endif
449 #endif // THERMO27_H
450  // thermo27
452 
453 // ------------------------------------------------------------------------ END
thermo27_t::slave_address
uint8_t slave_address
Definition: thermo27.h:188
thermo27_set_hysteresis
err_t thermo27_set_hysteresis(thermo27_t *ctx, uint8_t thigh_hyst, uint8_t tlow_hyst)
Thermo 27 set hysteresis function.
thermo27_enable_crc
err_t thermo27_enable_crc(thermo27_t *ctx)
Thermo 27 enable CRC function.
thermo27_sw_reset
err_t thermo27_sw_reset(thermo27_t *ctx)
Thermo 27 software reset function.
THERMO27_ERROR
@ THERMO27_ERROR
Definition: thermo27.h:215
thermo27_cfg_t::i2c_address
uint8_t i2c_address
Definition: thermo27.h:204
thermo27_set_high_temp_limit
err_t thermo27_set_high_temp_limit(thermo27_t *ctx, float high_temp_limit)
Thermo 27 set high temperature limit function.
thermo27_cfg_t::sda
pin_name_t sda
Definition: thermo27.h:201
thermo27_set_slew_limit
err_t thermo27_set_slew_limit(thermo27_t *ctx, float slew_limit)
Thermo 27 set slew limit function.
thermo27_init
err_t thermo27_init(thermo27_t *ctx, thermo27_cfg_t *cfg)
Thermo 27 initialization function.
thermo27_cfg_t::scl
pin_name_t scl
Definition: thermo27.h:200
thermo27_read_temp
err_t thermo27_read_temp(thermo27_t *ctx, float *temp_out)
Thermo 27 get read temperature function.
thermo27_cfg_t
Thermo 27 Click configuration object.
Definition: thermo27.h:199
thermo27_generic_write
err_t thermo27_generic_write(thermo27_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Thermo 27 I2C writing function.
thermo27_get_device_id
err_t thermo27_get_device_id(thermo27_t *ctx, uint16_t *device_id)
Thermo 27 get device id function.
thermo27_return_value_t
thermo27_return_value_t
Thermo 27 Click return value data.
Definition: thermo27.h:213
thermo27_set_low_temp_limit
err_t thermo27_set_low_temp_limit(thermo27_t *ctx, float low_temp_limit)
Thermo 27 set low temperature limit function.
thermo27_t::i2c
i2c_master_t i2c
Definition: thermo27.h:185
THERMO27_OK
@ THERMO27_OK
Definition: thermo27.h:214
thermo27_read_register
err_t thermo27_read_register(thermo27_t *ctx, uint8_t reg, uint16_t *data_out)
Thermo 27 register reading function.
thermo27_t::crc_mode
uint8_t crc_mode
Definition: thermo27.h:190
thermo27_write_register
err_t thermo27_write_register(thermo27_t *ctx, uint8_t reg, uint16_t data_in)
Thermo 27 register writing function.
thermo27_get_alert_reg
err_t thermo27_get_alert_reg(thermo27_t *ctx, uint8_t *register_flags)
Thermo 27 get alert register staus function.
thermo27_cfg_setup
void thermo27_cfg_setup(thermo27_cfg_t *cfg)
Thermo 27 configuration object setup function.
thermo27_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: thermo27.h:203
thermo27_default_cfg
err_t thermo27_default_cfg(thermo27_t *ctx)
Thermo 27 default configuration function.
thermo27_generic_read
err_t thermo27_generic_read(thermo27_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Thermo 27 I2C reading function.
thermo27_t
Thermo 27 Click context object.
Definition: thermo27.h:183