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
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 DIFFPRESS4_REG_COMMAND 0x22
60 #define DIFFPRESS4_REG_TEMPERATURE 0x2E
61 #define DIFFPRESS4_REG_PRESSURE 0x30
62 #define DIFFPRESS4_REG_STATUS_SYNC 0x32
63 #define DIFFPRESS4_REG_STATUS 0x36
64 #define DIFFPRESS4_REG_SER0 0x50
65 #define DIFFPRESS4_REG_SER1 0x52
66  // diffpress4_reg
68 
83 #define DIFFPRESS4_P_MIN -250.0f
84 #define DIFFPRESS4_P_MAX 250.0f
85 #define DIFFPRESS4_OUT_MIN -26215.0f
86 #define DIFFPRESS4_OUT_MAX 26214.0f
87 #define DIFFPRESS4_B_0 -16881.0f
88 #define DIFFPRESS4_B_1 397.2f
89 
94 #define DIFFPRESS4_STATUS_IDLE_CHIP_BUSY 0x00
95 #define DIFFPRESS4_STATUS_IDLE_CHIP_IDLE 0x01
96 #define DIFFPRESS4_STATUS_DSP_S_CLEARED 0x00
97 #define DIFFPRESS4_STATUS_DSP_S_UPDATED 0x01
98 #define DIFFPRESS4_STATUS_DSP_T_CLEARED 0x00
99 #define DIFFPRESS4_STATUS_DSP_T_UPDATED 0x01
100 #define DIFFPRESS4_STATUS_BS_FAIL_NO_FAILURE 0x00
101 #define DIFFPRESS4_STATUS_BS_FAIL_OCCURRED 0x01
102 #define DIFFPRESS4_STATUS_BC_FAIL_NO_FAILURE 0x00
103 #define DIFFPRESS4_STATUS_BC_FAIL_OCCURRED 0x01
104 #define DIFFPRESS4_STATUS_DSP_SAT_NORMAL 0x00
105 #define DIFFPRESS4_STATUS_DSP_SAT_OVERFLOW 0x01
106 #define DIFFPRESS4_STATUS_COM_CRC_OK 0x00
107 #define DIFFPRESS4_STATUS_COM_CRC_ERROR 0x01
108 #define DIFFPRESS4_STATUS_DSP_S_MISSED 0x00
109 #define DIFFPRESS4_STATUS_DSP_S_M_UPDATED 0x01
110 #define DIFFPRESS4_STATUS_DSP_T_MISSED 0x00
111 #define DIFFPRESS4_STATUS_DSP_T_M_UPDATED 0x01
112 
117 #define DIFFPRESS4_SET_CMD_SLEEP_MODE 0x32, 0x6C
118 #define DIFFPRESS4_SET_CMD_RESET 0x69, 0xB1
119 
125 #define DIFFPRESS4_DEVICE_ADDRESS_UNPROTECTED 0x6C
126 #define DIFFPRESS4_DEVICE_ADDRESS_CRC_PROTECTED 0x6D
127  // diffpress4_set
129 
144 #define DIFFPRESS4_MAP_MIKROBUS( cfg, mikrobus ) \
145  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
146  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
147  // diffpress4_map // diffpress4
150 
155 typedef struct
156 {
157  // Modules
158  i2c_master_t i2c;
160  // I2C slave address
161  uint8_t slave_address;
163 } diffpress4_t;
164 
169 typedef struct
170 {
171  pin_name_t scl;
172  pin_name_t sda;
174  uint32_t i2c_speed;
175  uint8_t i2c_address;
178 
183 typedef struct
184 {
185  uint8_t idle;
186  uint8_t dsp_s_up;
187  uint8_t dsp_t_up;
188  uint8_t bs_fail;
189  uint8_t bc_fail;
190  uint8_t dsp_sat;
192  uint8_t com_crc_error;
193  uint8_t dsp_s_missed;
194  uint8_t dsp_t_missed;
197 
202 typedef enum
203 {
205  DIFFPRESS4_ERROR = -1
206 
208 
225 
240 
253 err_t diffpress4_set_slave_address ( diffpress4_t *ctx, uint8_t slave_address );
254 
269 err_t diffpress4_generic_write ( diffpress4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
270 
285 err_t diffpress4_generic_read ( diffpress4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
286 
299 
313 
326 err_t diffpress4_get_serial_number ( diffpress4_t *ctx, uint32_t *serial_number );
327 
342 
356 err_t diffpress4_get_raw_data ( diffpress4_t *ctx, int16_t *temp_data, int16_t *press_data );
357 
371 err_t diffpress4_get_measurement_data ( diffpress4_t *ctx, float *diff_press, float *temperature );
372 
373 #ifdef __cplusplus
374 }
375 #endif
376 #endif // DIFFPRESS4_H
377  // diffpress4
379 
380 // ------------------------------------------------------------------------ END
diffpress4_status_t::dsp_t_up
uint8_t dsp_t_up
Definition: diffpress4.h:187
diffpress4_init
err_t diffpress4_init(diffpress4_t *ctx, diffpress4_cfg_t *cfg)
Diff Press 4 initialization function.
diffpress4_t
Diff Press 4 Click context object.
Definition: diffpress4.h:156
diffpress4_cfg_t
Diff Press 4 Click configuration object.
Definition: diffpress4.h:170
diffpress4_status_t::dsp_sat
uint8_t dsp_sat
Definition: diffpress4.h:190
diffpress4_status_t::bs_fail
uint8_t bs_fail
Definition: diffpress4.h:188
diffpress4_generic_read
err_t diffpress4_generic_read(diffpress4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Diff Press 4 I2C reading function.
diffpress4_get_status
err_t diffpress4_get_status(diffpress4_t *ctx, diffpress4_status_t *status)
Diff Press 4 get status function.
DIFFPRESS4_ERROR
@ DIFFPRESS4_ERROR
Definition: diffpress4.h:205
diffpress4_get_raw_data
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.
diffpress4_get_measurement_data
err_t diffpress4_get_measurement_data(diffpress4_t *ctx, float *diff_press, float *temperature)
Diff Press 4 gets the raw data function.
diffpress4_get_serial_number
err_t diffpress4_get_serial_number(diffpress4_t *ctx, uint32_t *serial_number)
Diff Press 4 get serial number function.
diffpress4_cfg_t::scl
pin_name_t scl
Definition: diffpress4.h:171
diffpress4_return_value_t
diffpress4_return_value_t
Diff Press 4 Click return value data.
Definition: diffpress4.h:203
diffpress4_cfg_setup
void diffpress4_cfg_setup(diffpress4_cfg_t *cfg)
Diff Press 4 configuration object setup function.
diffpress4_status_t::dsp_t_missed
uint8_t dsp_t_missed
Definition: diffpress4.h:194
diffpress4_cfg_t::sda
pin_name_t sda
Definition: diffpress4.h:172
DIFFPRESS4_OK
@ DIFFPRESS4_OK
Definition: diffpress4.h:204
diffpress4_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: diffpress4.h:174
diffpress4_cfg_t::i2c_address
uint8_t i2c_address
Definition: diffpress4.h:175
diffpress4_status_t
Diff Press 4 Click status object.
Definition: diffpress4.h:184
diffpress4_status_t::dsp_s_up
uint8_t dsp_s_up
Definition: diffpress4.h:186
diffpress4_set_sleep_mode
err_t diffpress4_set_sleep_mode(diffpress4_t *ctx)
Diff Press 4 set sleep mode function.
diffpress4_set_slave_address
err_t diffpress4_set_slave_address(diffpress4_t *ctx, uint8_t slave_address)
Diff Press 4 set I2C Slave address function.
diffpress4_sw_reset
err_t diffpress4_sw_reset(diffpress4_t *ctx)
Diff Press 4 software reset function.
diffpress4_status_t::bc_fail
uint8_t bc_fail
Definition: diffpress4.h:189
diffpress4_status_t::dsp_s_missed
uint8_t dsp_s_missed
Definition: diffpress4.h:193
diffpress4_t::i2c
i2c_master_t i2c
Definition: diffpress4.h:158
diffpress4_generic_write
err_t diffpress4_generic_write(diffpress4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Diff Press 4 I2C writing function.
diffpress4_t::slave_address
uint8_t slave_address
Definition: diffpress4.h:161
diffpress4_status_t::com_crc_error
uint8_t com_crc_error
Definition: diffpress4.h:192
diffpress4_status_t::idle
uint8_t idle
Definition: diffpress4.h:185