rtd2  2.0.0.0
rtd2.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 RTD2_H
36 #define RTD2_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
53 #define RTD2_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
55  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
56  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
57  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
58  cfg.str = MIKROBUS( mikrobus, MIKROBUS_AN ); \
59  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
60  cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
61 
67 #define RTD2_RETVAL uint8_t
68 
69 #define RTD2_OK 0x00
70 #define RTD2_INIT_ERROR 0xFF
71 
77 #define RTD2_REG_MUX0 0x00
78 #define RTD2_REG_VBIAS 0x01
79 #define RTD2_REG_MUX1 0x02
80 #define RTD2_REG_SYS0 0x03
81 #define RTD2_REG_OFC0 0x04
82 #define RTD2_REG_OFC1 0x05
83 #define RTD2_REG_OFC2 0x06
84 #define RTD2_REG_FSC0 0x07
85 #define RTD2_REG_FSC1 0x08
86 #define RTD2_REG_FSC2 0x09
87 #define RTD2_REG_IDAC0 0x0A
88 #define RTD2_REG_IDAC1 0x0B
89 #define RTD2_REG_GPIOCFG 0x0C
90 #define RTD2_REG_GPIODIR 0x0D
91 #define RTD2_REG_GPIODAT 0x0E
92 
103 #define RTD2_CMD_WAKEUP 0x01
104 #define RTD2_CMD_SLEEP 0x03
105 #define RTD2_CMD_SYNC 0x05
106 #define RTD2_CMD_RESET 0x07
107 #define RTD2_CMD_NOP 0xFF
108 
114 #define RTD2_CMD_RDATA 0x12
115 #define RTD2_CMD_RDATAC 0x14
116 #define RTD2_CMD_SDATAC 0x16
117 
123 #define RTD2_CMD_RREG 0x20
124 
130 #define RTD2_CMD_WREG 0x40
131 
137 #define RTD2_CMD_SYSOCAL 0x60
138 #define RTD2_CMD_SYSGCAL 0x61
139 #define RTD2_CMD_SELFOCAL 0x62
140 
146 #define RTD2_RW_DUMMY 0xFF
147 
159 #define RTD2_BCS_OFF 0x00
160 #define RTD2_BCS_500 0x40
161 #define RTD2_BCS_2 0x80
162 #define RTD2_BCS_10 0xC0
163 
169 #define RTD2_AINP0 0x00
170 #define RTD2_AINP1 0x08
171 #define RTD2_AINP2 0x10
172 #define RTD2_AINP3 0x18
173 #define RTD2_AIN_POS 0x38
174 
180 #define RTD2_AINN0 0x00
181 #define RTD2_AINN1 0x01
182 #define RTD2_AINN2 0x02
183 #define RTD2_AINN3 0x03
184 #define RTD2_AIN_NEG 0x07
185 
191 #define RTD2_VBIAS_OFF 0x00
192 #define RTD2_VBIAS0 0x01
193 #define RTD2_VBIAS1 0x02
194 #define RTD2_VBIAS2 0x04
195 #define RTD2_VBIAS3 0x08
196 
208 #define RTD2_INT_VREF_OFF 0x00
209 #define RTD2_INT_VREF_ON 0x20
210 #define RTD2_INT_VREF_CONV 0x40
211 
217 #define RTD2_REF0 0x00
218 #define RTD2_INT 0x10
219 #define RTD2_INT_REF0 0x18
220 
226 #define RTD2_MEAS_NORM 0x00
227 #define RTD2_MEAS_OFFSET 0x01
228 #define RTD2_MEAS_GAIN 0x02
229 #define RTD2_MEAS_TEMP 0x03
230 #define RTD2_MEAS_REF0 0x05
231 #define RTD2_MEAS_AVDD 0x06
232 #define RTD2_MEAS_DVDD 0x07
233 
245 #define RTD2_GAIN_1 0x00
246 #define RTD2_GAIN_2 0x10
247 #define RTD2_GAIN_4 0x20
248 #define RTD2_GAIN_8 0x30
249 #define RTD2_GAIN_16 0x40
250 #define RTD2_GAIN_32 0x50
251 #define RTD2_GAIN_64 0x60
252 #define RTD2_GAIN_128 0x70
253 
259 #define RTD2_DR_5 0x00
260 #define RTD2_DR_10 0x01
261 #define RTD2_DR_20 0x02
262 #define RTD2_DR_40 0x03
263 #define RTD2_DR_80 0x04
264 #define RTD2_DR_160 0x05
265 #define RTD2_DR_320 0x06
266 #define RTD2_DR_640 0x07
267 #define RTD2_DR_1000 0x08
268 #define RTD2_DR_2000 0x0F
269 
281 #define RTD2_IDAC_ID 0x90
282 
288 #define RTD2_DRDY_OFF 0x00
289 #define RTD2_DRDY_ON 0x08
290 
296 #define RTD2_IDAC_OFF 0x00
297 #define RTD2_IDAC_50 0x01
298 #define RTD2_IDAC_100 0x02
299 #define RTD2_IDAC_250 0x03
300 #define RTD2_IDAC_500 0x04
301 #define RTD2_IDAC_750 0x05
302 #define RTD2_IDAC_1000 0x06
303 #define RTD2_IDAC_1500 0x07
304 
316 #define RTD2_IDAC1_A0 0xCC
317 #define RTD2_IDAC1_A1 0xDC
318 #define RTD2_IDAC1_A2 0xEC
319 #define RTD2_IDAC1_A3 0xFC
320 
326 #define RTD2_IDAC2_A0 0xCC
327 #define RTD2_IDAC2_A1 0xCD
328 #define RTD2_IDAC2_A2 0xCE
329 #define RTD2_IDAC2_A3 0xCF
330 
342 #define RTD2_GPIO_0 0x01
343 #define RTD2_GPIO_1 0x02
344 #define RTD2_GPIO_2 0x04
345 #define RTD2_GPIO_3 0x08
346 
358 #define RTD2_IO_0 0x01
359 #define RTD2_IO_1 0x02
360 #define RTD2_IO_2 0x04
361 #define RTD2_IO_3 0x08
362 
369 #define RTD2_OUT_0 0x01
370 #define RTD2_OUT_1 0x02
371 #define RTD2_OUT_2 0x04
372 #define RTD2_OUT_3 0x08
373 
379 #define RTD2_PIN_LOW 0x00
380 #define RTD2_PIN_HIGH 0x01
381 
387 #define RTD2_ERROR 0x00
388 #define RTD2_SUCESS 0x01
389 
395 #define RTD2_START_CONVERSION_DISABLE 0x00
396 #define RTD2_START_CONVERSION_ENABLE 0x01
397 
403 #define RTD2_NEW_DATA_IS_NOT_READY 0x00
404 #define RTD2_NEW_DATA_IS_READY 0x01
405 
411 #define COEFF_PT100_RESISTANCE_OHMS_0_C 100.00000000
412 #define COEFF_ALPHA 0.3920000000
413 #define COEFF_ADC_RES_RT_P 0.0000753846
414 #define COEFF_ADC_COR_FACT 50.980300000
415  // End group macro
417 // --------------------------------------------------------------- PUBLIC TYPES
426 typedef struct
427 {
428  digital_out_t cs;
429  // Output pins
430 
431  digital_out_t str;
432  digital_out_t rst;
433 
434  // Input pins
435 
436  digital_in_t rdy;
437 
438  // Modules
439 
440  spi_master_t spi;
441  pin_name_t chip_select;
442 
443 } rtd2_t;
444 
448 typedef struct
449 {
450  // Communication gpio pins
451 
452  pin_name_t miso;
453  pin_name_t mosi;
454  pin_name_t sck;
455  pin_name_t cs;
456 
457  // Additional gpio pins
458 
459  pin_name_t str;
460  pin_name_t rst;
461  pin_name_t rdy;
462 
463  // static variable
464 
465  uint32_t spi_speed;
466  spi_master_mode_t spi_mode;
467  spi_master_chip_select_polarity_t cs_polarity;
468 
469 } rtd2_cfg_t;
470  // End types group
472 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
473 
478 #ifdef __cplusplus
479 extern "C"{
480 #endif
481 
490 void rtd2_cfg_setup ( rtd2_cfg_t *cfg );
491 
501 RTD2_RETVAL rtd2_init ( rtd2_t *ctx, rtd2_cfg_t *cfg );
502 
522 void rtd2_default_cfg ( rtd2_t *ctx );
523 
536 (
537  rtd2_t *ctx,
538  uint8_t *wr_buf,
539  uint16_t wr_len,
540  uint8_t *rd_buf,
541  uint16_t rd_len
542 );
543 
556 void rtd2_hw_reset ( rtd2_t *ctx );
557 
571 void rtd2_toggle_cs ( rtd2_t *ctx, uint8_t cs_state );
572 
586 void rtd2_enable_start ( rtd2_t *ctx, uint8_t en_start );
587 
604 uint8_t rtd2_check_interupt ( rtd2_t *ctx );
605 
617 void rtd2_send_cmd ( rtd2_t *ctx, uint8_t cmd );
618 
629 void rtd2_set_wakeup ( rtd2_t *ctx );
630 
641 void rtd2_set_sleep ( rtd2_t *ctx );
642 
654 void rtd2_set_sync ( rtd2_t *ctx );
655 
667 void rtd2_set_reset ( rtd2_t *ctx );
668 
680 void rtd2_set_read_data_once ( rtd2_t *ctx );
681 
694 
706 void rtd2_set_stop_data ( rtd2_t *ctx );
707 
725 void rtd2_write_continuous ( rtd2_t *ctx, uint8_t reg, uint8_t *p_tx_data, uint8_t n_bytes );
726 
744 void rtd2_read_continuous ( rtd2_t *ctx, uint8_t reg, uint8_t *p_rx_data, uint8_t n_bytes );
745 
761 void rtd2_write_reg ( rtd2_t *ctx, uint8_t reg, uint8_t tx_data );
762 
779 uint8_t rtd2_read_reg ( rtd2_t *ctx, uint8_t reg );
780 
801 uint8_t rtd2_set_burn_out_source ( rtd2_t *ctx, uint8_t burn_out );
802 
826 void rtd2_set_mux_sel ( rtd2_t *ctx, uint8_t adc_pos, uint8_t adc_neg );
827 
849 uint8_t rtd2_set_bias ( rtd2_t *ctx, uint8_t v_bias );
850 
870 uint8_t rtd2_set_int_ref ( rtd2_t *ctx, uint8_t s_ref );
871 
891 void rtd2_set_system_monitor ( rtd2_t *ctx, uint8_t sys_mon );
892 
925 void rtd2_set_system_control ( rtd2_t *ctx, uint8_t gain, uint8_t output_rate );
926 
947 void rtd2_set_idac_current_mag ( rtd2_t *ctx, uint8_t c_idac );
948 
971 void rtd2_set_idac_current_out ( rtd2_t *ctx, uint8_t c_out_1, uint8_t c_out_2 );
972 
987 uint8_t rtd2_check_new_data_ready ( rtd2_t *ctx );
988 
1001 int32_t rtd2_read_output_data ( rtd2_t *ctx );
1002 
1017 float rtd2_calc_temperature ( int32_t adc_val );
1018 
1032 float rtd2_get_temperature ( rtd2_t *ctx );
1033 
1034 #ifdef __cplusplus
1035 }
1036 #endif
1037 #endif // _RTD2_H_
1038  // End public_function group
1041 
1042 // ------------------------------------------------------------------------- END
rtd2_set_system_control
void rtd2_set_system_control(rtd2_t *ctx, uint8_t gain, uint8_t output_rate)
Set system control function.
rtd2_cfg_t::sck
pin_name_t sck
Definition: rtd2.h:454
rtd2_t::chip_select
pin_name_t chip_select
Definition: rtd2.h:441
rtd2_set_mux_sel
void rtd2_set_mux_sel(rtd2_t *ctx, uint8_t adc_pos, uint8_t adc_neg)
Set multiplexer selection function.
rtd2_set_idac_current_out
void rtd2_set_idac_current_out(rtd2_t *ctx, uint8_t c_out_1, uint8_t c_out_2)
Set IDAC current out function.
rtd2_t::cs
digital_out_t cs
Definition: rtd2.h:428
rtd2_set_int_ref
uint8_t rtd2_set_int_ref(rtd2_t *ctx, uint8_t s_ref)
Set int ref function.
rtd2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: rtd2.h:466
rtd2_get_temperature
float rtd2_get_temperature(rtd2_t *ctx)
Get temperature function.
rtd2_calc_temperature
float rtd2_calc_temperature(int32_t adc_val)
Calculate temperature function.
rtd2_set_system_monitor
void rtd2_set_system_monitor(rtd2_t *ctx, uint8_t sys_mon)
Set system monitor function.
rtd2_send_cmd
void rtd2_send_cmd(rtd2_t *ctx, uint8_t cmd)
Send command function.
rtd2_toggle_cs
void rtd2_toggle_cs(rtd2_t *ctx, uint8_t cs_state)
Toggle CS pin function.
RTD2_RETVAL
#define RTD2_RETVAL
Definition: rtd2.h:67
rtd2_set_sleep
void rtd2_set_sleep(rtd2_t *ctx)
Set to sleep function.
rtd2_set_bias
uint8_t rtd2_set_bias(rtd2_t *ctx, uint8_t v_bias)
Set bias function.
rtd2_t::rst
digital_out_t rst
Definition: rtd2.h:432
rtd2_cfg_t::rdy
pin_name_t rdy
Definition: rtd2.h:461
rtd2_t
Click ctx object definition.
Definition: rtd2.h:426
rtd2_generic_transfer
void rtd2_generic_transfer(rtd2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
rtd2_enable_start
void rtd2_enable_start(rtd2_t *ctx, uint8_t en_start)
Enable conversion start function.
rtd2_cfg_t::spi_speed
uint32_t spi_speed
Definition: rtd2.h:465
rtd2_set_read_data_once
void rtd2_set_read_data_once(rtd2_t *ctx)
Set read data once function.
rtd2_cfg_t::rst
pin_name_t rst
Definition: rtd2.h:460
rtd2_cfg_t
Click configuration structure definition.
Definition: rtd2.h:448
rtd2_set_idac_current_mag
void rtd2_set_idac_current_mag(rtd2_t *ctx, uint8_t c_idac)
Set IDAC current magnitude function.
rtd2_cfg_t::miso
pin_name_t miso
Definition: rtd2.h:452
rtd2_cfg_t::mosi
pin_name_t mosi
Definition: rtd2.h:453
rtd2_check_new_data_ready
uint8_t rtd2_check_new_data_ready(rtd2_t *ctx)
Check new data ready function.
rtd2_t::str
digital_out_t str
Definition: rtd2.h:431
rtd2_cfg_setup
void rtd2_cfg_setup(rtd2_cfg_t *cfg)
Config Object Initialization function.
rtd2_set_sync
void rtd2_set_sync(rtd2_t *ctx)
Set sync function.
rtd2_set_read_data_continuous
void rtd2_set_read_data_continuous(rtd2_t *ctx)
Set read data continuous function.
rtd2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: rtd2.h:467
rtd2_read_output_data
int32_t rtd2_read_output_data(rtd2_t *ctx)
Read output data function.
rtd2_cfg_t::str
pin_name_t str
Definition: rtd2.h:459
rtd2_default_cfg
void rtd2_default_cfg(rtd2_t *ctx)
Set default configuration function.
rtd2_set_burn_out_source
uint8_t rtd2_set_burn_out_source(rtd2_t *ctx, uint8_t burn_out)
Set burn out source function.
rtd2_hw_reset
void rtd2_hw_reset(rtd2_t *ctx)
Hardware reset function.
rtd2_t::rdy
digital_in_t rdy
Definition: rtd2.h:436
rtd2_set_wakeup
void rtd2_set_wakeup(rtd2_t *ctx)
Set wakeup function.
rtd2_t::spi
spi_master_t spi
Definition: rtd2.h:440
rtd2_read_reg
uint8_t rtd2_read_reg(rtd2_t *ctx, uint8_t reg)
Read the register function.
rtd2_set_stop_data
void rtd2_set_stop_data(rtd2_t *ctx)
Set stop data function.
rtd2_set_reset
void rtd2_set_reset(rtd2_t *ctx)
Set reset function.
rtd2_read_continuous
void rtd2_read_continuous(rtd2_t *ctx, uint8_t reg, uint8_t *p_rx_data, uint8_t n_bytes)
Continuous read the data function.
rtd2_write_continuous
void rtd2_write_continuous(rtd2_t *ctx, uint8_t reg, uint8_t *p_tx_data, uint8_t n_bytes)
Continuous write the data function.
rtd2_write_reg
void rtd2_write_reg(rtd2_t *ctx, uint8_t reg, uint8_t tx_data)
Write the register function.
rtd2_cfg_t::cs
pin_name_t cs
Definition: rtd2.h:455
rtd2_init
RTD2_RETVAL rtd2_init(rtd2_t *ctx, rtd2_cfg_t *cfg)
Initialization function.
rtd2_check_interupt
uint8_t rtd2_check_interupt(rtd2_t *ctx)
Check interrupt status function.