rtd  2.0.0.0
rtd.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE 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 #include "spi_specifics.h"
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_OK 0
67 #define RTD_ERROR -1
68 
74 #define RTD_REF_RESISTANCE_470 470
75 
81 #define RTD_CONFIGURATION 0x00
82 #define RTD_RTD_MSB 0x01
83 #define RTD_RTD_LSB 0x02
84 #define RTD_HI_FLT_THRHLD_MSB 0x03
85 #define RTD_HI_FLT_THRHLD_LSB 0x04
86 #define RTD_LO_FLT_THRHLD_MSB 0x05
87 #define RTD_LO_FLT_THRHLD_LSB 0x06
88 #define RTD_FLT_STATUS 0x07
89 
99 #define RTD_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
100 #define RTD_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
101  // End group macro
103 // --------------------------------------------------------------- PUBLIC TYPES
112 typedef struct
113 {
114  // Input pins
115  digital_in_t drdy;
116 
117  // Modules
118  spi_master_t spi;
119  pin_name_t chip_select;
120 
121 } rtd_t;
122 
126 typedef struct
127 {
128  // Communication gpio pins
129  pin_name_t miso;
130  pin_name_t mosi;
131  pin_name_t sck;
132  pin_name_t cs;
133 
134  // Additional gpio pins
135  pin_name_t drdy;
136 
137  // static variable
138  uint32_t spi_speed;
139  spi_master_mode_t spi_mode;
140  spi_master_chip_select_polarity_t cs_polarity;
141 
142 } rtd_cfg_t;
143  // End types group
145 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
146 
151 #ifdef __cplusplus
152 extern "C"{
153 #endif
154 
163 void rtd_cfg_setup ( rtd_cfg_t *cfg );
164 
173 err_t rtd_init ( rtd_t *ctx, rtd_cfg_t *cfg );
174 
187 void rtd_write_register ( rtd_t *ctx, uint8_t reg_address, uint8_t write_data );
188 
197 uint8_t rtd_read_register ( rtd_t *ctx, uint8_t reg_address );
198 
206 uint16_t rtd_read_temperature ( rtd_t *ctx );
207 
222 float rtd_convert_temperature ( rtd_t *ctx, uint16_t input_data, uint16_t referent_resistance );
223 
224 #ifdef __cplusplus
225 }
226 #endif
227 #endif // _RTD_H_
228  // End public_function group
231 
232 // ------------------------------------------------------------------------- END
rtd_t::drdy
digital_in_t drdy
Definition: rtd.h:115
rtd_t::chip_select
pin_name_t chip_select
Definition: rtd.h:119
rtd_write_register
void rtd_write_register(rtd_t *ctx, uint8_t reg_address, uint8_t write_data)
Write to Register function.
rtd_t::spi
spi_master_t spi
Definition: rtd.h:118
rtd_cfg_setup
void rtd_cfg_setup(rtd_cfg_t *cfg)
Config Object Initialization function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
rtd_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: rtd.h:140
rtd_cfg_t::cs
pin_name_t cs
Definition: rtd.h:132
rtd_cfg_t::drdy
pin_name_t drdy
Definition: rtd.h:135
rtd_read_temperature
uint16_t rtd_read_temperature(rtd_t *ctx)
Read Temperature function.
rtd_convert_temperature
float rtd_convert_temperature(rtd_t *ctx, uint16_t input_data, uint16_t referent_resistance)
Convert Temperature function.
rtd_t
Click ctx object definition.
Definition: rtd.h:113
rtd_cfg_t::spi_speed
uint32_t spi_speed
Definition: rtd.h:138
rtd_cfg_t
Click configuration structure definition.
Definition: rtd.h:127
rtd_read_register
uint8_t rtd_read_register(rtd_t *ctx, uint8_t reg_address)
Read from Register function.
rtd_cfg_t::miso
pin_name_t miso
Definition: rtd.h:129
rtd_init
err_t rtd_init(rtd_t *ctx, rtd_cfg_t *cfg)
Initialization function.
rtd_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: rtd.h:139
rtd_cfg_t::sck
pin_name_t sck
Definition: rtd.h:131
rtd_cfg_t::mosi
pin_name_t mosi
Definition: rtd.h:130