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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_spi_master.h"
51 #include "spi_specifics.h"
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
64 #define RTD_MAP_MIKROBUS( cfg, mikrobus ) \
65  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
66  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
67  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
68  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
69  cfg.drdy = MIKROBUS( mikrobus, MIKROBUS_INT );
70 
76 #define RTD_OK 0
77 #define RTD_ERROR -1
78 
84 #define RTD_REF_RESISTANCE_470 470
85 
91 #define RTD_CONFIGURATION 0x00
92 #define RTD_RTD_MSB 0x01
93 #define RTD_RTD_LSB 0x02
94 #define RTD_HI_FLT_THRHLD_MSB 0x03
95 #define RTD_HI_FLT_THRHLD_LSB 0x04
96 #define RTD_LO_FLT_THRHLD_MSB 0x05
97 #define RTD_LO_FLT_THRHLD_LSB 0x06
98 #define RTD_FLT_STATUS 0x07
99 
109 #define RTD_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
110 #define RTD_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
111  // End group macro
113 // --------------------------------------------------------------- PUBLIC TYPES
122 typedef struct
123 {
124  // Input pins
125  digital_in_t drdy;
126 
127  // Modules
128  spi_master_t spi;
129  pin_name_t chip_select;
130 
131 } rtd_t;
132 
136 typedef struct
137 {
138  // Communication gpio pins
139  pin_name_t miso;
140  pin_name_t mosi;
141  pin_name_t sck;
142  pin_name_t cs;
143 
144  // Additional gpio pins
145  pin_name_t drdy;
146 
147  // static variable
148  uint32_t spi_speed;
149  spi_master_mode_t spi_mode;
150  spi_master_chip_select_polarity_t cs_polarity;
151 
152 } rtd_cfg_t;
153  // End types group
155 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
156 
161 #ifdef __cplusplus
162 extern "C"{
163 #endif
164 
173 void rtd_cfg_setup ( rtd_cfg_t *cfg );
174 
183 err_t rtd_init ( rtd_t *ctx, rtd_cfg_t *cfg );
184 
197 void rtd_write_register ( rtd_t *ctx, uint8_t reg_address, uint8_t write_data );
198 
207 uint8_t rtd_read_register ( rtd_t *ctx, uint8_t reg_address );
208 
216 uint16_t rtd_read_temperature ( rtd_t *ctx );
217 
232 float rtd_convert_temperature ( rtd_t *ctx, uint16_t input_data, uint16_t referent_resistance );
233 
234 #ifdef __cplusplus
235 }
236 #endif
237 #endif // _RTD_H_
238  // End public_function group
241 
242 // ------------------------------------------------------------------------- END
rtd_t::drdy
digital_in_t drdy
Definition: rtd.h:125
rtd_t::chip_select
pin_name_t chip_select
Definition: rtd.h:129
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:128
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:150
rtd_cfg_t::cs
pin_name_t cs
Definition: rtd.h:142
rtd_cfg_t::drdy
pin_name_t drdy
Definition: rtd.h:145
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:123
rtd_cfg_t::spi_speed
uint32_t spi_speed
Definition: rtd.h:148
rtd_cfg_t
Click configuration structure definition.
Definition: rtd.h:137
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:139
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:149
rtd_cfg_t::sck
pin_name_t sck
Definition: rtd.h:141
rtd_cfg_t::mosi
pin_name_t mosi
Definition: rtd.h:140