thermo29  2.1.0.0
thermo29.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 THERMO29_H
29 #define THERMO29_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_spi_master.h"
38 #include "spi_specifics.h"
39 
60 #define THERMO29_REG_TEMP_RESULT 0x00
61 #define THERMO29_REG_SLEW_RESULT 0x01
62 #define THERMO29_REG_ALERT_STATUS 0x02
63 #define THERMO29_REG_CONFIGURATION 0x03
64 #define THERMO29_REG_ALERT_ENABLE 0x04
65 #define THERMO29_REG_TLOW_LIMIT 0x05
66 #define THERMO29_REG_THIGH_LIMIT 0x06
67 #define THERMO29_REG_HYSTERESIS 0x07
68 #define THERMO29_REG_SLEW_LIMIT 0x08
69 #define THERMO29_REG_UNIQUE_ID1 0x09
70 #define THERMO29_REG_UNIQUE_ID2 0x0A
71 #define THERMO29_REG_UNIQUE_ID3 0x0B
72 #define THERMO29_REG_DEVICE_ID 0x0C
73  // thermo29_reg
75 
90 #define THERMO29_CONFIGURATION_RESETS 0x0100u
91 #define THERMO29_CONFIGURATION_AVG 0x0080u
92 #define THERMO29_CONFIGURATION_INT_COMP 0x0020u
93 #define THERMO29_CONFIGURATION_ONE_SHOT 0x0010u
94 #define THERMO29_CONFIGURATION_MODE_CONT 0x0000u
95 #define THERMO29_CONFIGURATION_MODE_SHDN 0x0008u
96 #define THERMO29_CONFIGURATION_MODE_MASK 0x0008u
97 #define THERMO29_CONFIGURATION_CONV_PER_6MS 0x0000u
98 #define THERMO29_CONFIGURATION_CONV_PER_31_25MS 0x0001u
99 #define THERMO29_CONFIGURATION_CONV_PER_62_5MS 0x0002u
100 #define THERMO29_CONFIGURATION_CONV_PER_125MS 0x0003u
101 #define THERMO29_CONFIGURATION_CONV_PER_250MS 0x0004u
102 #define THERMO29_CONFIGURATION_CONV_PER_500MS 0x0005u
103 #define THERMO29_CONFIGURATION_CONV_PER_1S 0x0006u
104 #define THERMO29_CONFIGURATION_CONV_PER_2S 0x0007u
105 #define THERMO29_CONFIGURATION_CONV_PER_MASK 0x0007u
106 
111 #define THERMO29_ALERT_ENABLE_CRC 0x0010u
112 #define THERMO29_ALERT_ENABLE_SLEW 0x0008u
113 #define THERMO29_ALERT_ENABLE_THIG 0x0004u
114 #define THERMO29_ALERT_ENABLE_TLOW 0x0002u
115 #define THERMO29_ALERT_ENABLE_DATA_READY 0x0001u
116 
121 #define THERMO29_CRC_ENABLE 0x40
122 #define THERMO29_CRC_DATA_BLOCK_LEN_MASK 0x3C
123 #define THERMO29_AUTO_INCREMENT 0x02
124 #define THERMO29_READ_BIT 0x01
125 #define THERMO29_WRITE_BIT 0x00
126 #define THERMO29_DATA_LEN_MAX 10
127 
132 #define THERMO29_TEMP_RESOLUTION 0.03125f
133 
138 #define THERMO29_DEVICE_REV_MASK 0xF000u
139 #define THERMO29_DEVICE_ID_MASK 0x0FFFu
140 #define THERMO29_DEVICE_ID 0x0126u
141 
150 #define THERMO29_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
151 #define THERMO29_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
152  // thermo29_set
154 
169 #define THERMO29_MAP_MIKROBUS( cfg, mikrobus ) \
170  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
171  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
172  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
173  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
174  cfg.alert = MIKROBUS( mikrobus, MIKROBUS_INT )
175  // thermo29_map // thermo29
178 
183 typedef struct
184 {
185  // Input pins
186  digital_in_t alert;
188  // Modules
189  spi_master_t spi;
191  pin_name_t chip_select;
193  bool crc_enable;
195 } thermo29_t;
196 
201 typedef struct
202 {
203  // Communication gpio pins
204  pin_name_t miso;
205  pin_name_t mosi;
206  pin_name_t sck;
207  pin_name_t cs;
209  // Additional gpio pins
210  pin_name_t alert;
212  // static variable
213  uint32_t spi_speed;
214  spi_master_mode_t spi_mode;
215  spi_master_chip_select_polarity_t cs_polarity;
218 
223 typedef enum
224 {
226  THERMO29_ERROR = -1
227 
229 
246 
261 
275 
288 err_t thermo29_write_register ( thermo29_t *ctx, uint8_t reg, uint16_t data_in );
289 
302 err_t thermo29_read_register ( thermo29_t *ctx, uint8_t reg, uint16_t *data_out );
303 
318 err_t thermo29_write_registers ( thermo29_t *ctx, uint8_t reg, uint16_t *data_in, uint8_t len );
319 
334 err_t thermo29_read_registers ( thermo29_t *ctx, uint8_t reg, uint16_t *data_out, uint8_t len );
335 
345 
355 
365 
377 
389 err_t thermo29_read_unique_id ( thermo29_t *ctx, uint16_t *unique_id );
390 
402 err_t thermo29_read_temperature ( thermo29_t *ctx, float *temperature );
403 
415 
416 #ifdef __cplusplus
417 }
418 #endif
419 #endif // THERMO29_H
420  // thermo29
422 
423 // ------------------------------------------------------------------------ END
thermo29_cfg_t::cs
pin_name_t cs
Definition: thermo29.h:207
thermo29_cfg_t::miso
pin_name_t miso
Definition: thermo29.h:204
THERMO29_OK
@ THERMO29_OK
Definition: thermo29.h:225
THERMO29_ERROR
@ THERMO29_ERROR
Definition: thermo29.h:226
spi_specifics.h
This file contains SPI specific macros, functions, etc.
thermo29_cfg_t::sck
pin_name_t sck
Definition: thermo29.h:206
thermo29_cfg_t::mosi
pin_name_t mosi
Definition: thermo29.h:205
thermo29_return_value_t
thermo29_return_value_t
Thermo 29 Click return value data.
Definition: thermo29.h:224
thermo29_disable_crc
void thermo29_disable_crc(thermo29_t *ctx)
Thermo 29 disable crc function.
thermo29_read_temperature
err_t thermo29_read_temperature(thermo29_t *ctx, float *temperature)
Thermo 29 read temperature function.
thermo29_t::spi
spi_master_t spi
Definition: thermo29.h:189
thermo29_init
err_t thermo29_init(thermo29_t *ctx, thermo29_cfg_t *cfg)
Thermo 29 initialization function.
thermo29_check_communication
err_t thermo29_check_communication(thermo29_t *ctx)
Thermo 29 check communication function.
thermo29_write_register
err_t thermo29_write_register(thermo29_t *ctx, uint8_t reg, uint16_t data_in)
Thermo 29 write register function.
thermo29_cfg_t
Thermo 29 Click configuration object.
Definition: thermo29.h:202
thermo29_write_registers
err_t thermo29_write_registers(thermo29_t *ctx, uint8_t reg, uint16_t *data_in, uint8_t len)
Thermo 29 write registers function.
thermo29_read_register
err_t thermo29_read_register(thermo29_t *ctx, uint8_t reg, uint16_t *data_out)
Thermo 29 read register function.
thermo29_cfg_t::alert
pin_name_t alert
Definition: thermo29.h:210
thermo29_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: thermo29.h:214
thermo29_t::crc_enable
bool crc_enable
Definition: thermo29.h:193
thermo29_clear_alert_status
err_t thermo29_clear_alert_status(thermo29_t *ctx)
Thermo 29 clear alert status function.
thermo29_enable_crc
void thermo29_enable_crc(thermo29_t *ctx)
Thermo 29 enable crc function.
thermo29_read_unique_id
err_t thermo29_read_unique_id(thermo29_t *ctx, uint16_t *unique_id)
Thermo 29 read unique id function.
thermo29_t::alert
digital_in_t alert
Definition: thermo29.h:186
thermo29_t::chip_select
pin_name_t chip_select
Definition: thermo29.h:191
thermo29_read_registers
err_t thermo29_read_registers(thermo29_t *ctx, uint8_t reg, uint16_t *data_out, uint8_t len)
Thermo 29 read registers function.
thermo29_cfg_setup
void thermo29_cfg_setup(thermo29_cfg_t *cfg)
Thermo 29 configuration object setup function.
thermo29_t
Thermo 29 Click context object.
Definition: thermo29.h:184
thermo29_get_alert_pin
uint8_t thermo29_get_alert_pin(thermo29_t *ctx)
Thermo 29 get alert pin function.
thermo29_cfg_t::spi_speed
uint32_t spi_speed
Definition: thermo29.h:213
thermo29_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: thermo29.h:215
thermo29_default_cfg
err_t thermo29_default_cfg(thermo29_t *ctx)
Thermo 29 default configuration function.