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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 #include "spi_specifics.h"
49 
70 #define TEMPPROBE_REG_COMM_STATUS 0x0000
71 #define TEMPPROBE_REG_THERMO_K_CONV_RES 0x0024
72 #define TEMPPROBE_REG_PN_JUNCTION_CONV_RES 0x0030
73 #define TEMPPROBE_REG_EEPROM_KEY 0x00B0
74 #define TEMPPROBE_REG_EEPROM_READ_RES_CODE 0x00D0
75 #define TEMPPROBE_REG_GLOBAL_CONFIG 0x00F0
76 #define TEMPPROBE_REG_MEAS_MULTIPLE_CHANN_MASK 0x00F4
77 #define TEMPPROBE_REG_EEPROM_STATUS 0x00F9
78 #define TEMPPROBE_REG_MUX_CONFIG_DELAY 0x00FF
79 #define TEMPPROBE_REG_THERMO_K_ASSIGN_DATA 0x0214
80 #define TEMPPROBE_REG_PN_JUNCTION_ASSIGN_DATA 0x0220
81 #define TEMPPROBE_REG_CUSTOM_SENS_TABLE_DATA 0x0250
82  // tempprobe_reg
84 
99 #define TEMPPROBE_TYPE_J_THERMOCOUPLE 0x08000000ul
100 #define TEMPPROBE_TYPE_K_THERMOCOUPLE 0x10000000ul
101 #define TEMPPROBE_TYPE_E_THERMOCOUPLE 0x18000000ul
102 #define TEMPPROBE_TYPE_N_THERMOCOUPLE 0x20000000ul
103 #define TEMPPROBE_TYPE_R_THERMOCOUPLE 0x28000000ul
104 #define TEMPPROBE_TYPE_S_THERMOCOUPLE 0x30000000ul
105 #define TEMPPROBE_TYPE_T_THERMOCOUPLE 0x38000000ul
106 #define TEMPPROBE_TYPE_B_THERMOCOUPLE 0x40000000ul
107 #define TEMPPROBE_CUSTOM_THERMOCOUPLE 0x48000000ul
108 
113 #define TEMPPROBE_CH1_COLD_JUNCTION 0x00400000ul
114 #define TEMPPROBE_CH2_COLD_JUNCTION 0x00800000ul
115 #define TEMPPROBE_CH3_COLD_JUNCTION 0x00C00000ul
116 #define TEMPPROBE_CH4_COLD_JUNCTION 0x01000000ul
117 #define TEMPPROBE_CH5_COLD_JUNCTION 0x01400000ul
118 #define TEMPPROBE_CH6_COLD_JUNCTION 0x01800000ul
119 #define TEMPPROBE_CH7_COLD_JUNCTION 0x01C00000ul
120 #define TEMPPROBE_CH8_COLD_JUNCTION 0x02000000ul
121 #define TEMPPROBE_CH9_COLD_JUNCTION 0x02400000ul
122 #define TEMPPROBE_CH10_COLD_JUNCTION 0x02800000ul
123 #define TEMPPROBE_NO_COLD_JUNCTION 0x00000000ul
124 
129 #define TEMPPROBE_DIFF_EXTERNAL_CURR 0x00000000ul
130 #define TEMPPROBE_DIFF_10MICROA_CURR 0x00100000ul
131 #define TEMPPROBE_DIFF_100MICROA_CURR 0x00140000ul
132 #define TEMPPROBE_DIFF_500MICROA_CURR 0x00180000ul
133 #define TEMPPROBE_DIFF_1MILIA_CURR 0x001C0000ul
134 #define TEMPPROBE_SINGLE_ENDED_EXT_CURR 0x00200000ul
135 #define TEMPPROBE_SINGLE_ENDED_10MICROA_CURR 0x00300000ul
136 #define TEMPPROBE_SINGLE_ENDED_100MICROA_CURR 0x00340000ul
137 #define TEMPPROBE_SINGLE_ENDED_500MICROA_CURR 0x00380000ul
138 #define TEMPPROBE_SINGLE_ENDED_1MILIA_CURR 0x003C0000ul
139 
144 #define TEMPPROBE_SENSE_RES_CH2_CH1 0x00800000ul
145 #define TEMPPROBE_SENSE_RES_CH3_CH2 0x00C00000ul
146 #define TEMPPROBE_SENSE_RES_CH4_CH3 0x01000000ul
147 #define TEMPPROBE_SENSE_RES_CH5_CH4 0x01400000ul
148 #define TEMPPROBE_SENSE_RES_CH6_CH5 0x01800000ul
149 #define TEMPPROBE_SENSE_RES_CH7_CH6 0x01C00000ul
150 #define TEMPPROBE_SENSE_RES_CH8_CH7 0x02000000ul
151 #define TEMPPROBE_SENSE_RES_CH9_CH8 0x02400000ul
152 #define TEMPPROBE_SENSE_RES_CH10_CH9 0x02800000ul
153 
158 #define TEMPPROBE_2_WIRE_GND_EXT 0x00000000ul
159 #define TEMPPROBE_2_WIRE_GND_INT 0x00040000ul
160 #define TEMPPROBE_3_WIRE_GND_EXT 0x00100000ul
161 #define TEMPPROBE_3_WIRE_GND_INT 0x00140000ul
162 #define TEMPPROBE_4_WIRE_GND_EXT 0x00200000ul
163 #define TEMPPROBE_4_WIRE_GND_INT 0x00240000ul
164 #define TEMPPROBE_4_WIRE_CURR_ROT 0x00280000ul
165 #define TEMPPROBE_4_WIRE_KELVIN_RSENSE_GND_EXT 0x00300000ul
166 #define TEMPPROBE_4_WIRE_KELVIN_RSENSE_GND_INT 0x00340000ul
167 #define TEMPPROBE_4_WIRE_KELVIN_RSENSE_CURR_ROT 0x00380000ul
168 
173 #define TEMPPROBE_EXTERNAL_CURR 0x00000000ul
174 #define TEMPPROBE_5MICROA_CURR 0x00004000ul
175 #define TEMPPROBE_10MICROA_CURR 0x00008000ul
176 #define TEMPPROBE_25MICROA_CURR 0x0000C000ul
177 #define TEMPPROBE_50MICROA_CURR 0x00010000ul
178 #define TEMPPROBE_100MICROA_CURR 0x00014000ul
179 #define TEMPPROBE_250MICROA_CURR 0x00018000ul
180 #define TEMPPROBE_500MICROA_CURR 0x0001C000ul
181 #define TEMPPROBE_1MILIA_CURR 0x00020000ul
182 
187 #define TEMPPROBE_EUROPEAN_CURVE 0x00000000ul
188 #define TEMPPROBE_AMERICAN_CURVE 0x00001000ul
189 #define TEMPPROBE_JAPANESE_CURVE 0x00002000ul
190 #define TEMPPROBE_ITS_90_CURVE 0x00003000ul
191 #define TEMPPROBE_OTHERS_CURVES 0x00000000ul
192 
197 #define TEMPPROBE_SENSE_RESISTOR 0xE8000000ul
198 #define TEMPPROBE_SENSE_RES_2K 0x001F4000ul
199 #define TEMPPROBE_SENSE_RES_10K2 0x009C40CDul
200 #define TEMPPROBE_SENSE_RES_1K 0x000FA933ul
201 
206 #define TEMPPROBE_DIODE 0xE0000000ul
207 #define TEMPPROBE_DIRECT_ADC 0xF0000000ul
208 #define TEMPPROBE_ANALOG_TEMP_SENS 0xF8000000ul
209 #define TEMPPROBE_DIODE_SNGL_END 0x04000000ul
210 #define TEMPPROBE_DIODE_DIFF 0x00000000ul
211 #define TEMPPROBE_DIODE_2_READ 0x00000000ul
212 #define TEMPPROBE_DIODE_3_READ 0x02000000ul
213 #define TEMPPROBE_DIODE_AVRG_ON 0x01000000ul
214 
219 #define TEMPPROBE_START_CONV 0x80
220 #define TEMPPROBE_INITIATE_SLEEP 0x97
221 #define TEMPPROBE_READ_EEPROM 0x96
222 #define TEMPPROBE_WRITE_EEPROM 0x95
223 
228 #define TEMPPROBE_FILTER_FREQ_55HZ 0x00
229 #define TEMPPROBE_FILTER_FREQ_60HZ 0x01
230 #define TEMPPROBE_FILTER_FREQ_50HZ 0x02
231 #define TEMPPROBE_CELSIUS 0x00
232 #define TEMPPROBE_FAHRENHEIT 0x04
233 #define TEMPPROBE_3_WIRE_RTD_KELVIN_CURR 0x10
234 #define TEMPPROBE_2_WIRE_RTD_KELVIN_CURR 0x20
235 #define TEMPPROBE_THERMISTOR_KELVIN_CURR 0x40
236 
241 #define TEMPPROBE_CH10_MASK 0x00000200ul
242 #define TEMPPROBE_CH9_MASK 0x00000100ul
243 #define TEMPPROBE_CH8_MASK 0x00000080ul
244 #define TEMPPROBE_CH7_MASK 0x00000040ul
245 #define TEMPPROBE_CH6_MASK 0x00000020ul
246 #define TEMPPROBE_CH5_MASK 0x00000010ul
247 #define TEMPPROBE_CH4_MASK 0x00000008ul
248 #define TEMPPROBE_CH3_MASK 0x00000004ul
249 #define TEMPPROBE_CH2_MASK 0x00000002ul
250 #define TEMPPROBE_CH1_MASK 0x00000001ul
251 #define TEMPPROBE_NO_CHANN_MASK 0x00000000ul
252 #define TEMPPROBE_ALL_CHANN_MASK 0x000003FFul
253 
254 #define TEMPPROBE_EEPROM_KEY 0xA53C0F5Aul
255 
260 #define TEMPPROBE_SPI_READ_INSTR 0x03
261 #define TEMPPROBE_SPI_WRITE_INSTR 0x02
262 
267 #define TEMPPROBE_REG_ADDR_ERROR 0x01
268 #define TEMPPROBE_NUM_BYTES_ERROR 0x02
269 #define TEMPPROBE_NO_ERROR 0x00
270 #define TEMPPROBE_BUSY_STATE 0x02
271 #define TEMPPROBE_NO_BUSY_STATE 0x01
272 #define TEMPPROBE_EEPROM_READ_PASS 0x00
273 #define TEMPPROBE_EEPROM_READ_FAIL 0xFF
274 #define TEMPPROBE_CHANN_SEL_ERROR 0xFF
275 
276 #define TEMPPROBE_PN_JUNCTION_DEF_CFG 0xE5000000
277 #define TEMPPROBE_GLOBAL_CONFIG_DEF_CFG 0x00000072
278 
279 
288 #define TEMPPROBE_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
289 #define TEMPPROBE_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
290  // tempprobe_set
292 
307 #define TEMPPROBE_MAP_MIKROBUS( cfg, mikrobus ) \
308  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
309  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
310  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
311  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
312  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
313  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
314  // tempprobe_map // tempprobe
317 
322 typedef struct
323 {
324  // Output pins
325  digital_out_t rst;
327  // Input pins
328  digital_in_t int_pin;
330  // Modules
331  spi_master_t spi;
333  pin_name_t chip_select;
336 } tempprobe_t;
337 
342 typedef struct
343 {
344  // Communication gpio pins
345  pin_name_t miso;
346  pin_name_t mosi;
347  pin_name_t sck;
348  pin_name_t cs;
350  // Additional gpio pins
351  pin_name_t rst;
352  pin_name_t int_pin;
354  // static variable
355  uint32_t spi_speed;
356  spi_master_mode_t spi_mode;
357  spi_master_chip_select_polarity_t cs_polarity;
360 
365 typedef enum
366 {
368  TEMPPROBE_ERROR = -1
369 
371 
388 
402 
416 
429 err_t tempprobe_write_byte ( tempprobe_t *ctx, uint16_t reg_addr, uint8_t data_in );
430 
443 err_t tempprobe_write_dword ( tempprobe_t *ctx, uint16_t reg_addr, uint32_t data_in );
444 
458 err_t tempprobe_read_bytes( tempprobe_t *ctx, uint16_t reg_addr, uint8_t *data_out, uint8_t n_bytes );
459 
472 err_t tempprobe_read_dword ( tempprobe_t *ctx, uint16_t reg_addr, uint32_t *data_out );
473 
483 
493 
503 
513 
523 uint8_t tempprobe_read_temp ( tempprobe_t *ctx, uint16_t sel_channel, float *data_out );
524 
525 #ifdef __cplusplus
526 }
527 #endif
528 #endif // TEMPPROBE_H
529  // tempprobe
531 
532 // ------------------------------------------------------------------------ END
tempprobe_cfg_t::int_pin
pin_name_t int_pin
Definition: tempprobe.h:352
tempprobe_init
err_t tempprobe_init(tempprobe_t *ctx, tempprobe_cfg_t *cfg)
Temp Probe initialization function.
tempprobe_read_dword
err_t tempprobe_read_dword(tempprobe_t *ctx, uint16_t reg_addr, uint32_t *data_out)
Word Read 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:345
TEMPPROBE_OK
@ TEMPPROBE_OK
Definition: tempprobe.h:367
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:328
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:355
tempprobe_t::chip_select
pin_name_t chip_select
Definition: tempprobe.h:333
tempprobe_write_eeprom_data
uint8_t tempprobe_write_eeprom_data(tempprobe_t *ctx)
EEPROM Write function.
tempprobe_cfg_t::sck
pin_name_t sck
Definition: tempprobe.h:347
tempprobe_cfg_t
Temp Probe Click configuration object.
Definition: tempprobe.h:343
tempprobe_write_dword
err_t tempprobe_write_dword(tempprobe_t *ctx, uint16_t reg_addr, uint32_t data_in)
Word Write function.
tempprobe_t
Temp Probe Click context object.
Definition: tempprobe.h:323
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:334
TEMPPROBE_ERROR
@ TEMPPROBE_ERROR
Definition: tempprobe.h:368
tempprobe_reset
void tempprobe_reset(tempprobe_t *ctx)
Reset function.
tempprobe_cfg_t::rst
pin_name_t rst
Definition: tempprobe.h:351
tempprobe_t::spi
spi_master_t spi
Definition: tempprobe.h:331
tempprobe_return_value_t
tempprobe_return_value_t
Temp Probe Click return value data.
Definition: tempprobe.h:366
tempprobe_cfg_t::cs
pin_name_t cs
Definition: tempprobe.h:348
tempprobe_write_byte
err_t tempprobe_write_byte(tempprobe_t *ctx, uint16_t reg_addr, uint8_t data_in)
Byte Write function.
tempprobe_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: tempprobe.h:357
tempprobe_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: tempprobe.h:356
tempprobe_cfg_setup
void tempprobe_cfg_setup(tempprobe_cfg_t *cfg)
Temp Probe configuration object setup 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:346
tempprobe_t::rst
digital_out_t rst
Definition: tempprobe.h:325