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
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_spi_master.h"
52#include "spi_specifics.h"
53
74#define TEMPPROBE_REG_COMM_STATUS 0x0000
75#define TEMPPROBE_REG_THERMO_K_CONV_RES 0x0024
76#define TEMPPROBE_REG_PN_JUNCTION_CONV_RES 0x0030
77#define TEMPPROBE_REG_EEPROM_KEY 0x00B0
78#define TEMPPROBE_REG_EEPROM_READ_RES_CODE 0x00D0
79#define TEMPPROBE_REG_GLOBAL_CONFIG 0x00F0
80#define TEMPPROBE_REG_MEAS_MULTIPLE_CHANN_MASK 0x00F4
81#define TEMPPROBE_REG_EEPROM_STATUS 0x00F9
82#define TEMPPROBE_REG_MUX_CONFIG_DELAY 0x00FF
83#define TEMPPROBE_REG_THERMO_K_ASSIGN_DATA 0x0214
84#define TEMPPROBE_REG_PN_JUNCTION_ASSIGN_DATA 0x0220
85#define TEMPPROBE_REG_CUSTOM_SENS_TABLE_DATA 0x0250
86
87 // tempprobe_reg
88
103#define TEMPPROBE_TYPE_J_THERMOCOUPLE 0x08000000ul
104#define TEMPPROBE_TYPE_K_THERMOCOUPLE 0x10000000ul
105#define TEMPPROBE_TYPE_E_THERMOCOUPLE 0x18000000ul
106#define TEMPPROBE_TYPE_N_THERMOCOUPLE 0x20000000ul
107#define TEMPPROBE_TYPE_R_THERMOCOUPLE 0x28000000ul
108#define TEMPPROBE_TYPE_S_THERMOCOUPLE 0x30000000ul
109#define TEMPPROBE_TYPE_T_THERMOCOUPLE 0x38000000ul
110#define TEMPPROBE_TYPE_B_THERMOCOUPLE 0x40000000ul
111#define TEMPPROBE_CUSTOM_THERMOCOUPLE 0x48000000ul
112
117#define TEMPPROBE_CH1_COLD_JUNCTION 0x00400000ul
118#define TEMPPROBE_CH2_COLD_JUNCTION 0x00800000ul
119#define TEMPPROBE_CH3_COLD_JUNCTION 0x00C00000ul
120#define TEMPPROBE_CH4_COLD_JUNCTION 0x01000000ul
121#define TEMPPROBE_CH5_COLD_JUNCTION 0x01400000ul
122#define TEMPPROBE_CH6_COLD_JUNCTION 0x01800000ul
123#define TEMPPROBE_CH7_COLD_JUNCTION 0x01C00000ul
124#define TEMPPROBE_CH8_COLD_JUNCTION 0x02000000ul
125#define TEMPPROBE_CH9_COLD_JUNCTION 0x02400000ul
126#define TEMPPROBE_CH10_COLD_JUNCTION 0x02800000ul
127#define TEMPPROBE_NO_COLD_JUNCTION 0x00000000ul
128
133#define TEMPPROBE_DIFF_EXTERNAL_CURR 0x00000000ul
134#define TEMPPROBE_DIFF_10MICROA_CURR 0x00100000ul
135#define TEMPPROBE_DIFF_100MICROA_CURR 0x00140000ul
136#define TEMPPROBE_DIFF_500MICROA_CURR 0x00180000ul
137#define TEMPPROBE_DIFF_1MILIA_CURR 0x001C0000ul
138#define TEMPPROBE_SINGLE_ENDED_EXT_CURR 0x00200000ul
139#define TEMPPROBE_SINGLE_ENDED_10MICROA_CURR 0x00300000ul
140#define TEMPPROBE_SINGLE_ENDED_100MICROA_CURR 0x00340000ul
141#define TEMPPROBE_SINGLE_ENDED_500MICROA_CURR 0x00380000ul
142#define TEMPPROBE_SINGLE_ENDED_1MILIA_CURR 0x003C0000ul
143
148#define TEMPPROBE_SENSE_RES_CH2_CH1 0x00800000ul
149#define TEMPPROBE_SENSE_RES_CH3_CH2 0x00C00000ul
150#define TEMPPROBE_SENSE_RES_CH4_CH3 0x01000000ul
151#define TEMPPROBE_SENSE_RES_CH5_CH4 0x01400000ul
152#define TEMPPROBE_SENSE_RES_CH6_CH5 0x01800000ul
153#define TEMPPROBE_SENSE_RES_CH7_CH6 0x01C00000ul
154#define TEMPPROBE_SENSE_RES_CH8_CH7 0x02000000ul
155#define TEMPPROBE_SENSE_RES_CH9_CH8 0x02400000ul
156#define TEMPPROBE_SENSE_RES_CH10_CH9 0x02800000ul
157
162#define TEMPPROBE_2_WIRE_GND_EXT 0x00000000ul
163#define TEMPPROBE_2_WIRE_GND_INT 0x00040000ul
164#define TEMPPROBE_3_WIRE_GND_EXT 0x00100000ul
165#define TEMPPROBE_3_WIRE_GND_INT 0x00140000ul
166#define TEMPPROBE_4_WIRE_GND_EXT 0x00200000ul
167#define TEMPPROBE_4_WIRE_GND_INT 0x00240000ul
168#define TEMPPROBE_4_WIRE_CURR_ROT 0x00280000ul
169#define TEMPPROBE_4_WIRE_KELVIN_RSENSE_GND_EXT 0x00300000ul
170#define TEMPPROBE_4_WIRE_KELVIN_RSENSE_GND_INT 0x00340000ul
171#define TEMPPROBE_4_WIRE_KELVIN_RSENSE_CURR_ROT 0x00380000ul
172
177#define TEMPPROBE_EXTERNAL_CURR 0x00000000ul
178#define TEMPPROBE_5MICROA_CURR 0x00004000ul
179#define TEMPPROBE_10MICROA_CURR 0x00008000ul
180#define TEMPPROBE_25MICROA_CURR 0x0000C000ul
181#define TEMPPROBE_50MICROA_CURR 0x00010000ul
182#define TEMPPROBE_100MICROA_CURR 0x00014000ul
183#define TEMPPROBE_250MICROA_CURR 0x00018000ul
184#define TEMPPROBE_500MICROA_CURR 0x0001C000ul
185#define TEMPPROBE_1MILIA_CURR 0x00020000ul
186
191#define TEMPPROBE_EUROPEAN_CURVE 0x00000000ul
192#define TEMPPROBE_AMERICAN_CURVE 0x00001000ul
193#define TEMPPROBE_JAPANESE_CURVE 0x00002000ul
194#define TEMPPROBE_ITS_90_CURVE 0x00003000ul
195#define TEMPPROBE_OTHERS_CURVES 0x00000000ul
196
201#define TEMPPROBE_SENSE_RESISTOR 0xE8000000ul
202#define TEMPPROBE_SENSE_RES_2K 0x001F4000ul
203#define TEMPPROBE_SENSE_RES_10K2 0x009C40CDul
204#define TEMPPROBE_SENSE_RES_1K 0x000FA933ul
205
210#define TEMPPROBE_DIODE 0xE0000000ul
211#define TEMPPROBE_DIRECT_ADC 0xF0000000ul
212#define TEMPPROBE_ANALOG_TEMP_SENS 0xF8000000ul
213#define TEMPPROBE_DIODE_SNGL_END 0x04000000ul
214#define TEMPPROBE_DIODE_DIFF 0x00000000ul
215#define TEMPPROBE_DIODE_2_READ 0x00000000ul
216#define TEMPPROBE_DIODE_3_READ 0x02000000ul
217#define TEMPPROBE_DIODE_AVRG_ON 0x01000000ul
218
223#define TEMPPROBE_START_CONV 0x80
224#define TEMPPROBE_INITIATE_SLEEP 0x97
225#define TEMPPROBE_READ_EEPROM 0x96
226#define TEMPPROBE_WRITE_EEPROM 0x95
227
232#define TEMPPROBE_FILTER_FREQ_55HZ 0x00
233#define TEMPPROBE_FILTER_FREQ_60HZ 0x01
234#define TEMPPROBE_FILTER_FREQ_50HZ 0x02
235#define TEMPPROBE_CELSIUS 0x00
236#define TEMPPROBE_FAHRENHEIT 0x04
237#define TEMPPROBE_3_WIRE_RTD_KELVIN_CURR 0x10
238#define TEMPPROBE_2_WIRE_RTD_KELVIN_CURR 0x20
239#define TEMPPROBE_THERMISTOR_KELVIN_CURR 0x40
240
245#define TEMPPROBE_CH10_MASK 0x00000200ul
246#define TEMPPROBE_CH9_MASK 0x00000100ul
247#define TEMPPROBE_CH8_MASK 0x00000080ul
248#define TEMPPROBE_CH7_MASK 0x00000040ul
249#define TEMPPROBE_CH6_MASK 0x00000020ul
250#define TEMPPROBE_CH5_MASK 0x00000010ul
251#define TEMPPROBE_CH4_MASK 0x00000008ul
252#define TEMPPROBE_CH3_MASK 0x00000004ul
253#define TEMPPROBE_CH2_MASK 0x00000002ul
254#define TEMPPROBE_CH1_MASK 0x00000001ul
255#define TEMPPROBE_NO_CHANN_MASK 0x00000000ul
256#define TEMPPROBE_ALL_CHANN_MASK 0x000003FFul
257
258#define TEMPPROBE_EEPROM_KEY 0xA53C0F5Aul
259
264#define TEMPPROBE_SPI_READ_INSTR 0x03
265#define TEMPPROBE_SPI_WRITE_INSTR 0x02
266
271#define TEMPPROBE_REG_ADDR_ERROR 0x01
272#define TEMPPROBE_NUM_BYTES_ERROR 0x02
273#define TEMPPROBE_NO_ERROR 0x00
274#define TEMPPROBE_BUSY_STATE 0x02
275#define TEMPPROBE_NO_BUSY_STATE 0x01
276#define TEMPPROBE_EEPROM_READ_PASS 0x00
277#define TEMPPROBE_EEPROM_READ_FAIL 0xFF
278#define TEMPPROBE_CHANN_SEL_ERROR 0xFF
279
280#define TEMPPROBE_PN_JUNCTION_DEF_CFG 0xE5000000
281#define TEMPPROBE_GLOBAL_CONFIG_DEF_CFG 0x00000072
282
283
292#define TEMPPROBE_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
293#define TEMPPROBE_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
294
295 // tempprobe_set
296
311#define TEMPPROBE_MAP_MIKROBUS( cfg, mikrobus ) \
312 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
313 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
314 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
315 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
316 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
317 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
318
319 // tempprobe_map
320 // tempprobe
321
326typedef struct
327{
328 // Output pins
329 digital_out_t rst;
331 // Input pins
332 digital_in_t int_pin;
334 // Modules
335 spi_master_t spi;
337 pin_name_t chip_select;
341
346typedef struct
347{
348 // Communication gpio pins
349 pin_name_t miso;
350 pin_name_t mosi;
351 pin_name_t sck;
352 pin_name_t cs;
354 // Additional gpio pins
355 pin_name_t rst;
356 pin_name_t int_pin;
358 // static variable
359 uint32_t spi_speed;
360 spi_master_mode_t spi_mode;
361 spi_master_chip_select_polarity_t cs_polarity;
364
375
392
406
420
433err_t tempprobe_write_byte ( tempprobe_t *ctx, uint16_t reg_addr, uint8_t data_in );
434
447err_t tempprobe_write_dword ( tempprobe_t *ctx, uint16_t reg_addr, uint32_t data_in );
448
462err_t tempprobe_read_bytes( tempprobe_t *ctx, uint16_t reg_addr, uint8_t *data_out, uint8_t n_bytes );
463
476err_t tempprobe_read_dword ( tempprobe_t *ctx, uint16_t reg_addr, uint32_t *data_out );
477
487
497
507
517
527uint8_t tempprobe_read_temp ( tempprobe_t *ctx, uint16_t sel_channel, float *data_out );
528
529#ifdef __cplusplus
530}
531#endif
532#endif // TEMPPROBE_H
533
534 // tempprobe
535
536// ------------------------------------------------------------------------ END
err_t tempprobe_read_bytes(tempprobe_t *ctx, uint16_t reg_addr, uint8_t *data_out, uint8_t n_bytes)
Byte Read function.
void tempprobe_cfg_setup(tempprobe_cfg_t *cfg)
Temp Probe configuration object setup function.
uint8_t tempprobe_read_eeprom_data(tempprobe_t *ctx)
EEPROM Read function.
uint8_t tempprobe_read_temp(tempprobe_t *ctx, uint16_t sel_channel, float *data_out)
Temperature Read function.
err_t tempprobe_read_dword(tempprobe_t *ctx, uint16_t reg_addr, uint32_t *data_out)
Word Read function.
uint8_t tempprobe_write_eeprom_data(tempprobe_t *ctx)
EEPROM Write function.
void tempprobe_reset(tempprobe_t *ctx)
Reset function.
err_t tempprobe_write_byte(tempprobe_t *ctx, uint16_t reg_addr, uint8_t data_in)
Byte Write function.
err_t tempprobe_write_dword(tempprobe_t *ctx, uint16_t reg_addr, uint32_t data_in)
Word Write function.
uint8_t tempprobe_check_busy(tempprobe_t *ctx)
Busy Check function.
err_t tempprobe_init(tempprobe_t *ctx, tempprobe_cfg_t *cfg)
Temp Probe initialization function.
err_t tempprobe_default_cfg(tempprobe_t *ctx)
Temp Probe default configuration function.
This file contains SPI specific macros, functions, etc.
Temp Probe Click configuration object.
Definition tempprobe.h:347
spi_master_chip_select_polarity_t cs_polarity
Definition tempprobe.h:361
pin_name_t sck
Definition tempprobe.h:351
spi_master_mode_t spi_mode
Definition tempprobe.h:360
pin_name_t mosi
Definition tempprobe.h:350
uint32_t spi_speed
Definition tempprobe.h:359
pin_name_t int_pin
Definition tempprobe.h:356
pin_name_t miso
Definition tempprobe.h:349
pin_name_t rst
Definition tempprobe.h:355
pin_name_t cs
Definition tempprobe.h:352
Temp Probe Click context object.
Definition tempprobe.h:327
spi_master_t spi
Definition tempprobe.h:335
digital_in_t int_pin
Definition tempprobe.h:332
uint8_t drv_temperature_format
Definition tempprobe.h:338
digital_out_t rst
Definition tempprobe.h:329
pin_name_t chip_select
Definition tempprobe.h:337
tempprobe_return_value_t
Temp Probe Click return value data.
Definition tempprobe.h:370
@ TEMPPROBE_ERROR
Definition tempprobe.h:372
@ TEMPPROBE_OK
Definition tempprobe.h:371