thermo9 2.0.0.0
thermo9.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef THERMO9_H
36#define THERMO9_H
37
38#include "drv_digital_out.h"
39#include "drv_i2c_master.h"
40#include "drv_spi_master.h"
41
42// -------------------------------------------------------------- PUBLIC MACROS
53#define THERMO9_MAP_MIKROBUS( cfg, mikrobus ) \
54 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
57 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
58 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
59 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
66#define THERMO9_MASTER_I2C 0
67#define THERMO9_MASTER_SPI 1
74#define THERMO9_RETVAL uint8_t
75
76#define THERMO9_OK 0x00
77#define THERMO9_INIT_ERROR 0xFF
83#define THERMO9_ADDR_VCC 0x76
84#define THERMO9_ADDR_GND 0x77
91#define THERMO9_DUMMY_BYTE 0x00
92#define THERMO9_RESET_CMD 0x1E
93#define THERMO9_START_ADC_TEMP_CONV 0x48
94#define THERMO9_READ_ADC_TEMP_RES 0x00
95#define THERMO9_PROM_READ_ADR_0 0xA0
96#define THERMO9_PROM_READ_ADR_1_COEF_K4 0xA2
97#define THERMO9_PROM_READ_ADR_2_COEF_K3 0xA4
98#define THERMO9_PROM_READ_ADR_3_COEF_K2 0xA6
99#define THERMO9_PROM_READ_ADR_4_COEF_K1 0xA8
100#define THERMO9_PROM_READ_ADR_5_COEF_K0 0xAA
101#define THERMO9_PROM_READ_ADR_6_SN23_8 0xAC
102#define THERMO9_PROM_READ_ADR_7_SN7_0_CHECKSUM 0xAE
109#define THERMO9_COEF_CALC_4_2 -2
110#define THERMO9_COEF_CALC_3 4
111#define THERMO9_COEF_CALC_0 -1.5
112#define THERMO9_CALC_COEF_4 1000000000000000000000.0
113#define THERMO9_CALC_COEF_3 10000000000000000.0
114#define THERMO9_CALC_COEF_2 100000000000.0
115#define THERMO9_CALC_COEF_1 1000000.0
116#define THERMO9_CALC_COEF_0 100.0
117#define THERMO9_RES_MOD 256.0 // End group macro
121// --------------------------------------------------------------- PUBLIC TYPES
130typedef uint8_t thermo9_select_t;
131
135typedef void ( *thermo9_master_io_t )( struct thermo9_s*, uint8_t, uint8_t*, uint8_t );
136
140typedef struct
141{
142 uint16_t coef0;
143 uint16_t coef1;
144 uint16_t coef2;
145 uint16_t coef3;
146 uint16_t coef4;
147
149
153typedef struct thermo9_s
154{
155 // Output pins
156
157 digital_out_t cs;
158
159 // Modules
160
161 i2c_master_t i2c;
162 spi_master_t spi;
163
164 // ctx variable
165
167 pin_name_t chip_select;
171
172 // Temperature calibration coefficient
173
175
177
181typedef struct
182{
183 // Communication gpio pins
184
185 pin_name_t scl;
186 pin_name_t sda;
187 pin_name_t miso;
188 pin_name_t mosi;
189 pin_name_t sck;
190 pin_name_t cs;
191
192 // static variable
193
194 uint32_t i2c_speed;
195 uint8_t i2c_address;
196
197 uint32_t spi_speed;
198 spi_master_mode_t spi_mode;
199 spi_master_chip_select_polarity_t cs_polarity;
200
202
204 // End types group
206// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
212#ifdef __cplusplus
213extern "C"{
214#endif
215
225
235
246void thermo9_generic_write ( thermo9_t *ctx, uint8_t reg, uint8_t *data_buf,
247 uint8_t len );
248
259void thermo9_generic_read ( thermo9_t *ctx, uint8_t reg, uint8_t *data_buf,
260 uint8_t len );
261
270void thermo9_send_cmd ( thermo9_t *ctx, uint8_t cmd_byte );
271
281
292
293#ifdef __cplusplus
294}
295#endif
296#endif // _THERMO9_H_
297 // End public_function group
300
301// ------------------------------------------------------------------------- END
#define THERMO9_RETVAL
Definition: thermo9.h:74
void thermo9_generic_write(thermo9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void thermo9_generic_read(thermo9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void thermo9_send_cmd(thermo9_t *ctx, uint8_t cmd_byte)
Send command function.
float thermo9_read_temp(thermo9_t *ctx)
Read temperature function.
THERMO9_RETVAL thermo9_init(thermo9_t *ctx, thermo9_cfg_t *cfg)
Initialization function.
void thermo9_cfg_setup(thermo9_cfg_t *cfg)
Config Object Initialization function.
void thermo9_calibation(thermo9_t *ctx)
Calibration function.
struct thermo9_s thermo9_t
Click ctx object definition.
uint8_t thermo9_select_t
Communication type.
Definition: thermo9.h:130
void(* thermo9_master_io_t)(struct thermo9_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition: thermo9.h:135
Click configuration structure definition.
Definition: thermo9.h:182
uint32_t i2c_speed
Definition: thermo9.h:194
spi_master_chip_select_polarity_t cs_polarity
Definition: thermo9.h:199
thermo9_select_t sel
Definition: thermo9.h:201
pin_name_t sck
Definition: thermo9.h:189
spi_master_mode_t spi_mode
Definition: thermo9.h:198
pin_name_t mosi
Definition: thermo9.h:188
uint32_t spi_speed
Definition: thermo9.h:197
pin_name_t scl
Definition: thermo9.h:185
pin_name_t miso
Definition: thermo9.h:187
pin_name_t sda
Definition: thermo9.h:186
pin_name_t cs
Definition: thermo9.h:190
uint8_t i2c_address
Definition: thermo9.h:195
Click ctx object definition.
Definition: thermo9.h:154
digital_out_t cs
Definition: thermo9.h:157
spi_master_t spi
Definition: thermo9.h:162
i2c_master_t i2c
Definition: thermo9.h:161
uint8_t slave_address
Definition: thermo9.h:166
thermo9_master_io_t read_f
Definition: thermo9.h:169
thermo9_temp_coef_t temp_coef
Definition: thermo9.h:174
pin_name_t chip_select
Definition: thermo9.h:167
thermo9_master_io_t write_f
Definition: thermo9.h:168
thermo9_select_t master_sel
Definition: thermo9.h:170
Temperature calibration coefficient.
Definition: thermo9.h:141
uint16_t coef4
Definition: thermo9.h:146
uint16_t coef2
Definition: thermo9.h:144
uint16_t coef3
Definition: thermo9.h:145
uint16_t coef1
Definition: thermo9.h:143
uint16_t coef0
Definition: thermo9.h:142