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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 #include "spi_specifics.h"
49 
70 #define THERMO29_REG_TEMP_RESULT 0x00
71 #define THERMO29_REG_SLEW_RESULT 0x01
72 #define THERMO29_REG_ALERT_STATUS 0x02
73 #define THERMO29_REG_CONFIGURATION 0x03
74 #define THERMO29_REG_ALERT_ENABLE 0x04
75 #define THERMO29_REG_TLOW_LIMIT 0x05
76 #define THERMO29_REG_THIGH_LIMIT 0x06
77 #define THERMO29_REG_HYSTERESIS 0x07
78 #define THERMO29_REG_SLEW_LIMIT 0x08
79 #define THERMO29_REG_UNIQUE_ID1 0x09
80 #define THERMO29_REG_UNIQUE_ID2 0x0A
81 #define THERMO29_REG_UNIQUE_ID3 0x0B
82 #define THERMO29_REG_DEVICE_ID 0x0C
83  // thermo29_reg
85 
100 #define THERMO29_CONFIGURATION_RESETS 0x0100u
101 #define THERMO29_CONFIGURATION_AVG 0x0080u
102 #define THERMO29_CONFIGURATION_INT_COMP 0x0020u
103 #define THERMO29_CONFIGURATION_ONE_SHOT 0x0010u
104 #define THERMO29_CONFIGURATION_MODE_CONT 0x0000u
105 #define THERMO29_CONFIGURATION_MODE_SHDN 0x0008u
106 #define THERMO29_CONFIGURATION_MODE_MASK 0x0008u
107 #define THERMO29_CONFIGURATION_CONV_PER_6MS 0x0000u
108 #define THERMO29_CONFIGURATION_CONV_PER_31_25MS 0x0001u
109 #define THERMO29_CONFIGURATION_CONV_PER_62_5MS 0x0002u
110 #define THERMO29_CONFIGURATION_CONV_PER_125MS 0x0003u
111 #define THERMO29_CONFIGURATION_CONV_PER_250MS 0x0004u
112 #define THERMO29_CONFIGURATION_CONV_PER_500MS 0x0005u
113 #define THERMO29_CONFIGURATION_CONV_PER_1S 0x0006u
114 #define THERMO29_CONFIGURATION_CONV_PER_2S 0x0007u
115 #define THERMO29_CONFIGURATION_CONV_PER_MASK 0x0007u
116 
121 #define THERMO29_ALERT_ENABLE_CRC 0x0010u
122 #define THERMO29_ALERT_ENABLE_SLEW 0x0008u
123 #define THERMO29_ALERT_ENABLE_THIG 0x0004u
124 #define THERMO29_ALERT_ENABLE_TLOW 0x0002u
125 #define THERMO29_ALERT_ENABLE_DATA_READY 0x0001u
126 
131 #define THERMO29_CRC_ENABLE 0x40
132 #define THERMO29_CRC_DATA_BLOCK_LEN_MASK 0x3C
133 #define THERMO29_AUTO_INCREMENT 0x02
134 #define THERMO29_READ_BIT 0x01
135 #define THERMO29_WRITE_BIT 0x00
136 #define THERMO29_DATA_LEN_MAX 10
137 
142 #define THERMO29_TEMP_RESOLUTION 0.03125f
143 
148 #define THERMO29_DEVICE_REV_MASK 0xF000u
149 #define THERMO29_DEVICE_ID_MASK 0x0FFFu
150 #define THERMO29_DEVICE_ID 0x0126u
151 
160 #define THERMO29_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
161 #define THERMO29_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
162  // thermo29_set
164 
179 #define THERMO29_MAP_MIKROBUS( cfg, mikrobus ) \
180  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
181  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
182  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
183  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
184  cfg.alert = MIKROBUS( mikrobus, MIKROBUS_INT )
185  // thermo29_map // thermo29
188 
193 typedef struct
194 {
195  // Input pins
196  digital_in_t alert;
198  // Modules
199  spi_master_t spi;
201  pin_name_t chip_select;
203  bool crc_enable;
205 } thermo29_t;
206 
211 typedef struct
212 {
213  // Communication gpio pins
214  pin_name_t miso;
215  pin_name_t mosi;
216  pin_name_t sck;
217  pin_name_t cs;
219  // Additional gpio pins
220  pin_name_t alert;
222  // static variable
223  uint32_t spi_speed;
224  spi_master_mode_t spi_mode;
225  spi_master_chip_select_polarity_t cs_polarity;
228 
233 typedef enum
234 {
236  THERMO29_ERROR = -1
237 
239 
256 
271 
285 
298 err_t thermo29_write_register ( thermo29_t *ctx, uint8_t reg, uint16_t data_in );
299 
312 err_t thermo29_read_register ( thermo29_t *ctx, uint8_t reg, uint16_t *data_out );
313 
328 err_t thermo29_write_registers ( thermo29_t *ctx, uint8_t reg, uint16_t *data_in, uint8_t len );
329 
344 err_t thermo29_read_registers ( thermo29_t *ctx, uint8_t reg, uint16_t *data_out, uint8_t len );
345 
355 
365 
375 
387 
399 err_t thermo29_read_unique_id ( thermo29_t *ctx, uint16_t *unique_id );
400 
412 err_t thermo29_read_temperature ( thermo29_t *ctx, float *temperature );
413 
425 
426 #ifdef __cplusplus
427 }
428 #endif
429 #endif // THERMO29_H
430  // thermo29
432 
433 // ------------------------------------------------------------------------ END
thermo29_cfg_t::cs
pin_name_t cs
Definition: thermo29.h:217
thermo29_cfg_t::miso
pin_name_t miso
Definition: thermo29.h:214
THERMO29_OK
@ THERMO29_OK
Definition: thermo29.h:235
THERMO29_ERROR
@ THERMO29_ERROR
Definition: thermo29.h:236
spi_specifics.h
This file contains SPI specific macros, functions, etc.
thermo29_cfg_t::sck
pin_name_t sck
Definition: thermo29.h:216
thermo29_cfg_t::mosi
pin_name_t mosi
Definition: thermo29.h:215
thermo29_return_value_t
thermo29_return_value_t
Thermo 29 Click return value data.
Definition: thermo29.h:234
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:199
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:212
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:220
thermo29_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: thermo29.h:224
thermo29_t::crc_enable
bool crc_enable
Definition: thermo29.h:203
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:196
thermo29_t::chip_select
pin_name_t chip_select
Definition: thermo29.h:201
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:194
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:223
thermo29_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: thermo29.h:225
thermo29_default_cfg
err_t thermo29_default_cfg(thermo29_t *ctx)
Thermo 29 default configuration function.