rtd  2.0.0.0
rtd.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef RTD_H
36 #define RTD_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
54 #define RTD_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
56  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
57  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
58  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
59  cfg.drdy = MIKROBUS( mikrobus, MIKROBUS_INT );
60 
66 #define RTD_RETVAL uint8_t
67 
68 #define RTD_OK 0x00
69 #define RTD_INIT_ERROR 0xFF
70 #define RTD_ERR 1
71 
77 #define RTD_REF_RESISTANCE_470 470
78 
84 #define RTD_CONFIGURATION 0x00
85 #define RTD_RTD_MSB 0x01
86 #define RTD_RTD_LSB 0x02
87 #define RTD_HI_FLT_THRHLD_MSB 0x03
88 #define RTD_HI_FLT_THRHLD_LSB 0x04
89 #define RTD_LO_FLT_THRHLD_MSB 0x05
90 #define RTD_LO_FLT_THRHLD_LSB 0x06
91 #define RTD_FLT_STATUS 0x07
92  // End group macro
95 // --------------------------------------------------------------- PUBLIC TYPES
104 typedef struct
105 {
106  // Input pins
107 
108  digital_in_t drdy;
109 
110  // Modules
111 
112  spi_master_t spi;
113 
114 } rtd_t;
115 
119 typedef struct
120 {
121  // Communication gpio pins
122 
123  pin_name_t miso;
124  pin_name_t mosi;
125  pin_name_t sck;
126  pin_name_t cs;
127 
128  // Additional gpio pins
129 
130  pin_name_t drdy;
131 
132  // static variable
133 
134  hal_spi_speed_t spi_speed;
135  hal_spi_mode_t spi_mode;
136 
137 } rtd_cfg_t;
138  // End types group
140 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
141 
146 #ifdef __cplusplus
147 extern "C"{
148 #endif
149 
158 void rtd_cfg_setup ( rtd_cfg_t *cfg );
159 
168 RTD_RETVAL rtd_init ( rtd_t *ctx, rtd_cfg_t *cfg );
169 
178 void rtd_generic_transfer ( rtd_t *ctx, spi_master_transfer_data_t *block );
179 
192 void rtd_write_register ( rtd_t *ctx, uint8_t reg_address, uint8_t write_data );
193 
202 uint8_t rtd_read_register ( rtd_t *ctx, uint8_t reg_address );
203 
211 uint16_t rtd_read_temperature ( rtd_t *ctx );
212 
227 float rtd_convert_temperature ( rtd_t *ctx, uint16_t input_data, uint16_t referent_resistance );
228 
229 #ifdef __cplusplus
230 }
231 #endif
232 #endif // _RTD_H_
233  // End public_function group
236 
237 // ------------------------------------------------------------------------- END
uint16_t rtd_read_temperature(rtd_t *ctx)
Read Temperature function.
pin_name_t sck
Definition: rtd.h:125
pin_name_t mosi
Definition: rtd.h:124
pin_name_t cs
Definition: rtd.h:126
digital_in_t drdy
Definition: rtd.h:108
void rtd_generic_transfer(rtd_t *ctx, spi_master_transfer_data_t *block)
Generic transfer function.
RTD_RETVAL rtd_init(rtd_t *ctx, rtd_cfg_t *cfg)
Initialization function.
float rtd_convert_temperature(rtd_t *ctx, uint16_t input_data, uint16_t referent_resistance)
Convert Temperature function.
Click ctx object definition.
Definition: rtd.h:104
hal_spi_mode_t spi_mode
Definition: rtd.h:135
pin_name_t drdy
Definition: rtd.h:130
#define RTD_RETVAL
Definition: rtd.h:66
spi_master_t spi
Definition: rtd.h:112
pin_name_t miso
Definition: rtd.h:123
uint8_t rtd_read_register(rtd_t *ctx, uint8_t reg_address)
Read from Register function.
void rtd_write_register(rtd_t *ctx, uint8_t reg_address, uint8_t write_data)
Write to Register function.
void rtd_cfg_setup(rtd_cfg_t *cfg)
Config Object Initialization function.
Click configuration structure definition.
Definition: rtd.h:119
hal_spi_speed_t spi_speed
Definition: rtd.h:134