thermo26  2.1.0.0
thermo26.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 THERMO26_H
29 #define THERMO26_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 THERMO26_CMD_SINGLE_SHOT_CLK_STR_EN_REP_HIGH 0x2C06
70 #define THERMO26_CMD_SINGLE_SHOT_CLK_STR_EN_REP_MID 0x2C0D
71 #define THERMO26_CMD_SINGLE_SHOT_CLK_STR_EN_REP_LOW 0x2C10
72 #define THERMO26_CMD_SINGLE_SHOT_CLK_STR_DIS_REP_HIGH 0x2400
73 #define THERMO26_CMD_SINGLE_SHOT_CLK_STR_DIS_REP_MID 0x240B
74 #define THERMO26_CMD_SINGLE_SHOT_CLK_STR_DIS_REP_LOW 0x2416
75 #define THERMO26_CMD_PERIODIC_0p5_MPS_REP_HIGH 0x2032
76 #define THERMO26_CMD_PERIODIC_0p5_MPS_REP_MID 0x2024
77 #define THERMO26_CMD_PERIODIC_0p5_MPS_REP_LOW 0x202F
78 #define THERMO26_CMD_PERIODIC_1_MPS_REP_HIGH 0x2130
79 #define THERMO26_CMD_PERIODIC_1_MPS_REP_MID 0x2126
80 #define THERMO26_CMD_PERIODIC_1_MPS_REP_LOW 0x212D
81 #define THERMO26_CMD_PERIODIC_2_MPS_REP_HIGH 0x2236
82 #define THERMO26_CMD_PERIODIC_2_MPS_REP_MID 0x2220
83 #define THERMO26_CMD_PERIODIC_2_MPS_REP_LOW 0x222B
84 #define THERMO26_CMD_PERIODIC_4_MPS_REP_HIGH 0x2334
85 #define THERMO26_CMD_PERIODIC_4_MPS_REP_MID 0x2322
86 #define THERMO26_CMD_PERIODIC_4_MPS_REP_LOW 0x2329
87 #define THERMO26_CMD_PERIODIC_10_MPS_REP_HIGH 0x2737
88 #define THERMO26_CMD_PERIODIC_10_MPS_REP_MID 0x2721
89 #define THERMO26_CMD_PERIODIC_10_MPS_REP_LOW 0x272A
90 #define THERMO26_CMD_FETCH_DATA 0xE000
91 #define THERMO26_CMD_BREAK 0x3093
92 #define THERMO26_CMD_SOFT_RESET 0x30A2
93 #define THERMO26_CMD_HEATER_ENABLE 0x306D
94 #define THERMO26_CMD_HEATER_DISABLE 0x3066
95 #define THERMO26_CMD_READ_STATUS 0xF32D
96 #define THERMO26_CMD_CLEAR_STATUS 0x3041
97 #define THERMO26_CMD_GET_SERIAL_NUM 0x3780
98  // thermo26_reg
100 
115 #define THERMO26_DATA_RESOLUTION 65535.0f
116 #define THERMO26_ABS_MIN_TEMP ( -45.0f )
117 #define THERMO26_ABS_MAX_TEMP ( 130.0f )
118 
124 #define THERMO26_DEVICE_ADDRESS_0 0x4A
125 #define THERMO26_DEVICE_ADDRESS_1 0x4B
126  // thermo26_set
128 
143 #define THERMO26_MAP_MIKROBUS( cfg, mikrobus ) \
144  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
145  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
146  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
147  cfg.alt = MIKROBUS( mikrobus, MIKROBUS_INT )
148  // thermo26_map // thermo26
151 
156 typedef struct
157 {
158  // Output pins
159  digital_out_t rst;
161  // Input pins
162  digital_in_t alt;
164  // Modules
165  i2c_master_t i2c;
167  // I2C slave address
168  uint8_t slave_address;
170 } thermo26_t;
171 
176 typedef struct
177 {
178  pin_name_t scl;
179  pin_name_t sda;
181  pin_name_t rst;
182  pin_name_t alt;
184  uint32_t i2c_speed;
185  uint8_t i2c_address;
188 
193 typedef enum
194 {
196  THERMO26_ERROR = -1
197 
199 
216 
231 
243 err_t thermo26_write_command ( thermo26_t *ctx, uint16_t cmd );
244 
258 err_t thermo26_read_command ( thermo26_t *ctx, uint16_t cmd, uint16_t *data_out );
259 
269 
279 void thermo26_set_rst_pin ( thermo26_t *ctx, uint8_t state );
280 
290 
302 err_t thermo26_read_temperature ( thermo26_t *ctx, float *temperature );
303 
315 err_t thermo26_read_serial_num ( thermo26_t *ctx, uint32_t *serial_num );
316 
328 err_t thermo26_start_measurement ( thermo26_t *ctx, uint16_t cmd );
329 
341 
342 #ifdef __cplusplus
343 }
344 #endif
345 #endif // THERMO26_H
346  // thermo26
348 
349 // ------------------------------------------------------------------------ END
thermo26_reset_device
void thermo26_reset_device(thermo26_t *ctx)
Thermo 26 reset device function.
thermo26_cfg_t::sda
pin_name_t sda
Definition: thermo26.h:179
thermo26_get_alert_pin
uint8_t thermo26_get_alert_pin(thermo26_t *ctx)
Thermo 26 get alert pin function.
thermo26_return_value_t
thermo26_return_value_t
Thermo 26 Click return value data.
Definition: thermo26.h:194
thermo26_cfg_t::rst
pin_name_t rst
Definition: thermo26.h:181
thermo26_t::i2c
i2c_master_t i2c
Definition: thermo26.h:165
thermo26_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: thermo26.h:184
thermo26_stop_measurement
err_t thermo26_stop_measurement(thermo26_t *ctx)
Thermo 26 stop measurement function.
thermo26_t::slave_address
uint8_t slave_address
Definition: thermo26.h:168
thermo26_start_measurement
err_t thermo26_start_measurement(thermo26_t *ctx, uint16_t cmd)
Thermo 26 start measurement function.
THERMO26_OK
@ THERMO26_OK
Definition: thermo26.h:195
thermo26_read_temperature
err_t thermo26_read_temperature(thermo26_t *ctx, float *temperature)
Thermo 26 read temperature function.
thermo26_t::alt
digital_in_t alt
Definition: thermo26.h:162
thermo26_read_command
err_t thermo26_read_command(thermo26_t *ctx, uint16_t cmd, uint16_t *data_out)
Thermo 26 read command function.
thermo26_cfg_t
Thermo 26 Click configuration object.
Definition: thermo26.h:177
thermo26_cfg_setup
void thermo26_cfg_setup(thermo26_cfg_t *cfg)
Thermo 26 configuration object setup function.
thermo26_cfg_t::alt
pin_name_t alt
Definition: thermo26.h:182
thermo26_write_command
err_t thermo26_write_command(thermo26_t *ctx, uint16_t cmd)
Thermo 26 write command function.
thermo26_read_serial_num
err_t thermo26_read_serial_num(thermo26_t *ctx, uint32_t *serial_num)
Thermo 26 read serial num function.
THERMO26_ERROR
@ THERMO26_ERROR
Definition: thermo26.h:196
thermo26_t::rst
digital_out_t rst
Definition: thermo26.h:159
thermo26_t
Thermo 26 Click context object.
Definition: thermo26.h:157
thermo26_cfg_t::i2c_address
uint8_t i2c_address
Definition: thermo26.h:185
thermo26_cfg_t::scl
pin_name_t scl
Definition: thermo26.h:178
thermo26_set_rst_pin
void thermo26_set_rst_pin(thermo26_t *ctx, uint8_t state)
Thermo 26 set rst pin function.
thermo26_init
err_t thermo26_init(thermo26_t *ctx, thermo26_cfg_t *cfg)
Thermo 26 initialization function.