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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define DIFFPRESS2_CMD_START_CONT_MEAS_MASS_FLOW_AVG 0x3603
60 #define DIFFPRESS2_CMD_START_CONT_MEAS_MASS_FLOW_NONE 0x3608
61 #define DIFFPRESS2_CMD_START_CONT_MEAS_DIFF_PRESS_AVG 0x3615
62 #define DIFFPRESS2_CMD_START_CONT_MEAS_DIFF_PRESS_NONE 0x361E
63 #define DIFFPRESS2_CMD_STOP_CONT_MEAS 0x3FF9
64 #define DIFFPRESS2_CMD_TRIGGER_MEAS_MASS_FLOW 0x3624
65 #define DIFFPRESS2_CMD_TRIGGER_MEAS_MASS_FLOW_STRETCH 0x3726
66 #define DIFFPRESS2_CMD_TRIGGER_MEAS_DIFF_PRESS 0x362F
67 #define DIFFPRESS2_CMD_TRIGGER_MEAS_DIFF_PRESS_STRETCH 0x372D
68 #define DIFFPRESS2_CMD_PRODUCT_ID_PT1 0x367C
69 #define DIFFPRESS2_CMD_PRODUCT_ID_PT2 0xE102
70  // diffpress2_reg
72 
87 #define DIFFPRESS2_PRODUCT_ID 0x03010101
88 #define DIFFPRESS2_PRESSURE_SCALE_FACOTR 60.0
89 #define DIFFPRESS2_TEMPERATURE_SCALE_FACOTR 200.0
90 
96 #define DIFFPRESS2_SET_DEV_ADDR_GND 0x21
97 #define DIFFPRESS2_SET_DEV_ADDR_R4 0x22
98 #define DIFFPRESS2_SET_DEV_ADDR DIFFPRESS2_SET_DEV_ADDR_R4
99  // diffpress2_set
101 
116 #define DIFFPRESS2_MAP_MIKROBUS( cfg, mikrobus ) \
117  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
118  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
119  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
120  // diffpress2_map // diffpress2
123 
128 typedef struct
129 {
130  // Input pins
131  digital_in_t int_pin;
133  // Modules
134  i2c_master_t i2c;
136  // I2C slave address
137  uint8_t slave_address;
139  //ID's
140  uint32_t product_id;
141  uint32_t serial_id[ 2 ];
142 
143 } diffpress2_t;
144 
149 typedef struct
150 {
151  pin_name_t scl;
152  pin_name_t sda;
154  pin_name_t int_pin;
156  uint32_t i2c_speed;
157  uint8_t i2c_address;
160 
165 typedef enum
166 {
168  DIFFPRESS2_ERROR = -1
169 
171 
188 
204 
219 
232 err_t diffpress2_send_command ( diffpress2_t *ctx, uint16_t cmd );
233 
248 err_t diffpress2_generic_read ( diffpress2_t *ctx, uint16_t cmd, uint16_t *rx_buf, uint8_t rx_len );
249 
263 err_t diffpress2_raw_read ( diffpress2_t *ctx, uint16_t *rx_buf, uint8_t rx_len );
264 
278 
291 
307 err_t diffpress2_trigger_measurement ( diffpress2_t *ctx, uint16_t trigger_type,
308  float *diff_press, float *temperature );
309 
310 #ifdef __cplusplus
311 }
312 #endif
313 #endif // DIFFPRESS2_H
314  // diffpress2
316 
317 // ------------------------------------------------------------------------ END
diffpress2_t::slave_address
uint8_t slave_address
Definition: diffpress2.h:137
diffpress2_default_cfg
err_t diffpress2_default_cfg(diffpress2_t *ctx)
Diff Press 2 default configuration function.
diffpress2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: diffpress2.h:156
diffpress2_cfg_t::i2c_address
uint8_t i2c_address
Definition: diffpress2.h:157
diffpress2_raw_read
err_t diffpress2_raw_read(diffpress2_t *ctx, uint16_t *rx_buf, uint8_t rx_len)
Reading function.
diffpress2_generic_read
err_t diffpress2_generic_read(diffpress2_t *ctx, uint16_t cmd, uint16_t *rx_buf, uint8_t rx_len)
Command reading function.
diffpress2_cfg_t::scl
pin_name_t scl
Definition: diffpress2.h:151
diffpress2_init
err_t diffpress2_init(diffpress2_t *ctx, diffpress2_cfg_t *cfg)
Diff Press 2 initialization function.
diffpress2_cfg_t::int_pin
pin_name_t int_pin
Definition: diffpress2.h:154
DIFFPRESS2_OK
@ DIFFPRESS2_OK
Definition: diffpress2.h:167
diffpress2_t::product_id
uint32_t product_id
Definition: diffpress2.h:140
diffpress2_cfg_t::sda
pin_name_t sda
Definition: diffpress2.h:152
diffpress2_t
Diff Press 2 Click context object.
Definition: diffpress2.h:129
DIFFPRESS2_ERROR
@ DIFFPRESS2_ERROR
Definition: diffpress2.h:168
diffpress2_reset
err_t diffpress2_reset(diffpress2_t *ctx)
Reset device.
diffpress2_trigger_measurement
err_t diffpress2_trigger_measurement(diffpress2_t *ctx, uint16_t trigger_type, float *diff_press, float *temperature)
Pressure and temperature reading.
diffpress2_send_command
err_t diffpress2_send_command(diffpress2_t *ctx, uint16_t cmd)
Command writing function.
diffpress2_t::i2c
i2c_master_t i2c
Definition: diffpress2.h:134
diffpress2_get_id
err_t diffpress2_get_id(diffpress2_t *ctx)
Reads device ID's.
diffpress2_return_value_t
diffpress2_return_value_t
Diff Press 2 Click return value data.
Definition: diffpress2.h:166
diffpress2_cfg_setup
void diffpress2_cfg_setup(diffpress2_cfg_t *cfg)
Diff Press 2 configuration object setup function.
diffpress2_t::int_pin
digital_in_t int_pin
Definition: diffpress2.h:131
diffpress2_cfg_t
Diff Press 2 Click configuration object.
Definition: diffpress2.h:150