thermo20 2.0.0.0
thermo20.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 THERMO20_H
29#define THERMO20_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_i2c_master.h"
52
73#define THERMO20_CMD_RESET 0x1E
74#define THERMO20_CMD_READ_SERIAL_NUMBER 0x0A
75#define THERMO20_CMD_CONVERSION 0x46
76#define THERMO20_CMD_READ_ADC 0x00
77
78 // thermo20_reg
79
95#define THERMO20_SET_DEV_ADDR 0x40
96
97 // thermo20_set
98
113#define THERMO20_MAP_MIKROBUS( cfg, mikrobus ) \
114 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
115 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
116
117 // thermo20_map
118 // thermo20
119
124typedef struct
125{
126 // Modules
127 i2c_master_t i2c;
129 // I2C slave address
132} thermo20_t;
133
138typedef struct
139{
140 pin_name_t scl;
141 pin_name_t sda;
143 uint32_t i2c_speed;
144 uint8_t i2c_address;
147
152typedef enum
153{
155 THERMO20_ERROR = -1
156
158
175
191
206
222err_t thermo20_generic_write ( thermo20_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
223
239err_t thermo20_generic_read ( thermo20_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
240
253err_t thermo20_set_cmd ( thermo20_t *ctx, uint8_t cmd );
254
264
276
286
296
306
307#ifdef __cplusplus
308}
309#endif
310#endif // THERMO20_H
311
312 // thermo20
313
314// ------------------------------------------------------------------------ END
uint16_t thermo20_read_adc(thermo20_t *ctx)
Read ADC data function.
void thermo20_start_conversion(thermo20_t *ctx)
Start conversion function.
void thermo20_cfg_setup(thermo20_cfg_t *cfg)
Thermo 20 configuration object setup function.
err_t thermo20_generic_read(thermo20_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Thermo 20 I2C reading function.
err_t thermo20_generic_write(thermo20_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Thermo 20 I2C writing function.
uint32_t thermo20_get_serial_number(thermo20_t *ctx)
Get serial number function.
void thermo20_soft_reset(thermo20_t *ctx)
Soft reset function.
err_t thermo20_init(thermo20_t *ctx, thermo20_cfg_t *cfg)
Thermo 20 initialization function.
err_t thermo20_default_cfg(thermo20_t *ctx)
Thermo 20 default configuration function.
err_t thermo20_set_cmd(thermo20_t *ctx, uint8_t cmd)
Send command function.
float thermo20_get_temperature(thermo20_t *ctx)
Get temperature data function.
Thermo 20 Click configuration object.
Definition thermo20.h:139
uint32_t i2c_speed
Definition thermo20.h:143
pin_name_t scl
Definition thermo20.h:140
pin_name_t sda
Definition thermo20.h:141
uint8_t i2c_address
Definition thermo20.h:144
Thermo 20 Click context object.
Definition thermo20.h:125
i2c_master_t i2c
Definition thermo20.h:127
uint8_t slave_address
Definition thermo20.h:130
thermo20_return_value_t
Thermo 20 Click return value data.
Definition thermo20.h:153
@ THERMO20_ERROR
Definition thermo20.h:155
@ THERMO20_OK
Definition thermo20.h:154