tempprobe  2.0.0.0
tempprobe.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 TEMPPROBE_H
29 #define TEMPPROBE_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 
60 #define TEMPPROBE_REG_COMM_STATUS 0x0000
61 #define TEMPPROBE_REG_THERMO_K_CONV_RES 0x0024
62 #define TEMPPROBE_REG_PN_JUNCTION_CONV_RES 0x0030
63 #define TEMPPROBE_REG_EEPROM_KEY 0x00B0
64 #define TEMPPROBE_REG_EEPROM_READ_RES_CODE 0x00D0
65 #define TEMPPROBE_REG_GLOBAL_CONFIG 0x00F0
66 #define TEMPPROBE_REG_MEAS_MULTIPLE_CHANN_MASK 0x00F4
67 #define TEMPPROBE_REG_EEPROM_STATUS 0x00F9
68 #define TEMPPROBE_REG_MUX_CONFIG_DELAY 0x00FF
69 #define TEMPPROBE_REG_THERMO_K_ASSIGN_DATA 0x0214
70 #define TEMPPROBE_REG_PN_JUNCTION_ASSIGN_DATA 0x0220
71 #define TEMPPROBE_REG_CUSTOM_SENS_TABLE_DATA 0x0250
72  // tempprobe_reg
74 
94 #define TEMPPROBE_TYPE_J_THERMOCOUPLE 0x08000000
95 #define TEMPPROBE_TYPE_K_THERMOCOUPLE 0x10000000
96 #define TEMPPROBE_TYPE_E_THERMOCOUPLE 0x18000000
97 #define TEMPPROBE_TYPE_N_THERMOCOUPLE 0x20000000
98 #define TEMPPROBE_TYPE_R_THERMOCOUPLE 0x28000000
99 #define TEMPPROBE_TYPE_S_THERMOCOUPLE 0x30000000
100 #define TEMPPROBE_TYPE_T_THERMOCOUPLE 0x38000000
101 #define TEMPPROBE_TYPE_B_THERMOCOUPLE 0x40000000
102 #define TEMPPROBE_CUSTOM_THERMOCOUPLE 0x48000000
103 
108 #define TEMPPROBE_CH1_COLD_JUNCTION 0x00400000
109 #define TEMPPROBE_CH2_COLD_JUNCTION 0x00800000
110 #define TEMPPROBE_CH3_COLD_JUNCTION 0x00C00000
111 #define TEMPPROBE_CH4_COLD_JUNCTION 0x01000000
112 #define TEMPPROBE_CH5_COLD_JUNCTION 0x01400000
113 #define TEMPPROBE_CH6_COLD_JUNCTION 0x01800000
114 #define TEMPPROBE_CH7_COLD_JUNCTION 0x01C00000
115 #define TEMPPROBE_CH8_COLD_JUNCTION 0x02000000
116 #define TEMPPROBE_CH9_COLD_JUNCTION 0x02400000
117 #define TEMPPROBE_CH10_COLD_JUNCTION 0x02800000
118 #define TEMPPROBE_NO_COLD_JUNCTION 0x00000000
119 
124 #define TEMPPROBE_DIFF_EXTERNAL_CURR 0x00000000
125 #define TEMPPROBE_DIFF_10MICROA_CURR 0x00100000
126 #define TEMPPROBE_DIFF_100MICROA_CURR 0x00140000
127 #define TEMPPROBE_DIFF_500MICROA_CURR 0x00180000
128 #define TEMPPROBE_DIFF_1MILIA_CURR 0x001C0000
129 #define TEMPPROBE_SINGLE_ENDED_EXT_CURR 0x00200000
130 #define TEMPPROBE_SINGLE_ENDED_10MICROA_CURR 0x00300000
131 #define TEMPPROBE_SINGLE_ENDED_100MICROA_CURR 0x00340000
132 #define TEMPPROBE_SINGLE_ENDED_500MICROA_CURR 0x00380000
133 #define TEMPPROBE_SINGLE_ENDED_1MILIA_CURR 0x003C0000
134 
139 #define TEMPPROBE_SENSE_RES_CH2_CH1 0x00800000
140 #define TEMPPROBE_SENSE_RES_CH3_CH2 0x00C00000
141 #define TEMPPROBE_SENSE_RES_CH4_CH3 0x01000000
142 #define TEMPPROBE_SENSE_RES_CH5_CH4 0x01400000
143 #define TEMPPROBE_SENSE_RES_CH6_CH5 0x01800000
144 #define TEMPPROBE_SENSE_RES_CH7_CH6 0x01C00000
145 #define TEMPPROBE_SENSE_RES_CH8_CH7 0x02000000
146 #define TEMPPROBE_SENSE_RES_CH9_CH8 0x02400000
147 #define TEMPPROBE_SENSE_RES_CH10_CH9 0x02800000
148 
153 #define TEMPPROBE_2_WIRE_GND_EXT 0x00000000
154 #define TEMPPROBE_2_WIRE_GND_INT 0x00040000
155 #define TEMPPROBE_3_WIRE_GND_EXT 0x00100000
156 #define TEMPPROBE_3_WIRE_GND_INT 0x00140000
157 #define TEMPPROBE_4_WIRE_GND_EXT 0x00200000
158 #define TEMPPROBE_4_WIRE_GND_INT 0x00240000
159 #define TEMPPROBE_4_WIRE_CURR_ROT 0x00280000
160 #define TEMPPROBE_4_WIRE_KELVIN_RSENSE_GND_EXT 0x00300000
161 #define TEMPPROBE_4_WIRE_KELVIN_RSENSE_GND_INT 0x00340000
162 #define TEMPPROBE_4_WIRE_KELVIN_RSENSE_CURR_ROT 0x00380000
163 
168 #define TEMPPROBE_EXTERNAL_CURR 0x00000000
169 #define TEMPPROBE_5MICROA_CURR 0x00004000
170 #define TEMPPROBE_10MICROA_CURR 0x00008000
171 #define TEMPPROBE_25MICROA_CURR 0x0000C000
172 #define TEMPPROBE_50MICROA_CURR 0x00010000
173 #define TEMPPROBE_100MICROA_CURR 0x00014000
174 #define TEMPPROBE_250MICROA_CURR 0x00018000
175 #define TEMPPROBE_500MICROA_CURR 0x0001C000
176 #define TEMPPROBE_1MILIA_CURR 0x00020000
177 
182 #define TEMPPROBE_EUROPEAN_CURVE 0x00000000
183 #define TEMPPROBE_AMERICAN_CURVE 0x00001000
184 #define TEMPPROBE_JAPANESE_CURVE 0x00002000
185 #define TEMPPROBE_ITS_90_CURVE 0x00003000
186 #define TEMPPROBE_OTHERS_CURVES 0x00000000
187 
192 #define TEMPPROBE_SENSE_RESISTOR 0xE8000000
193 #define TEMPPROBE_SENSE_RES_2K 0x001F4000
194 #define TEMPPROBE_SENSE_RES_10K2 0x009C40CD
195 #define TEMPPROBE_SENSE_RES_1K 0x000FA933
196 
201 #define TEMPPROBE_DIODE 0xE0000000
202 #define TEMPPROBE_DIRECT_ADC 0xF0000000
203 #define TEMPPROBE_ANALOG_TEMP_SENS 0xF8000000
204 #define TEMPPROBE_DIODE_SNGL_END 0x04000000
205 #define TEMPPROBE_DIODE_DIFF 0x00000000
206 #define TEMPPROBE_DIODE_2_READ 0x00000000
207 #define TEMPPROBE_DIODE_3_READ 0x02000000
208 #define TEMPPROBE_DIODE_AVRG_ON 0x01000000
209 
214 #define TEMPPROBE_START_CONV 0x80
215 #define TEMPPROBE_INITIATE_SLEEP 0x97
216 #define TEMPPROBE_READ_EEPROM 0x96
217 #define TEMPPROBE_WRITE_EEPROM 0x95
218 
223 #define TEMPPROBE_FILTER_FREQ_55HZ 0x00
224 #define TEMPPROBE_FILTER_FREQ_60HZ 0x01
225 #define TEMPPROBE_FILTER_FREQ_50HZ 0x02
226 #define TEMPPROBE_CELSIUS 0x00
227 #define TEMPPROBE_FAHRENHEIT 0x04
228 #define TEMPPROBE_3_WIRE_RTD_KELVIN_CURR 0x10
229 #define TEMPPROBE_2_WIRE_RTD_KELVIN_CURR 0x20
230 #define TEMPPROBE_THERMISTOR_KELVIN_CURR 0x40
231 
236 #define TEMPPROBE_CH10_MASK 0x00000200
237 #define TEMPPROBE_CH9_MASK 0x00000100
238 #define TEMPPROBE_CH8_MASK 0x00000080
239 #define TEMPPROBE_CH7_MASK 0x00000040
240 #define TEMPPROBE_CH6_MASK 0x00000020
241 #define TEMPPROBE_CH5_MASK 0x00000010
242 #define TEMPPROBE_CH4_MASK 0x00000008
243 #define TEMPPROBE_CH3_MASK 0x00000004
244 #define TEMPPROBE_CH2_MASK 0x00000002
245 #define TEMPPROBE_CH1_MASK 0x00000001
246 #define TEMPPROBE_NO_CHANN_MASK 0x00000000
247 #define TEMPPROBE_ALL_CHANN_MASK 0x000003FF
248 
249 #define TEMPPROBE_EEPROM_KEY 0xA53C0F5A
250 
255 #define TEMPPROBE_SPI_READ_INSTR 0x03
256 #define TEMPPROBE_SPI_WRITE_INSTR 0x02
257 
262 #define TEMPPROBE_REG_ADDR_ERROR 0x01
263 #define TEMPPROBE_NUM_BYTES_ERROR 0x02
264 #define TEMPPROBE_NO_ERROR 0x00
265 #define TEMPPROBE_BUSY_STATE 0x02
266 #define TEMPPROBE_NO_BUSY_STATE 0x01
267 #define TEMPPROBE_EEPROM_READ_PASS 0x00
268 #define TEMPPROBE_EEPROM_READ_FAIL 0xFF
269 #define TEMPPROBE_CHANN_SEL_ERROR 0xFF
270 
271 #define TEMPPROBE_PN_JUNCTION_DEF_CFG 0xE5000000
272 #define TEMPPROBE_GLOBAL_CONFIG_DEF_CFG 0x00000072
273 
274 
283 #define TEMPPROBE_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
284 #define TEMPPROBE_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
285  // tempprobe_set
287 
302 #define TEMPPROBE_MAP_MIKROBUS( cfg, mikrobus ) \
303  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
304  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
305  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
306  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
307  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
308  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
309  // tempprobe_map // tempprobe
312 
317 typedef struct
318 {
319  // Output pins
320  digital_out_t rst;
322  // Input pins
323  digital_in_t int_pin;
325  // Modules
326  spi_master_t spi;
328  pin_name_t chip_select;
331 } tempprobe_t;
332 
337 typedef struct
338 {
339  // Communication gpio pins
340  pin_name_t miso;
341  pin_name_t mosi;
342  pin_name_t sck;
343  pin_name_t cs;
345  // Additional gpio pins
346  pin_name_t rst;
347  pin_name_t int_pin;
349  // static variable
350  uint32_t spi_speed;
351  spi_master_mode_t spi_mode;
352  spi_master_chip_select_polarity_t cs_polarity;
355 
360 typedef enum
361 {
364 
366 
383 
397 err_t tempprobe_init ( tempprobe_t *ctx, tempprobe_cfg_t *cfg );
398 
412 err_t tempprobe_default_cfg ( tempprobe_t *ctx );
413 
428 err_t tempprobe_generic_write ( tempprobe_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
429 
444 err_t tempprobe_generic_read ( tempprobe_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
445 
459 err_t tempprobe_write_byte ( tempprobe_t *ctx, uint16_t reg_addr, uint8_t data_in );
460 
474 err_t tempprobe_write_word ( tempprobe_t *ctx, uint16_t reg_addr, uint32_t data_in );
475 
489 err_t tempprobe_read_bytes( tempprobe_t *ctx, uint16_t reg_addr, uint8_t *data_out, uint8_t n_bytes );
490 
504 uint8_t tempprobe_read_word ( tempprobe_t *ctx, uint16_t reg_addr, uint32_t *data_out );
505 
514 uint8_t tempprobe_check_busy ( tempprobe_t *ctx );
515 
524 void tempprobe_reset( tempprobe_t *ctx );
525 
535 
544 uint8_t tempprobe_read_eeprom_data ( tempprobe_t *ctx );
545 
555 uint8_t tempprobe_read_temp ( tempprobe_t *ctx, uint16_t sel_channel, float *data_out );
556 
557 #ifdef __cplusplus
558 }
559 #endif
560 #endif // TEMPPROBE_H
561  // tempprobe
563 
564 // ------------------------------------------------------------------------ END
tempprobe_cfg_t::int_pin
pin_name_t int_pin
Definition: tempprobe.h:347
tempprobe_init
err_t tempprobe_init(tempprobe_t *ctx, tempprobe_cfg_t *cfg)
Temp Probe initialization function.
tempprobe_read_eeprom_data
uint8_t tempprobe_read_eeprom_data(tempprobe_t *ctx)
EEPROM Read function.
tempprobe_cfg_t::miso
pin_name_t miso
Definition: tempprobe.h:340
TEMPPROBE_OK
Definition: tempprobe.h:362
tempprobe_read_bytes
err_t tempprobe_read_bytes(tempprobe_t *ctx, uint16_t reg_addr, uint8_t *data_out, uint8_t n_bytes)
Byte Read function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
tempprobe_t::int_pin
digital_in_t int_pin
Definition: tempprobe.h:323
tempprobe_read_temp
uint8_t tempprobe_read_temp(tempprobe_t *ctx, uint16_t sel_channel, float *data_out)
Temperature Read function.
tempprobe_cfg_t::spi_speed
uint32_t spi_speed
Definition: tempprobe.h:350
tempprobe_t::chip_select
pin_name_t chip_select
Definition: tempprobe.h:328
tempprobe_write_eeprom_data
uint8_t tempprobe_write_eeprom_data(tempprobe_t *ctx)
EEPROM Write function.
tempprobe_read_word
uint8_t tempprobe_read_word(tempprobe_t *ctx, uint16_t reg_addr, uint32_t *data_out)
Word Read function.
tempprobe_cfg_t::sck
pin_name_t sck
Definition: tempprobe.h:342
tempprobe_cfg_t
Temp Probe Click configuration object.
Definition: tempprobe.h:337
tempprobe_t
Temp Probe Click context object.
Definition: tempprobe.h:317
tempprobe_default_cfg
err_t tempprobe_default_cfg(tempprobe_t *ctx)
Temp Probe default configuration function.
tempprobe_t::drv_temperature_format
uint8_t drv_temperature_format
Definition: tempprobe.h:329
TEMPPROBE_ERROR
Definition: tempprobe.h:363
tempprobe_reset
void tempprobe_reset(tempprobe_t *ctx)
Reset function.
tempprobe_cfg_t::rst
pin_name_t rst
Definition: tempprobe.h:346
tempprobe_generic_write
err_t tempprobe_generic_write(tempprobe_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Temp Probe data writing function.
tempprobe_t::spi
spi_master_t spi
Definition: tempprobe.h:326
tempprobe_return_value_t
tempprobe_return_value_t
Temp Probe Click return value data.
Definition: tempprobe.h:360
tempprobe_cfg_t::cs
pin_name_t cs
Definition: tempprobe.h:343
tempprobe_write_byte
err_t tempprobe_write_byte(tempprobe_t *ctx, uint16_t reg_addr, uint8_t data_in)
Byte Write function.
tempprobe_generic_read
err_t tempprobe_generic_read(tempprobe_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Temp Probe data reading function.
tempprobe_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: tempprobe.h:352
tempprobe_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: tempprobe.h:351
tempprobe_cfg_setup
void tempprobe_cfg_setup(tempprobe_cfg_t *cfg)
Temp Probe configuration object setup function.
tempprobe_write_word
err_t tempprobe_write_word(tempprobe_t *ctx, uint16_t reg_addr, uint32_t data_in)
Word Write function.
tempprobe_check_busy
uint8_t tempprobe_check_busy(tempprobe_t *ctx)
Busy Check function.
tempprobe_cfg_t::mosi
pin_name_t mosi
Definition: tempprobe.h:341
tempprobe_t::rst
digital_out_t rst
Definition: tempprobe.h:320