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 
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_spi_master.h"
52 #include "spi_specifics.h"
53 
74 #define THERMO29_REG_TEMP_RESULT 0x00
75 #define THERMO29_REG_SLEW_RESULT 0x01
76 #define THERMO29_REG_ALERT_STATUS 0x02
77 #define THERMO29_REG_CONFIGURATION 0x03
78 #define THERMO29_REG_ALERT_ENABLE 0x04
79 #define THERMO29_REG_TLOW_LIMIT 0x05
80 #define THERMO29_REG_THIGH_LIMIT 0x06
81 #define THERMO29_REG_HYSTERESIS 0x07
82 #define THERMO29_REG_SLEW_LIMIT 0x08
83 #define THERMO29_REG_UNIQUE_ID1 0x09
84 #define THERMO29_REG_UNIQUE_ID2 0x0A
85 #define THERMO29_REG_UNIQUE_ID3 0x0B
86 #define THERMO29_REG_DEVICE_ID 0x0C
87  // thermo29_reg
89 
104 #define THERMO29_CONFIGURATION_RESETS 0x0100u
105 #define THERMO29_CONFIGURATION_AVG 0x0080u
106 #define THERMO29_CONFIGURATION_INT_COMP 0x0020u
107 #define THERMO29_CONFIGURATION_ONE_SHOT 0x0010u
108 #define THERMO29_CONFIGURATION_MODE_CONT 0x0000u
109 #define THERMO29_CONFIGURATION_MODE_SHDN 0x0008u
110 #define THERMO29_CONFIGURATION_MODE_MASK 0x0008u
111 #define THERMO29_CONFIGURATION_CONV_PER_6MS 0x0000u
112 #define THERMO29_CONFIGURATION_CONV_PER_31_25MS 0x0001u
113 #define THERMO29_CONFIGURATION_CONV_PER_62_5MS 0x0002u
114 #define THERMO29_CONFIGURATION_CONV_PER_125MS 0x0003u
115 #define THERMO29_CONFIGURATION_CONV_PER_250MS 0x0004u
116 #define THERMO29_CONFIGURATION_CONV_PER_500MS 0x0005u
117 #define THERMO29_CONFIGURATION_CONV_PER_1S 0x0006u
118 #define THERMO29_CONFIGURATION_CONV_PER_2S 0x0007u
119 #define THERMO29_CONFIGURATION_CONV_PER_MASK 0x0007u
120 
125 #define THERMO29_ALERT_ENABLE_CRC 0x0010u
126 #define THERMO29_ALERT_ENABLE_SLEW 0x0008u
127 #define THERMO29_ALERT_ENABLE_THIG 0x0004u
128 #define THERMO29_ALERT_ENABLE_TLOW 0x0002u
129 #define THERMO29_ALERT_ENABLE_DATA_READY 0x0001u
130 
135 #define THERMO29_CRC_ENABLE 0x40
136 #define THERMO29_CRC_DATA_BLOCK_LEN_MASK 0x3C
137 #define THERMO29_AUTO_INCREMENT 0x02
138 #define THERMO29_READ_BIT 0x01
139 #define THERMO29_WRITE_BIT 0x00
140 #define THERMO29_DATA_LEN_MAX 10
141 
146 #define THERMO29_TEMP_RESOLUTION 0.03125f
147 
152 #define THERMO29_DEVICE_REV_MASK 0xF000u
153 #define THERMO29_DEVICE_ID_MASK 0x0FFFu
154 #define THERMO29_DEVICE_ID 0x0126u
155 
164 #define THERMO29_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
165 #define THERMO29_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
166  // thermo29_set
168 
183 #define THERMO29_MAP_MIKROBUS( cfg, mikrobus ) \
184  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
185  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
186  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
187  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
188  cfg.alert = MIKROBUS( mikrobus, MIKROBUS_INT )
189  // thermo29_map // thermo29
192 
197 typedef struct
198 {
199  // Input pins
200  digital_in_t alert;
202  // Modules
203  spi_master_t spi;
205  pin_name_t chip_select;
207  bool crc_enable;
209 } thermo29_t;
210 
215 typedef struct
216 {
217  // Communication gpio pins
218  pin_name_t miso;
219  pin_name_t mosi;
220  pin_name_t sck;
221  pin_name_t cs;
223  // Additional gpio pins
224  pin_name_t alert;
226  // static variable
227  uint32_t spi_speed;
228  spi_master_mode_t spi_mode;
229  spi_master_chip_select_polarity_t cs_polarity;
232 
237 typedef enum
238 {
240  THERMO29_ERROR = -1
241 
243 
260 
275 
289 
302 err_t thermo29_write_register ( thermo29_t *ctx, uint8_t reg, uint16_t data_in );
303 
316 err_t thermo29_read_register ( thermo29_t *ctx, uint8_t reg, uint16_t *data_out );
317 
332 err_t thermo29_write_registers ( thermo29_t *ctx, uint8_t reg, uint16_t *data_in, uint8_t len );
333 
348 err_t thermo29_read_registers ( thermo29_t *ctx, uint8_t reg, uint16_t *data_out, uint8_t len );
349 
359 
369 
379 
391 
403 err_t thermo29_read_unique_id ( thermo29_t *ctx, uint16_t *unique_id );
404 
416 err_t thermo29_read_temperature ( thermo29_t *ctx, float *temperature );
417 
429 
430 #ifdef __cplusplus
431 }
432 #endif
433 #endif // THERMO29_H
434  // thermo29
436 
437 // ------------------------------------------------------------------------ END
thermo29_cfg_t::cs
pin_name_t cs
Definition: thermo29.h:221
thermo29_cfg_t::miso
pin_name_t miso
Definition: thermo29.h:218
THERMO29_OK
@ THERMO29_OK
Definition: thermo29.h:239
THERMO29_ERROR
@ THERMO29_ERROR
Definition: thermo29.h:240
spi_specifics.h
This file contains SPI specific macros, functions, etc.
thermo29_cfg_t::sck
pin_name_t sck
Definition: thermo29.h:220
thermo29_cfg_t::mosi
pin_name_t mosi
Definition: thermo29.h:219
thermo29_return_value_t
thermo29_return_value_t
Thermo 29 Click return value data.
Definition: thermo29.h:238
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:203
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:216
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:224
thermo29_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: thermo29.h:228
thermo29_t::crc_enable
bool crc_enable
Definition: thermo29.h:207
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:200
thermo29_t::chip_select
pin_name_t chip_select
Definition: thermo29.h:205
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:198
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:227
thermo29_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: thermo29.h:229
thermo29_default_cfg
err_t thermo29_default_cfg(thermo29_t *ctx)
Thermo 29 default configuration function.