thermo30  2.1.0.0
thermo30.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 THERMO30_H
29 #define THERMO30_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_i2c_master.h"
52 
73 #define THERMO30_CMD_SINGLE_SHOT_CLK_STR_EN_REP_HIGH 0x2C06
74 #define THERMO30_CMD_SINGLE_SHOT_CLK_STR_EN_REP_MID 0x2C0D
75 #define THERMO30_CMD_SINGLE_SHOT_CLK_STR_EN_REP_LOW 0x2C10
76 #define THERMO30_CMD_SINGLE_SHOT_CLK_STR_DIS_REP_HIGH 0x2400
77 #define THERMO30_CMD_SINGLE_SHOT_CLK_STR_DIS_REP_MID 0x240B
78 #define THERMO30_CMD_SINGLE_SHOT_CLK_STR_DIS_REP_LOW 0x2416
79 #define THERMO30_CMD_PERIODIC_0p5_MPS_REP_HIGH 0x2032
80 #define THERMO30_CMD_PERIODIC_0p5_MPS_REP_MID 0x2024
81 #define THERMO30_CMD_PERIODIC_0p5_MPS_REP_LOW 0x202F
82 #define THERMO30_CMD_PERIODIC_1_MPS_REP_HIGH 0x2130
83 #define THERMO30_CMD_PERIODIC_1_MPS_REP_MID 0x2126
84 #define THERMO30_CMD_PERIODIC_1_MPS_REP_LOW 0x212D
85 #define THERMO30_CMD_PERIODIC_2_MPS_REP_HIGH 0x2236
86 #define THERMO30_CMD_PERIODIC_2_MPS_REP_MID 0x2220
87 #define THERMO30_CMD_PERIODIC_2_MPS_REP_LOW 0x222B
88 #define THERMO30_CMD_PERIODIC_4_MPS_REP_HIGH 0x2334
89 #define THERMO30_CMD_PERIODIC_4_MPS_REP_MID 0x2322
90 #define THERMO30_CMD_PERIODIC_4_MPS_REP_LOW 0x2329
91 #define THERMO30_CMD_PERIODIC_10_MPS_REP_HIGH 0x2737
92 #define THERMO30_CMD_PERIODIC_10_MPS_REP_MID 0x2721
93 #define THERMO30_CMD_PERIODIC_10_MPS_REP_LOW 0x272A
94 #define THERMO30_CMD_FETCH_DATA 0xE000
95 #define THERMO30_CMD_BREAK 0x3093
96 #define THERMO30_CMD_SOFT_RESET 0x30A2
97 #define THERMO30_CMD_HEATER_ENABLE 0x306D
98 #define THERMO30_CMD_HEATER_DISABLE 0x3066
99 #define THERMO30_CMD_READ_STATUS 0xF32D
100 #define THERMO30_CMD_CLEAR_STATUS 0x3041
101 #define THERMO30_CMD_GET_SERIAL_NUM 0x3780
102 
107 #define THERMO30_PIN_STATE_HIGH 0x01
108 #define THERMO30_PIN_STATE_LOW 0x00
109 
114 #define THERMO30_DATA_RESOLUTION 65535.0f
115 #define THERMO30_ABS_MIN_TEMP -45.0f
116 #define THERMO30_ABS_MAX_TEMP 175.0f
117 
123 #define THERMO30_DEVICE_ADDRESS_GND 0x4A
124 #define THERMO30_DEVICE_ADDRESS_VCC 0x4B
125  // thermo30_set
127 
142 #define THERMO30_MAP_MIKROBUS( cfg, mikrobus ) \
143  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
144  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
145  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
146  cfg.alr = MIKROBUS( mikrobus, MIKROBUS_INT )
147  // thermo30_map // thermo30
150 
155 typedef struct
156 {
157  // Output pins
158  digital_out_t rst;
160  // Input pins
161  digital_in_t alr;
163  // Modules
164  i2c_master_t i2c;
166  // I2C slave address
167  uint8_t slave_address;
169 } thermo30_t;
170 
175 typedef struct
176 {
177  pin_name_t scl;
178  pin_name_t sda;
180  pin_name_t rst;
181  pin_name_t alr;
183  uint32_t i2c_speed;
184  uint8_t i2c_address;
187 
192 typedef enum
193 {
195  THERMO30_ERROR = -1
196 
198 
215 
230 
244 
254 void thermo30_set_rst_pin ( thermo30_t *ctx, uint8_t pin_state );
255 
265 
275 
287 err_t thermo30_write_command ( thermo30_t *ctx, uint16_t cmd );
288 
303 err_t thermo30_read_command ( thermo30_t *ctx, uint16_t cmd, uint16_t *data_out );
304 
317 err_t thermo30_start_measurement ( thermo30_t *ctx, uint16_t cmd );
318 
330 
342 err_t thermo30_read_status ( thermo30_t *ctx, uint16_t *status_val );
343 
356 err_t thermo30_read_temperature ( thermo30_t *ctx, float *temperature );
357 
358 #ifdef __cplusplus
359 }
360 #endif
361 #endif // THERMO30_H
362  // thermo30
364 
365 // ------------------------------------------------------------------------ END
THERMO30_ERROR
@ THERMO30_ERROR
Definition: thermo30.h:195
thermo30_read_status
err_t thermo30_read_status(thermo30_t *ctx, uint16_t *status_val)
Thermo 30 read status function.
thermo30_t::slave_address
uint8_t slave_address
Definition: thermo30.h:167
thermo30_cfg_t::alr
pin_name_t alr
Definition: thermo30.h:181
thermo30_return_value_t
thermo30_return_value_t
Thermo 30 Click return value data.
Definition: thermo30.h:193
thermo30_stop_measurement
err_t thermo30_stop_measurement(thermo30_t *ctx)
Thermo 30 stop measurement function.
thermo30_get_alert_pin
uint8_t thermo30_get_alert_pin(thermo30_t *ctx)
Thermo 30 get alert pin function.
thermo30_start_measurement
err_t thermo30_start_measurement(thermo30_t *ctx, uint16_t cmd)
Thermo 30 start measurement function.
thermo30_read_command
err_t thermo30_read_command(thermo30_t *ctx, uint16_t cmd, uint16_t *data_out)
Thermo 30 read command function.
thermo30_hw_reset
void thermo30_hw_reset(thermo30_t *ctx)
Thermo 30 hw reset device function.
thermo30_t::rst
digital_out_t rst
Definition: thermo30.h:158
thermo30_set_rst_pin
void thermo30_set_rst_pin(thermo30_t *ctx, uint8_t pin_state)
Thermo 30 set rst pin function.
thermo30_cfg_t
Thermo 30 Click configuration object.
Definition: thermo30.h:176
thermo30_default_cfg
err_t thermo30_default_cfg(thermo30_t *ctx)
Thermo 30 default configuration function.
thermo30_cfg_t::i2c_address
uint8_t i2c_address
Definition: thermo30.h:184
thermo30_t::alr
digital_in_t alr
Definition: thermo30.h:161
thermo30_cfg_t::rst
pin_name_t rst
Definition: thermo30.h:180
thermo30_t
Thermo 30 Click context object.
Definition: thermo30.h:156
thermo30_cfg_t::sda
pin_name_t sda
Definition: thermo30.h:178
thermo30_cfg_t::scl
pin_name_t scl
Definition: thermo30.h:177
thermo30_t::i2c
i2c_master_t i2c
Definition: thermo30.h:164
thermo30_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: thermo30.h:183
thermo30_read_temperature
err_t thermo30_read_temperature(thermo30_t *ctx, float *temperature)
Thermo 30 read temperature function.
thermo30_cfg_setup
void thermo30_cfg_setup(thermo30_cfg_t *cfg)
Thermo 30 configuration object setup function.
THERMO30_OK
@ THERMO30_OK
Definition: thermo30.h:194
thermo30_write_command
err_t thermo30_write_command(thermo30_t *ctx, uint16_t cmd)
Thermo 30 write command function.
thermo30_init
err_t thermo30_init(thermo30_t *ctx, thermo30_cfg_t *cfg)
Thermo 30 initialization function.