thermo23 2.0.0.0
thermo23.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 THERMO23_H
29#define THERMO23_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_uart.h"
52
73#define THERMO23_CMD_SOFT_RESET 0xB4
74#define THERMO23_CMD_GLOBAL_INIT 0x8C
75#define THERMO23_CMD_GLOBAL_ADDRESS_ASSIGN 0x90
76#define THERMO23_CMD_GLOBAL_CLEAR_INT 0xA9
77#define THERMO23_CMD_GLOBAL_WRITE_TEMP 0xF0
78#define THERMO23_CMD_GLOBAL_WRITE_CONFIG 0xF2
79#define THERMO23_CMD_GLOBAL_WRITE_TLOW 0xF4
80#define THERMO23_CMD_GLOBAL_WRITE_THIGH 0xF6
81#define THERMO23_CMD_GLOBAL_READ_TEMP 0xF1
82#define THERMO23_CMD_GLOBAL_READ_CONFIG 0xF3
83#define THERMO23_CMD_GLOBAL_READ_TLOW 0xF5
84#define THERMO23_CMD_GLOBAL_READ_THIGH 0xF7
85#define THERMO23_CMD_INDIVIDUAL_WRITE_BIT 0x00
86#define THERMO23_CMD_INDIVIDUAL_READ_BIT 0x01
87
92#define THERMO23_CALIBRATION_BYTE 0x55
93
98#define THERMO23_TIMEOUT 5000
99
104#define THERMO23_CONFIG_INT_EN 0x8000
105#define THERMO23_CONFIG_CR_0p25HZ 0x0000
106#define THERMO23_CONFIG_CR_1HZ 0x2000
107#define THERMO23_CONFIG_CR_4HZ 0x4000
108#define THERMO23_CONFIG_CR_8HZ 0x6000
109#define THERMO23_CONFIG_FH 0x1000
110#define THERMO23_CONFIG_FL 0x0800
111#define THERMO23_CONFIG_LC 0x0400
112#define THERMO23_CONFIG_MODE_SHUTDOWN 0x0000
113#define THERMO23_CONFIG_MODE_ONE_SHOT 0x0100
114#define THERMO23_CONFIG_MODE_CONTINUOUS 0x0200
115#define THERMO23_CONFIG_ETM 0x0080
116#define THERMO23_CONFIG_RESERVED_BITS 0x007F
117
122#define THERMO23_TEMP_RESOLUTION 0.0625
123
129#define DRV_BUFFER_SIZE 200
130
131 // thermo23_cmd
132
147#define THERMO23_MAP_MIKROBUS( cfg, mikrobus ) \
148 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
149 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX );
150
151 // thermo23_map
152 // thermo23
153
158typedef struct
159{
160 // Modules
161 uart_t uart;
163 // Buffers
164 char uart_rx_buffer[ DRV_BUFFER_SIZE ];
165 char uart_tx_buffer[ DRV_BUFFER_SIZE ];
167 uint16_t config;
169} thermo23_t;
170
175typedef struct
176{
177 // Communication gpio pins
178 pin_name_t rx_pin;
179 pin_name_t tx_pin;
181 // Static variable
182 uint32_t baud_rate;
184 uart_data_bits_t data_bit;
185 uart_parity_t parity_bit;
186 uart_stop_bits_t stop_bit;
189
194typedef enum
195{
197 THERMO23_ERROR = -1
198
200
217
232
246
259err_t thermo23_write_command ( thermo23_t *ctx, uint8_t cmd, uint16_t data_in );
260
273err_t thermo23_read_command ( thermo23_t *ctx, uint8_t cmd, uint16_t *data_out );
274
286err_t thermo23_set_config ( thermo23_t *ctx, uint16_t config );
287
299err_t thermo23_read_temperature ( thermo23_t *ctx, float *temperature );
300
301#ifdef __cplusplus
302}
303#endif
304#endif // THERMO23_H
305
306 // thermo23
307
308// ------------------------------------------------------------------------ END
#define DRV_BUFFER_SIZE
Thermo 23 driver buffer size.
Definition thermo23.h:129
err_t thermo23_init(thermo23_t *ctx, thermo23_cfg_t *cfg)
Thermo 23 initialization function.
void thermo23_cfg_setup(thermo23_cfg_t *cfg)
Thermo 23 configuration object setup function.
err_t thermo23_set_config(thermo23_t *ctx, uint16_t config)
Thermo 23 set config function.
err_t thermo23_write_command(thermo23_t *ctx, uint8_t cmd, uint16_t data_in)
Thermo 23 write command function.
err_t thermo23_default_cfg(thermo23_t *ctx)
Thermo 23 default configuration function.
err_t thermo23_read_command(thermo23_t *ctx, uint8_t cmd, uint16_t *data_out)
Thermo 23 read command function.
err_t thermo23_read_temperature(thermo23_t *ctx, float *temperature)
Thermo 23 read temperature function.
Thermo 23 Click configuration object.
Definition thermo23.h:176
uint32_t baud_rate
Definition thermo23.h:182
bool uart_blocking
Definition thermo23.h:183
uart_data_bits_t data_bit
Definition thermo23.h:184
pin_name_t tx_pin
Definition thermo23.h:179
pin_name_t rx_pin
Definition thermo23.h:178
uart_stop_bits_t stop_bit
Definition thermo23.h:186
uart_parity_t parity_bit
Definition thermo23.h:185
Thermo 23 Click context object.
Definition thermo23.h:159
uart_t uart
Definition thermo23.h:161
uint16_t config
Definition thermo23.h:167
thermo23_return_value_t
Thermo 23 Click return value data.
Definition thermo23.h:195
@ THERMO23_OK
Definition thermo23.h:196
@ THERMO23_ERROR
Definition thermo23.h:197