diffpress2 2.0.0.0
diffpress2.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef DIFFPRESS2_H
29#define DIFFPRESS2_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
73#define DIFFPRESS2_CMD_START_CONT_MEAS_MASS_FLOW_AVG 0x3603
74#define DIFFPRESS2_CMD_START_CONT_MEAS_MASS_FLOW_NONE 0x3608
75#define DIFFPRESS2_CMD_START_CONT_MEAS_DIFF_PRESS_AVG 0x3615
76#define DIFFPRESS2_CMD_START_CONT_MEAS_DIFF_PRESS_NONE 0x361E
77#define DIFFPRESS2_CMD_STOP_CONT_MEAS 0x3FF9
78#define DIFFPRESS2_CMD_TRIGGER_MEAS_MASS_FLOW 0x3624
79#define DIFFPRESS2_CMD_TRIGGER_MEAS_MASS_FLOW_STRETCH 0x3726
80#define DIFFPRESS2_CMD_TRIGGER_MEAS_DIFF_PRESS 0x362F
81#define DIFFPRESS2_CMD_TRIGGER_MEAS_DIFF_PRESS_STRETCH 0x372D
82#define DIFFPRESS2_CMD_PRODUCT_ID_PT1 0x367C
83#define DIFFPRESS2_CMD_PRODUCT_ID_PT2 0xE102
84
85 // diffpress2_reg
86
101#define DIFFPRESS2_PRODUCT_ID 0x03010101
102#define DIFFPRESS2_PRESSURE_SCALE_FACOTR 60.0
103#define DIFFPRESS2_TEMPERATURE_SCALE_FACOTR 200.0
104
110#define DIFFPRESS2_SET_DEV_ADDR_GND 0x21
111#define DIFFPRESS2_SET_DEV_ADDR_R4 0x22
112#define DIFFPRESS2_SET_DEV_ADDR DIFFPRESS2_SET_DEV_ADDR_R4
113
114 // diffpress2_set
115
130#define DIFFPRESS2_MAP_MIKROBUS( cfg, mikrobus ) \
131 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
132 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
133 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
134
135 // diffpress2_map
136 // diffpress2
137
142typedef struct
143{
144 // Input pins
145 digital_in_t int_pin;
147 // Modules
148 i2c_master_t i2c;
150 // I2C slave address
153 //ID's
154 uint32_t product_id;
155 uint32_t serial_id[ 2 ];
156
158
163typedef struct
164{
165 pin_name_t scl;
166 pin_name_t sda;
168 pin_name_t int_pin;
170 uint32_t i2c_speed;
171 uint8_t i2c_address;
174
185
202
218
233
246err_t diffpress2_send_command ( diffpress2_t *ctx, uint16_t cmd );
247
262err_t diffpress2_generic_read ( diffpress2_t *ctx, uint16_t cmd, uint16_t *rx_buf, uint8_t rx_len );
263
277err_t diffpress2_raw_read ( diffpress2_t *ctx, uint16_t *rx_buf, uint8_t rx_len );
278
292
305
321err_t diffpress2_trigger_measurement ( diffpress2_t *ctx, uint16_t trigger_type,
322 float *diff_press, float *temperature );
323
324#ifdef __cplusplus
325}
326#endif
327#endif // DIFFPRESS2_H
328
329 // diffpress2
330
331// ------------------------------------------------------------------------ END
diffpress2_return_value_t
Diff Press 2 Click return value data.
Definition diffpress2.h:180
@ DIFFPRESS2_ERROR
Definition diffpress2.h:182
@ DIFFPRESS2_OK
Definition diffpress2.h:181
err_t diffpress2_reset(diffpress2_t *ctx)
Reset device.
void diffpress2_cfg_setup(diffpress2_cfg_t *cfg)
Diff Press 2 configuration object setup function.
err_t diffpress2_default_cfg(diffpress2_t *ctx)
Diff Press 2 default configuration function.
err_t diffpress2_raw_read(diffpress2_t *ctx, uint16_t *rx_buf, uint8_t rx_len)
Reading function.
err_t diffpress2_send_command(diffpress2_t *ctx, uint16_t cmd)
Command writing function.
err_t diffpress2_init(diffpress2_t *ctx, diffpress2_cfg_t *cfg)
Diff Press 2 initialization function.
err_t diffpress2_generic_read(diffpress2_t *ctx, uint16_t cmd, uint16_t *rx_buf, uint8_t rx_len)
Command reading function.
err_t diffpress2_get_id(diffpress2_t *ctx)
Reads device ID's.
err_t diffpress2_trigger_measurement(diffpress2_t *ctx, uint16_t trigger_type, float *diff_press, float *temperature)
Pressure and temperature reading.
Diff Press 2 Click configuration object.
Definition diffpress2.h:164
uint32_t i2c_speed
Definition diffpress2.h:170
pin_name_t scl
Definition diffpress2.h:165
pin_name_t int_pin
Definition diffpress2.h:168
pin_name_t sda
Definition diffpress2.h:166
uint8_t i2c_address
Definition diffpress2.h:171
Diff Press 2 Click context object.
Definition diffpress2.h:143
uint32_t product_id
Definition diffpress2.h:154
digital_in_t int_pin
Definition diffpress2.h:145
i2c_master_t i2c
Definition diffpress2.h:148
uint8_t slave_address
Definition diffpress2.h:151