diffpress4 2.1.0.0
diffpress4.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 DIFFPRESS4_H
29#define DIFFPRESS4_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 DIFFPRESS4_REG_COMMAND 0x22
74#define DIFFPRESS4_REG_TEMPERATURE 0x2E
75#define DIFFPRESS4_REG_PRESSURE 0x30
76#define DIFFPRESS4_REG_STATUS_SYNC 0x32
77#define DIFFPRESS4_REG_STATUS 0x36
78#define DIFFPRESS4_REG_SER0 0x50
79#define DIFFPRESS4_REG_SER1 0x52
80
81 // diffpress4_reg
82
97#define DIFFPRESS4_P_MIN -250.0f
98#define DIFFPRESS4_P_MAX 250.0f
99#define DIFFPRESS4_OUT_MIN -26215.0f
100#define DIFFPRESS4_OUT_MAX 26214.0f
101#define DIFFPRESS4_B_0 -16881.0f
102#define DIFFPRESS4_B_1 397.2f
103
108#define DIFFPRESS4_STATUS_IDLE_CHIP_BUSY 0x00
109#define DIFFPRESS4_STATUS_IDLE_CHIP_IDLE 0x01
110#define DIFFPRESS4_STATUS_DSP_S_CLEARED 0x00
111#define DIFFPRESS4_STATUS_DSP_S_UPDATED 0x01
112#define DIFFPRESS4_STATUS_DSP_T_CLEARED 0x00
113#define DIFFPRESS4_STATUS_DSP_T_UPDATED 0x01
114#define DIFFPRESS4_STATUS_BS_FAIL_NO_FAILURE 0x00
115#define DIFFPRESS4_STATUS_BS_FAIL_OCCURRED 0x01
116#define DIFFPRESS4_STATUS_BC_FAIL_NO_FAILURE 0x00
117#define DIFFPRESS4_STATUS_BC_FAIL_OCCURRED 0x01
118#define DIFFPRESS4_STATUS_DSP_SAT_NORMAL 0x00
119#define DIFFPRESS4_STATUS_DSP_SAT_OVERFLOW 0x01
120#define DIFFPRESS4_STATUS_COM_CRC_OK 0x00
121#define DIFFPRESS4_STATUS_COM_CRC_ERROR 0x01
122#define DIFFPRESS4_STATUS_DSP_S_MISSED 0x00
123#define DIFFPRESS4_STATUS_DSP_S_M_UPDATED 0x01
124#define DIFFPRESS4_STATUS_DSP_T_MISSED 0x00
125#define DIFFPRESS4_STATUS_DSP_T_M_UPDATED 0x01
126
131#define DIFFPRESS4_SET_CMD_SLEEP_MODE 0x32, 0x6C
132#define DIFFPRESS4_SET_CMD_RESET 0x69, 0xB1
133
139#define DIFFPRESS4_DEVICE_ADDRESS_UNPROTECTED 0x6C
140#define DIFFPRESS4_DEVICE_ADDRESS_CRC_PROTECTED 0x6D
141
142 // diffpress4_set
143
158#define DIFFPRESS4_MAP_MIKROBUS( cfg, mikrobus ) \
159 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
160 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
161
162 // diffpress4_map
163 // diffpress4
164
169typedef struct
170{
171 // Modules
172 i2c_master_t i2c;
174 // I2C slave address
178
183typedef struct
184{
185 pin_name_t scl;
186 pin_name_t sda;
188 uint32_t i2c_speed;
189 uint8_t i2c_address;
192
197typedef struct
198{
199 uint8_t idle;
200 uint8_t dsp_s_up;
201 uint8_t dsp_t_up;
202 uint8_t bs_fail;
203 uint8_t bc_fail;
204 uint8_t dsp_sat;
207 uint8_t dsp_s_missed;
208 uint8_t dsp_t_missed;
211
222
239
254
267err_t diffpress4_set_slave_address ( diffpress4_t *ctx, uint8_t slave_address );
268
283err_t diffpress4_generic_write ( diffpress4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
284
299err_t diffpress4_generic_read ( diffpress4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
300
313
327
340err_t diffpress4_get_serial_number ( diffpress4_t *ctx, uint32_t *serial_number );
341
356
370err_t diffpress4_get_raw_data ( diffpress4_t *ctx, int16_t *temp_data, int16_t *press_data );
371
385err_t diffpress4_get_measurement_data ( diffpress4_t *ctx, float *diff_press, float *temperature );
386
387#ifdef __cplusplus
388}
389#endif
390#endif // DIFFPRESS4_H
391
392 // diffpress4
393
394// ------------------------------------------------------------------------ END
diffpress4_return_value_t
Diff Press 4 Click return value data.
Definition diffpress4.h:217
@ DIFFPRESS4_ERROR
Definition diffpress4.h:219
@ DIFFPRESS4_OK
Definition diffpress4.h:218
err_t diffpress4_generic_read(diffpress4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Diff Press 4 I2C reading function.
err_t diffpress4_generic_write(diffpress4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Diff Press 4 I2C writing function.
err_t diffpress4_get_measurement_data(diffpress4_t *ctx, float *diff_press, float *temperature)
Diff Press 4 gets the raw data function.
err_t diffpress4_set_sleep_mode(diffpress4_t *ctx)
Diff Press 4 set sleep mode function.
err_t diffpress4_init(diffpress4_t *ctx, diffpress4_cfg_t *cfg)
Diff Press 4 initialization function.
err_t diffpress4_set_slave_address(diffpress4_t *ctx, uint8_t slave_address)
Diff Press 4 set I2C Slave address function.
err_t diffpress4_get_raw_data(diffpress4_t *ctx, int16_t *temp_data, int16_t *press_data)
Diff Press 4 gets the raw data function.
void diffpress4_cfg_setup(diffpress4_cfg_t *cfg)
Diff Press 4 configuration object setup function.
err_t diffpress4_sw_reset(diffpress4_t *ctx)
Diff Press 4 software reset function.
err_t diffpress4_get_serial_number(diffpress4_t *ctx, uint32_t *serial_number)
Diff Press 4 get serial number function.
err_t diffpress4_get_status(diffpress4_t *ctx, diffpress4_status_t *status)
Diff Press 4 get status function.
Diff Press 4 Click configuration object.
Definition diffpress4.h:184
uint32_t i2c_speed
Definition diffpress4.h:188
pin_name_t scl
Definition diffpress4.h:185
pin_name_t sda
Definition diffpress4.h:186
uint8_t i2c_address
Definition diffpress4.h:189
Diff Press 4 Click status object.
Definition diffpress4.h:198
uint8_t dsp_s_up
Definition diffpress4.h:200
uint8_t bc_fail
Definition diffpress4.h:203
uint8_t dsp_t_up
Definition diffpress4.h:201
uint8_t dsp_s_missed
Definition diffpress4.h:207
uint8_t dsp_sat
Definition diffpress4.h:204
uint8_t bs_fail
Definition diffpress4.h:202
uint8_t dsp_t_missed
Definition diffpress4.h:208
uint8_t com_crc_error
Definition diffpress4.h:206
uint8_t idle
Definition diffpress4.h:199
Diff Press 4 Click context object.
Definition diffpress4.h:170
i2c_master_t i2c
Definition diffpress4.h:172
uint8_t slave_address
Definition diffpress4.h:175