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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_i2c_master.h"
50 #include "drv_spi_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
63 #define THERMO9_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
65  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
66  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
67  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
68  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
69  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
70 
76 #define THERMO9_MASTER_I2C 0
77 #define THERMO9_MASTER_SPI 1
78 
84 #define THERMO9_RETVAL uint8_t
85 
86 #define THERMO9_OK 0x00
87 #define THERMO9_INIT_ERROR 0xFF
88 
93 #define THERMO9_ADDR_VCC 0x76
94 #define THERMO9_ADDR_GND 0x77
95 
101 #define THERMO9_DUMMY_BYTE 0x00
102 #define THERMO9_RESET_CMD 0x1E
103 #define THERMO9_START_ADC_TEMP_CONV 0x48
104 #define THERMO9_READ_ADC_TEMP_RES 0x00
105 #define THERMO9_PROM_READ_ADR_0 0xA0
106 #define THERMO9_PROM_READ_ADR_1_COEF_K4 0xA2
107 #define THERMO9_PROM_READ_ADR_2_COEF_K3 0xA4
108 #define THERMO9_PROM_READ_ADR_3_COEF_K2 0xA6
109 #define THERMO9_PROM_READ_ADR_4_COEF_K1 0xA8
110 #define THERMO9_PROM_READ_ADR_5_COEF_K0 0xAA
111 #define THERMO9_PROM_READ_ADR_6_SN23_8 0xAC
112 #define THERMO9_PROM_READ_ADR_7_SN7_0_CHECKSUM 0xAE
113 
119 #define THERMO9_COEF_CALC_4_2 -2
120 #define THERMO9_COEF_CALC_3 4
121 #define THERMO9_COEF_CALC_0 -1.5
122 #define THERMO9_CALC_COEF_4 1000000000000000000000.0
123 #define THERMO9_CALC_COEF_3 10000000000000000.0
124 #define THERMO9_CALC_COEF_2 100000000000.0
125 #define THERMO9_CALC_COEF_1 1000000.0
126 #define THERMO9_CALC_COEF_0 100.0
127 #define THERMO9_RES_MOD 256.0
128  // End group macro
131 // --------------------------------------------------------------- PUBLIC TYPES
140 typedef uint8_t thermo9_select_t;
141 
145 typedef void ( *thermo9_master_io_t )( struct thermo9_s*, uint8_t, uint8_t*, uint8_t );
146 
150 typedef struct
151 {
152  uint16_t coef0;
153  uint16_t coef1;
154  uint16_t coef2;
155  uint16_t coef3;
156  uint16_t coef4;
157 
159 
163 typedef struct thermo9_s
164 {
165  // Output pins
166 
167  digital_out_t cs;
168 
169  // Modules
170 
171  i2c_master_t i2c;
172  spi_master_t spi;
173 
174  // ctx variable
175 
176  uint8_t slave_address;
177  pin_name_t chip_select;
181 
182  // Temperature calibration coefficient
183 
185 
187 
191 typedef struct
192 {
193  // Communication gpio pins
194 
195  pin_name_t scl;
196  pin_name_t sda;
197  pin_name_t miso;
198  pin_name_t mosi;
199  pin_name_t sck;
200  pin_name_t cs;
201 
202  // static variable
203 
204  uint32_t i2c_speed;
205  uint8_t i2c_address;
206 
207  uint32_t spi_speed;
208  spi_master_mode_t spi_mode;
209  spi_master_chip_select_polarity_t cs_polarity;
210 
212 
213 } thermo9_cfg_t;
214  // End types group
216 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
222 #ifdef __cplusplus
223 extern "C"{
224 #endif
225 
235 
245 
256 void thermo9_generic_write ( thermo9_t *ctx, uint8_t reg, uint8_t *data_buf,
257  uint8_t len );
258 
269 void thermo9_generic_read ( thermo9_t *ctx, uint8_t reg, uint8_t *data_buf,
270  uint8_t len );
271 
280 void thermo9_send_cmd ( thermo9_t *ctx, uint8_t cmd_byte );
281 
291 
302 
303 #ifdef __cplusplus
304 }
305 #endif
306 #endif // _THERMO9_H_
307  // End public_function group
310 
311 // ------------------------------------------------------------------------- END
thermo9_s::chip_select
pin_name_t chip_select
Definition: thermo9.h:177
thermo9_cfg_t::scl
pin_name_t scl
Definition: thermo9.h:195
thermo9_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: thermo9.h:209
thermo9_temp_coef_t
Temperature calibration coefficient.
Definition: thermo9.h:151
thermo9_s::spi
spi_master_t spi
Definition: thermo9.h:172
thermo9_cfg_t::sda
pin_name_t sda
Definition: thermo9.h:196
thermo9_master_io_t
void(* thermo9_master_io_t)(struct thermo9_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition: thermo9.h:145
thermo9_s::read_f
thermo9_master_io_t read_f
Definition: thermo9.h:179
thermo9_temp_coef_t::coef1
uint16_t coef1
Definition: thermo9.h:153
thermo9_s
Click ctx object definition.
Definition: thermo9.h:164
thermo9_cfg_t::i2c_address
uint8_t i2c_address
Definition: thermo9.h:205
thermo9_read_temp
float thermo9_read_temp(thermo9_t *ctx)
Read temperature function.
thermo9_cfg_t
Click configuration structure definition.
Definition: thermo9.h:192
thermo9_cfg_t::sck
pin_name_t sck
Definition: thermo9.h:199
thermo9_cfg_setup
void thermo9_cfg_setup(thermo9_cfg_t *cfg)
Config Object Initialization function.
thermo9_cfg_t::miso
pin_name_t miso
Definition: thermo9.h:197
thermo9_calibation
void thermo9_calibation(thermo9_t *ctx)
Calibration function.
thermo9_s::cs
digital_out_t cs
Definition: thermo9.h:167
thermo9_temp_coef_t::coef0
uint16_t coef0
Definition: thermo9.h:152
thermo9_cfg_t::sel
thermo9_select_t sel
Definition: thermo9.h:211
thermo9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: thermo9.h:204
thermo9_generic_read
void thermo9_generic_read(thermo9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
thermo9_temp_coef_t::coef4
uint16_t coef4
Definition: thermo9.h:156
thermo9_send_cmd
void thermo9_send_cmd(thermo9_t *ctx, uint8_t cmd_byte)
Send command function.
thermo9_temp_coef_t::coef3
uint16_t coef3
Definition: thermo9.h:155
thermo9_s::write_f
thermo9_master_io_t write_f
Definition: thermo9.h:178
thermo9_cfg_t::cs
pin_name_t cs
Definition: thermo9.h:200
thermo9_s::slave_address
uint8_t slave_address
Definition: thermo9.h:176
thermo9_temp_coef_t::coef2
uint16_t coef2
Definition: thermo9.h:154
thermo9_generic_write
void thermo9_generic_write(thermo9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
thermo9_s::temp_coef
thermo9_temp_coef_t temp_coef
Definition: thermo9.h:184
thermo9_s::i2c
i2c_master_t i2c
Definition: thermo9.h:171
thermo9_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: thermo9.h:208
thermo9_t
struct thermo9_s thermo9_t
Click ctx object definition.
thermo9_s::master_sel
thermo9_select_t master_sel
Definition: thermo9.h:180
thermo9_cfg_t::mosi
pin_name_t mosi
Definition: thermo9.h:198
thermo9_cfg_t::spi_speed
uint32_t spi_speed
Definition: thermo9.h:207
thermo9_select_t
uint8_t thermo9_select_t
Communication type.
Definition: thermo9.h:140
THERMO9_RETVAL
#define THERMO9_RETVAL
Definition: thermo9.h:84
thermo9_init
THERMO9_RETVAL thermo9_init(thermo9_t *ctx, thermo9_cfg_t *cfg)
Initialization function.