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
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_spi_master.h"
55#include "spi_specifics.h"
56
57// -------------------------------------------------------------- PUBLIC MACROS
68#define RTD_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73 cfg.drdy = MIKROBUS( mikrobus, MIKROBUS_INT );
80#define RTD_OK 0
81#define RTD_ERROR -1
88#define RTD_REF_RESISTANCE_470 470
95#define RTD_CONFIGURATION 0x00
96#define RTD_RTD_MSB 0x01
97#define RTD_RTD_LSB 0x02
98#define RTD_HI_FLT_THRHLD_MSB 0x03
99#define RTD_HI_FLT_THRHLD_LSB 0x04
100#define RTD_LO_FLT_THRHLD_MSB 0x05
101#define RTD_LO_FLT_THRHLD_LSB 0x06
102#define RTD_FLT_STATUS 0x07
113#define RTD_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
114#define RTD_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
115
116 // End group macro
117// --------------------------------------------------------------- PUBLIC TYPES
126typedef struct
127{
128 // Input pins
129 digital_in_t drdy;
130
131 // Modules
132 spi_master_t spi;
133 pin_name_t chip_select;
134
135} rtd_t;
136
140typedef struct
141{
142 // Communication gpio pins
143 pin_name_t miso;
144 pin_name_t mosi;
145 pin_name_t sck;
146 pin_name_t cs;
147
148 // Additional gpio pins
149 pin_name_t drdy;
150
151 // static variable
152 uint32_t spi_speed;
153 spi_master_mode_t spi_mode;
154 spi_master_chip_select_polarity_t cs_polarity;
155
156} rtd_cfg_t;
157
158 // End types group
159// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
160
165#ifdef __cplusplus
166extern "C"{
167#endif
168
178
187err_t rtd_init ( rtd_t *ctx, rtd_cfg_t *cfg );
188
201void rtd_write_register ( rtd_t *ctx, uint8_t reg_address, uint8_t write_data );
202
211uint8_t rtd_read_register ( rtd_t *ctx, uint8_t reg_address );
212
220uint16_t rtd_read_temperature ( rtd_t *ctx );
221
236float rtd_convert_temperature ( rtd_t *ctx, uint16_t input_data, uint16_t referent_resistance );
237
238#ifdef __cplusplus
239}
240#endif
241#endif // _RTD_H_
242
243 // End public_function group
245
246// ------------------------------------------------------------------------- END
err_t 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.
uint8_t rtd_read_register(rtd_t *ctx, uint8_t reg_address)
Read from Register function.
uint16_t rtd_read_temperature(rtd_t *ctx)
Read Temperature 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.
This file contains SPI specific macros, functions, etc.
Click configuration structure definition.
Definition rtd.h:141
pin_name_t drdy
Definition rtd.h:149
spi_master_chip_select_polarity_t cs_polarity
Definition rtd.h:154
pin_name_t sck
Definition rtd.h:145
spi_master_mode_t spi_mode
Definition rtd.h:153
pin_name_t mosi
Definition rtd.h:144
uint32_t spi_speed
Definition rtd.h:152
pin_name_t miso
Definition rtd.h:143
pin_name_t cs
Definition rtd.h:146
Click ctx object definition.
Definition rtd.h:127
spi_master_t spi
Definition rtd.h:132
digital_in_t drdy
Definition rtd.h:129
pin_name_t chip_select
Definition rtd.h:133