thermoj 2.0.0.0
thermoj.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 THERMOJ_H
36#define THERMOJ_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define THERMOJ_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.alert4 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
70 cfg.alert3 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71 cfg.alert2 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
72 cfg.alert1 = MIKROBUS( mikrobus, MIKROBUS_INT )
79#define THERMOJ_RETVAL uint8_t
80
81#define THERMOJ_OK 0x00
82#define THERMOJ_INIT_ERROR 0xFF
89#define THERMOJ_I2C_ADDR_0 0x60
90#define THERMOJ_I2C_ADDR_1 0x67
97#define THERMOJ_TH 0x00
98#define THERMOJ_TD 0x01
99#define THERMOJ_TC 0x02
100#define THERMOJ_RAW_ADC_DATA 0x03
101#define THERMOJ_STATUS 0x04
102#define THERMOJ_SENSOR_CONFIG 0x05
103#define THERMOJ_DEVICE_CONFIG 0x06
104#define THERMOJ_ALERT1_CONFIG 0x08
105#define THERMOJ_ALERT2_CONFIG 0x09
106#define THERMOJ_ALERT3_CONFIG 0x0A
107#define THERMOJ_Alert4_CONFIG 0x0B
108#define THERMOJ_THYST1 0x0C
109#define THERMOJ_THYST2 0x0D
110#define THERMOJ_THYST3 0x0E
111#define THERMOJ_THYST4 0x0F
112#define THERMOJ_TALERT1 0x10
113#define THERMOJ_TALERT2 0x11
114#define THERMOJ_TALERT3 0x12
115#define THERMOJ_TALERT4 0x13
116#define THERMOJ_DEVICE_ID 0x20
123#define THERMOJ_THERMOCOUPLE_TYPE_K 0x00
124#define THERMOJ_THERMOCOUPLE_TYPE_J 0x01
125#define THERMOJ_THERMOCOUPLE_TYPE_T 0x02
126#define THERMOJ_THERMOCOUPLE_TYPE_N 0x03
127#define THERMOJ_THERMOCOUPLE_TYPE_S 0x04
128#define THERMOJ_THERMOCOUPLE_TYPE_E 0x05
129#define THERMOJ_THERMOCOUPLE_TYPE_B 0x06
130#define THERMOJ_THERMOCOUPLE_TYPE_R 0x07
133 // End group macro
134// --------------------------------------------------------------- PUBLIC TYPES
143typedef struct
144{
145 // Input pins
146
147 digital_in_t alert4;
148 digital_in_t alert3;
149 digital_in_t alert2;
150 digital_in_t alert1;
151
152 // Modules
153
154 i2c_master_t i2c;
155
156 // ctx variable
157
159
160} thermoj_t;
161
165typedef struct
166{
167 // Communication gpio pins
168
169 pin_name_t scl;
170 pin_name_t sda;
171
172 // Additional gpio pins
173
174 pin_name_t alert4;
175 pin_name_t alert3;
176 pin_name_t alert2;
177 pin_name_t alert1;
178
179 // static variable
180
181 uint32_t i2c_speed;
182 uint8_t i2c_address;
183
185
186 // End types group
187// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
188
194#ifdef __cplusplus
195extern "C"{
196#endif
197
207
217
228void thermoj_generic_write ( thermoj_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
229
240void thermoj_generic_read ( thermoj_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
241
252void thermoj_write_byte ( thermoj_t *ctx, uint8_t reg_address, uint8_t write_data );
253
263uint8_t thermoj_read_byte ( thermoj_t *ctx, uint8_t reg_address );
264
274
284
294
304
317void thermoj_check_alert_status ( thermoj_t *ctx, uint8_t *alert_1, uint8_t *alert_2, uint8_t *alert_3, uint8_t *alert_4 );
318
328void thermoj_set_sensor_config ( thermoj_t *ctx, uint8_t config_val );
329
339void thermoj_set_thermocouple_type ( thermoj_t *ctx, uint8_t thermocouple_type );
340
350void thermoj_set_filter_coefficient ( thermoj_t *ctx, uint8_t filter_coeff );
351
361
371void thermoj_set_config ( thermoj_t *ctx, uint8_t config_val );
372
383
393void thermoj_set_adc_resolution ( thermoj_t *ctx, uint8_t adc_res );
394
404void thermoj_set_number_of_temperature_samples ( thermoj_t *ctx, uint8_t num_temp_samp );
405
415void thermoj_set_shutdown_modes ( thermoj_t *ctx, uint8_t sd_mod );
416
427void thermoj_write_data ( thermoj_t *ctx, uint8_t reg_address, uint16_t write_data );
428
438uint16_t thermoj_read_data ( thermoj_t *ctx, uint8_t reg_address );
439
449
459
469
479
489
499
509
521void thermoj_set_alerts_limits ( thermoj_t *ctx, uint8_t pos_alert, float temp_alert_limit );
522
534void thermoj_set_alert_config ( thermoj_t *ctx, uint8_t pos_alert, uint8_t alert_config );
535
546void thermoj_enable_alert ( thermoj_t *ctx, uint8_t pos_alert );
547
558void thermoj_disable_alert ( thermoj_t *ctx, uint8_t pos_alert );
559
560#ifdef __cplusplus
561}
562#endif
563#endif // _THERMOJ_H_
564
565 // End public_function group
567
568// ------------------------------------------------------------------------- END
#define THERMOJ_RETVAL
Definition thermoj.h:79
uint8_t thermoj_get_status(thermoj_t *ctx)
Get the status function.
void thermoj_generic_write(thermoj_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void thermoj_disable_alert(thermoj_t *ctx, uint8_t pos_alert)
Disable alerts function.
THERMOJ_RETVAL thermoj_init(thermoj_t *ctx, thermoj_cfg_t *cfg)
Initialization function.
void thermoj_cfg_setup(thermoj_cfg_t *cfg)
Config Object Initialization function.
uint16_t thermoj_read_data(thermoj_t *ctx, uint8_t reg_address)
Read data function.
void thermoj_set_shutdown_modes(thermoj_t *ctx, uint8_t sd_mod)
Set shutdown modes function.
void thermoj_set_alert_config(thermoj_t *ctx, uint8_t pos_alert, uint8_t alert_config)
Set alert configuration function.
uint8_t thermoj_get_alert_2(thermoj_t *ctx)
Get temperature alert 2 function.
uint8_t thermoj_get_alert_3(thermoj_t *ctx)
Get temperature alert 3 function.
uint8_t thermoj_read_byte(thermoj_t *ctx, uint8_t reg_address)
Read the byte of data function.
void thermoj_write_data(thermoj_t *ctx, uint8_t reg_address, uint16_t write_data)
Write data function.
void thermoj_set_sensor_config(thermoj_t *ctx, uint8_t config_val)
Set sensor configuration function.
uint8_t thermoj_check_data_ready(thermoj_t *ctx)
Check the status of data ready function.
void thermoj_set_filter_coefficient(thermoj_t *ctx, uint8_t filter_coeff)
Set filter coefficient sensor configuration function.
uint8_t thermoj_get_alert_1(thermoj_t *ctx)
Get temperature alert 1 function.
void thermoj_set_number_of_temperature_samples(thermoj_t *ctx, uint8_t num_temp_samp)
Set number of temperature samples function.
uint8_t thermoj_get_device_id(thermoj_t *ctx)
Get the device ID function.
void thermoj_set_cold_junction_resolution(thermoj_t *ctx, uint8_t cj_res)
Set cold-junction resolution function.
void thermoj_generic_read(thermoj_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
float thermoj_get_temperature_fahrenheit(thermoj_t *ctx)
Get temperature ( Fahrenheit ) function.
uint8_t thermoj_get_sensor_config(thermoj_t *ctx)
Get sensor configuration function.
void thermoj_enable_alert(thermoj_t *ctx, uint8_t pos_alert)
Enable alerts function.
uint8_t thermoj_get_alert_4(thermoj_t *ctx)
Get temperature alert 4 function.
void thermoj_set_adc_resolution(thermoj_t *ctx, uint8_t adc_res)
Set ADC measurement resolution function.
uint8_t thermoj_check_burst_complete(thermoj_t *ctx)
Check the status of burst complete function.
void thermoj_set_config(thermoj_t *ctx, uint8_t config_val)
Set configuration function.
void thermoj_set_thermocouple_type(thermoj_t *ctx, uint8_t thermocouple_type)
Set thermocouple type sensor configuration function.
void thermoj_set_alerts_limits(thermoj_t *ctx, uint8_t pos_alert, float temp_alert_limit)
Set temperature alert limits function.
void thermoj_check_alert_status(thermoj_t *ctx, uint8_t *alert_1, uint8_t *alert_2, uint8_t *alert_3, uint8_t *alert_4)
Write the byte of data function.
void thermoj_write_byte(thermoj_t *ctx, uint8_t reg_address, uint8_t write_data)
Write the byte of data function.
float thermoj_get_temperature(thermoj_t *ctx)
Get temperature function.
uint8_t thermoj_check_over_voltage(thermoj_t *ctx)
Check the status of over voltage function.
Click configuration structure definition.
Definition thermoj.h:166
pin_name_t alert4
Definition thermoj.h:174
uint32_t i2c_speed
Definition thermoj.h:181
pin_name_t alert1
Definition thermoj.h:177
pin_name_t alert3
Definition thermoj.h:175
pin_name_t alert2
Definition thermoj.h:176
pin_name_t scl
Definition thermoj.h:169
pin_name_t sda
Definition thermoj.h:170
uint8_t i2c_address
Definition thermoj.h:182
Click ctx object definition.
Definition thermoj.h:144
digital_in_t alert3
Definition thermoj.h:148
digital_in_t alert2
Definition thermoj.h:149
digital_in_t alert4
Definition thermoj.h:147
i2c_master_t i2c
Definition thermoj.h:154
digital_in_t alert1
Definition thermoj.h:150
uint8_t slave_address
Definition thermoj.h:158