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 
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_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define THERMOJ_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.alert4 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
66  cfg.alert3 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
67  cfg.alert2 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
68  cfg.alert1 = MIKROBUS( mikrobus, MIKROBUS_INT )
69 
75 #define THERMOJ_RETVAL uint8_t
76 
77 #define THERMOJ_OK 0x00
78 #define THERMOJ_INIT_ERROR 0xFF
79 
85 #define THERMOJ_I2C_ADDR_0 0x60
86 #define THERMOJ_I2C_ADDR_1 0x67
87 
93 #define THERMOJ_TH 0x00
94 #define THERMOJ_TD 0x01
95 #define THERMOJ_TC 0x02
96 #define THERMOJ_RAW_ADC_DATA 0x03
97 #define THERMOJ_STATUS 0x04
98 #define THERMOJ_SENSOR_CONFIG 0x05
99 #define THERMOJ_DEVICE_CONFIG 0x06
100 #define THERMOJ_ALERT1_CONFIG 0x08
101 #define THERMOJ_ALERT2_CONFIG 0x09
102 #define THERMOJ_ALERT3_CONFIG 0x0A
103 #define THERMOJ_Alert4_CONFIG 0x0B
104 #define THERMOJ_THYST1 0x0C
105 #define THERMOJ_THYST2 0x0D
106 #define THERMOJ_THYST3 0x0E
107 #define THERMOJ_THYST4 0x0F
108 #define THERMOJ_TALERT1 0x10
109 #define THERMOJ_TALERT2 0x11
110 #define THERMOJ_TALERT3 0x12
111 #define THERMOJ_TALERT4 0x13
112 #define THERMOJ_DEVICE_ID 0x20
113 
119 #define THERMOJ_THERMOCOUPLE_TYPE_K 0x00
120 #define THERMOJ_THERMOCOUPLE_TYPE_J 0x01
121 #define THERMOJ_THERMOCOUPLE_TYPE_T 0x02
122 #define THERMOJ_THERMOCOUPLE_TYPE_N 0x03
123 #define THERMOJ_THERMOCOUPLE_TYPE_S 0x04
124 #define THERMOJ_THERMOCOUPLE_TYPE_E 0x05
125 #define THERMOJ_THERMOCOUPLE_TYPE_B 0x06
126 #define THERMOJ_THERMOCOUPLE_TYPE_R 0x07
127  // End group macro
130 // --------------------------------------------------------------- PUBLIC TYPES
139 typedef struct
140 {
141  // Input pins
142 
143  digital_in_t alert4;
144  digital_in_t alert3;
145  digital_in_t alert2;
146  digital_in_t alert1;
147 
148  // Modules
149 
150  i2c_master_t i2c;
151 
152  // ctx variable
153 
154  uint8_t slave_address;
155 
156 } thermoj_t;
157 
161 typedef struct
162 {
163  // Communication gpio pins
164 
165  pin_name_t scl;
166  pin_name_t sda;
167 
168  // Additional gpio pins
169 
170  pin_name_t alert4;
171  pin_name_t alert3;
172  pin_name_t alert2;
173  pin_name_t alert1;
174 
175  // static variable
176 
177  uint32_t i2c_speed;
178  uint8_t i2c_address;
179 
180 } thermoj_cfg_t;
181  // End types group
183 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
184 
190 #ifdef __cplusplus
191 extern "C"{
192 #endif
193 
203 
213 
224 void thermoj_generic_write ( thermoj_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
225 
236 void thermoj_generic_read ( thermoj_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
237 
248 void thermoj_write_byte ( thermoj_t *ctx, uint8_t reg_address, uint8_t write_data );
249 
259 uint8_t thermoj_read_byte ( thermoj_t *ctx, uint8_t reg_address );
260 
269 uint8_t thermoj_get_status ( thermoj_t *ctx );
270 
280 
290 
300 
313 void thermoj_check_alert_status ( thermoj_t *ctx, uint8_t *alert_1, uint8_t *alert_2, uint8_t *alert_3, uint8_t *alert_4 );
314 
324 void thermoj_set_sensor_config ( thermoj_t *ctx, uint8_t config_val );
325 
335 void thermoj_set_thermocouple_type ( thermoj_t *ctx, uint8_t thermocouple_type );
336 
346 void thermoj_set_filter_coefficient ( thermoj_t *ctx, uint8_t filter_coeff );
347 
357 
367 void thermoj_set_config ( thermoj_t *ctx, uint8_t config_val );
368 
378 void thermoj_set_cold_junction_resolution ( thermoj_t *ctx, uint8_t cj_res );
379 
389 void thermoj_set_adc_resolution ( thermoj_t *ctx, uint8_t adc_res );
390 
400 void thermoj_set_number_of_temperature_samples ( thermoj_t *ctx, uint8_t num_temp_samp );
401 
411 void thermoj_set_shutdown_modes ( thermoj_t *ctx, uint8_t sd_mod );
412 
423 void thermoj_write_data ( thermoj_t *ctx, uint8_t reg_address, uint16_t write_data );
424 
434 uint16_t thermoj_read_data ( thermoj_t *ctx, uint8_t reg_address );
435 
445 
455 
465 
475 
485 
495 
505 
517 void thermoj_set_alerts_limits ( thermoj_t *ctx, uint8_t pos_alert, float temp_alert_limit );
518 
530 void thermoj_set_alert_config ( thermoj_t *ctx, uint8_t pos_alert, uint8_t alert_config );
531 
542 void thermoj_enable_alert ( thermoj_t *ctx, uint8_t pos_alert );
543 
554 void thermoj_disable_alert ( thermoj_t *ctx, uint8_t pos_alert );
555 
556 #ifdef __cplusplus
557 }
558 #endif
559 #endif // _THERMOJ_H_
560  // End public_function group
563 
564 // ------------------------------------------------------------------------- END
thermoj_generic_write
void thermoj_generic_write(thermoj_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
thermoj_set_sensor_config
void thermoj_set_sensor_config(thermoj_t *ctx, uint8_t config_val)
Set sensor configuration function.
thermoj_read_data
uint16_t thermoj_read_data(thermoj_t *ctx, uint8_t reg_address)
Read data function.
thermoj_cfg_t::alert4
pin_name_t alert4
Definition: thermoj.h:170
thermoj_t
Click ctx object definition.
Definition: thermoj.h:140
thermoj_check_burst_complete
uint8_t thermoj_check_burst_complete(thermoj_t *ctx)
Check the status of burst complete function.
thermoj_t::alert2
digital_in_t alert2
Definition: thermoj.h:145
thermoj_write_byte
void thermoj_write_byte(thermoj_t *ctx, uint8_t reg_address, uint8_t write_data)
Write the byte of data function.
thermoj_cfg_setup
void thermoj_cfg_setup(thermoj_cfg_t *cfg)
Config Object Initialization function.
thermoj_set_alert_config
void thermoj_set_alert_config(thermoj_t *ctx, uint8_t pos_alert, uint8_t alert_config)
Set alert configuration function.
thermoj_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: thermoj.h:177
thermoj_check_alert_status
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.
thermoj_cfg_t::alert2
pin_name_t alert2
Definition: thermoj.h:172
thermoj_enable_alert
void thermoj_enable_alert(thermoj_t *ctx, uint8_t pos_alert)
Enable alerts function.
thermoj_get_alert_3
uint8_t thermoj_get_alert_3(thermoj_t *ctx)
Get temperature alert 3 function.
thermoj_generic_read
void thermoj_generic_read(thermoj_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
thermoj_t::slave_address
uint8_t slave_address
Definition: thermoj.h:154
thermoj_cfg_t
Click configuration structure definition.
Definition: thermoj.h:162
thermoj_check_data_ready
uint8_t thermoj_check_data_ready(thermoj_t *ctx)
Check the status of data ready function.
thermoj_cfg_t::scl
pin_name_t scl
Definition: thermoj.h:165
thermoj_t::alert3
digital_in_t alert3
Definition: thermoj.h:144
thermoj_get_sensor_config
uint8_t thermoj_get_sensor_config(thermoj_t *ctx)
Get sensor configuration function.
thermoj_read_byte
uint8_t thermoj_read_byte(thermoj_t *ctx, uint8_t reg_address)
Read the byte of data function.
thermoj_get_temperature
float thermoj_get_temperature(thermoj_t *ctx)
Get temperature function.
thermoj_init
THERMOJ_RETVAL thermoj_init(thermoj_t *ctx, thermoj_cfg_t *cfg)
Initialization function.
thermoj_get_device_id
uint8_t thermoj_get_device_id(thermoj_t *ctx)
Get the device ID function.
thermoj_get_alert_2
uint8_t thermoj_get_alert_2(thermoj_t *ctx)
Get temperature alert 2 function.
thermoj_cfg_t::i2c_address
uint8_t i2c_address
Definition: thermoj.h:178
thermoj_cfg_t::alert1
pin_name_t alert1
Definition: thermoj.h:173
thermoj_set_shutdown_modes
void thermoj_set_shutdown_modes(thermoj_t *ctx, uint8_t sd_mod)
Set shutdown modes function.
thermoj_set_config
void thermoj_set_config(thermoj_t *ctx, uint8_t config_val)
Set configuration function.
thermoj_cfg_t::alert3
pin_name_t alert3
Definition: thermoj.h:171
thermoj_write_data
void thermoj_write_data(thermoj_t *ctx, uint8_t reg_address, uint16_t write_data)
Write data function.
thermoj_check_over_voltage
uint8_t thermoj_check_over_voltage(thermoj_t *ctx)
Check the status of over voltage function.
thermoj_t::i2c
i2c_master_t i2c
Definition: thermoj.h:150
thermoj_t::alert4
digital_in_t alert4
Definition: thermoj.h:143
thermoj_set_number_of_temperature_samples
void thermoj_set_number_of_temperature_samples(thermoj_t *ctx, uint8_t num_temp_samp)
Set number of temperature samples function.
thermoj_get_alert_1
uint8_t thermoj_get_alert_1(thermoj_t *ctx)
Get temperature alert 1 function.
thermoj_set_alerts_limits
void thermoj_set_alerts_limits(thermoj_t *ctx, uint8_t pos_alert, float temp_alert_limit)
Set temperature alert limits function.
thermoj_t::alert1
digital_in_t alert1
Definition: thermoj.h:146
thermoj_set_thermocouple_type
void thermoj_set_thermocouple_type(thermoj_t *ctx, uint8_t thermocouple_type)
Set thermocouple type sensor configuration function.
thermoj_get_alert_4
uint8_t thermoj_get_alert_4(thermoj_t *ctx)
Get temperature alert 4 function.
THERMOJ_RETVAL
#define THERMOJ_RETVAL
Definition: thermoj.h:75
thermoj_set_adc_resolution
void thermoj_set_adc_resolution(thermoj_t *ctx, uint8_t adc_res)
Set ADC measurement resolution function.
thermoj_get_status
uint8_t thermoj_get_status(thermoj_t *ctx)
Get the status function.
thermoj_set_filter_coefficient
void thermoj_set_filter_coefficient(thermoj_t *ctx, uint8_t filter_coeff)
Set filter coefficient sensor configuration function.
thermoj_get_temperature_fahrenheit
float thermoj_get_temperature_fahrenheit(thermoj_t *ctx)
Get temperature ( Fahrenheit ) function.
thermoj_set_cold_junction_resolution
void thermoj_set_cold_junction_resolution(thermoj_t *ctx, uint8_t cj_res)
Set cold-junction resolution function.
thermoj_cfg_t::sda
pin_name_t sda
Definition: thermoj.h:166
thermoj_disable_alert
void thermoj_disable_alert(thermoj_t *ctx, uint8_t pos_alert)
Disable alerts function.