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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_uart.h"
38 
59 #define THERMO23_CMD_SOFT_RESET 0xB4
60 #define THERMO23_CMD_GLOBAL_INIT 0x8C
61 #define THERMO23_CMD_GLOBAL_ADDRESS_ASSIGN 0x90
62 #define THERMO23_CMD_GLOBAL_CLEAR_INT 0xA9
63 #define THERMO23_CMD_GLOBAL_WRITE_TEMP 0xF0
64 #define THERMO23_CMD_GLOBAL_WRITE_CONFIG 0xF2
65 #define THERMO23_CMD_GLOBAL_WRITE_TLOW 0xF4
66 #define THERMO23_CMD_GLOBAL_WRITE_THIGH 0xF6
67 #define THERMO23_CMD_GLOBAL_READ_TEMP 0xF1
68 #define THERMO23_CMD_GLOBAL_READ_CONFIG 0xF3
69 #define THERMO23_CMD_GLOBAL_READ_TLOW 0xF5
70 #define THERMO23_CMD_GLOBAL_READ_THIGH 0xF7
71 #define THERMO23_CMD_INDIVIDUAL_WRITE_BIT 0x00
72 #define THERMO23_CMD_INDIVIDUAL_READ_BIT 0x01
73 
78 #define THERMO23_CALIBRATION_BYTE 0x55
79 
84 #define THERMO23_TIMEOUT 5000
85 
90 #define THERMO23_CONFIG_INT_EN 0x8000
91 #define THERMO23_CONFIG_CR_0p25HZ 0x0000
92 #define THERMO23_CONFIG_CR_1HZ 0x2000
93 #define THERMO23_CONFIG_CR_4HZ 0x4000
94 #define THERMO23_CONFIG_CR_8HZ 0x6000
95 #define THERMO23_CONFIG_FH 0x1000
96 #define THERMO23_CONFIG_FL 0x0800
97 #define THERMO23_CONFIG_LC 0x0400
98 #define THERMO23_CONFIG_MODE_SHUTDOWN 0x0000
99 #define THERMO23_CONFIG_MODE_ONE_SHOT 0x0100
100 #define THERMO23_CONFIG_MODE_CONTINUOUS 0x0200
101 #define THERMO23_CONFIG_ETM 0x0080
102 #define THERMO23_CONFIG_RESERVED_BITS 0x007F
103 
108 #define THERMO23_TEMP_RESOLUTION 0.0625
109 
115 #define DRV_BUFFER_SIZE 200
116  // thermo23_cmd
118 
133 #define THERMO23_MAP_MIKROBUS( cfg, mikrobus ) \
134  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
135  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX );
136  // thermo23_map // thermo23
139 
144 typedef struct
145 {
146  // Modules
147  uart_t uart;
149  // Buffers
150  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
151  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
153  uint16_t config;
155 } thermo23_t;
156 
161 typedef struct
162 {
163  // Communication gpio pins
164  pin_name_t rx_pin;
165  pin_name_t tx_pin;
167  // Static variable
168  uint32_t baud_rate;
170  uart_data_bits_t data_bit;
171  uart_parity_t parity_bit;
172  uart_stop_bits_t stop_bit;
175 
180 typedef enum
181 {
183  THERMO23_ERROR = -1
184 
186 
203 
218 
232 
245 err_t thermo23_write_command ( thermo23_t *ctx, uint8_t cmd, uint16_t data_in );
246 
259 err_t thermo23_read_command ( thermo23_t *ctx, uint8_t cmd, uint16_t *data_out );
260 
272 err_t thermo23_set_config ( thermo23_t *ctx, uint16_t config );
273 
285 err_t thermo23_read_temperature ( thermo23_t *ctx, float *temperature );
286 
287 #ifdef __cplusplus
288 }
289 #endif
290 #endif // THERMO23_H
291  // thermo23
293 
294 // ------------------------------------------------------------------------ END
thermo23_init
err_t thermo23_init(thermo23_t *ctx, thermo23_cfg_t *cfg)
Thermo 23 initialization function.
thermo23_cfg_setup
void thermo23_cfg_setup(thermo23_cfg_t *cfg)
Thermo 23 configuration object setup function.
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
Thermo 23 driver buffer size.
Definition: thermo23.h:115
thermo23_cfg_t::baud_rate
uint32_t baud_rate
Definition: thermo23.h:168
THERMO23_ERROR
@ THERMO23_ERROR
Definition: thermo23.h:183
thermo23_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: thermo23.h:172
thermo23_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: thermo23.h:171
thermo23_cfg_t::tx_pin
pin_name_t tx_pin
Definition: thermo23.h:165
thermo23_t::config
uint16_t config
Definition: thermo23.h:153
thermo23_cfg_t
Thermo 23 Click configuration object.
Definition: thermo23.h:162
thermo23_write_command
err_t thermo23_write_command(thermo23_t *ctx, uint8_t cmd, uint16_t data_in)
Thermo 23 write command function.
thermo23_read_command
err_t thermo23_read_command(thermo23_t *ctx, uint8_t cmd, uint16_t *data_out)
Thermo 23 read command function.
THERMO23_OK
@ THERMO23_OK
Definition: thermo23.h:182
thermo23_read_temperature
err_t thermo23_read_temperature(thermo23_t *ctx, float *temperature)
Thermo 23 read temperature function.
thermo23_t::uart
uart_t uart
Definition: thermo23.h:147
thermo23_return_value_t
thermo23_return_value_t
Thermo 23 Click return value data.
Definition: thermo23.h:181
thermo23_set_config
err_t thermo23_set_config(thermo23_t *ctx, uint16_t config)
Thermo 23 set config function.
thermo23_default_cfg
err_t thermo23_default_cfg(thermo23_t *ctx)
Thermo 23 default configuration function.
thermo23_cfg_t::rx_pin
pin_name_t rx_pin
Definition: thermo23.h:164
thermo23_t
Thermo 23 Click context object.
Definition: thermo23.h:145
thermo23_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: thermo23.h:170
thermo23_cfg_t::uart_blocking
bool uart_blocking
Definition: thermo23.h:169