pressure9 2.0.0.0
pressure9.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 PRESSURE9_H
36#define PRESSURE9_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_in.h"
53#include "drv_digital_out.h"
54#include "drv_i2c_master.h"
55#include "drv_spi_master.h"
56
57// -------------------------------------------------------------- PUBLIC MACROS
68#define PRESSURE9_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
70 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
71 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
72 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
73 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
74 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
81#define PRESSURE9_MASTER_I2C 0
82#define PRESSURE9_MASTER_SPI 1
89#define PRESSURE9_OK 0
90#define PRESSURE9_ERROR -1
97#define PRESSURE9_REG_PRESSURE_DATA_B2 0x00
98#define PRESSURE9_REG_PRESSURE_DATA_B1 0x01
99#define PRESSURE9_REG_PRESSURE_DATA_B0 0x02
100#define PRESSURE9_REG_TEMPERATRE_DATA_B2 0x03
101#define PRESSURE9_REG_TEMPERATRE_DATA_B1 0x04
102#define PRESSURE9_REG_TEMPERATRE_DATA_B0 0x05
103#define PRESSURE9_REG_PRESSURE_CONFIG 0x06
104#define PRESSURE9_REG_TEMPERATURE_CONFIG 0x07
105#define PRESSURE9_REG_MEASUREMENT_CONFIG 0x08
106#define PRESSURE9_REG_CONFIGURATION 0x09
107#define PRESSURE9_REG_INT_STATUS 0x0A
108#define PRESSURE9_REG_WATERMARK_CONFIG 0x0B
109#define PRESSURE9_REG_FIFO_STATUS 0x0C
110#define PRESSURE9_REG_RESET 0x0D
111#define PRESSURE9_REG_PRODUCT_ID 0x1D
112#define PRESSURE9_T_GAIN_COEFF 0x20
113#define PRESSURE9_T_DVBE_COEFF 0x21
114#define PRESSURE9_T_VBE_COEFF 0x22
115#define PRESSURE9_COEFF_REG_1 0x26
116#define PRESSURE9_COEFF_REG_2 0x27
117#define PRESSURE9_COEFF_REG_3 0x28
118#define PRESSURE9_COEFF_REG_4 0x29
119#define PRESSURE9_COEFF_REG_5 0x2A
120#define PRESSURE9_COEFF_REG_6 0x2B
121#define PRESSURE9_COEFF_REG_7 0x2C
122#define PRESSURE9_COEFF_REG_8 0x2D
123#define PRESSURE9_COEFF_REG_9 0x2E
124#define PRESSURE9_COEFF_REG_10 0x2F
125#define PRESSURE9_COEFF_REG_11 0x30
126#define PRESSURE9_COEFF_REG_12 0x31
127#define PRESSURE9_COEFF_REG_13 0x32
128#define PRESSURE9_COEFF_REG_14 0x33
129#define PRESSURE9_COEFF_REG_15 0x34
130#define PRESSURE9_COEFF_REG_16 0x35
131#define PRESSURE9_COEFF_REG_17 0x36
132#define PRESSURE9_COEFF_REG_18 0x37
139#define PRESSURE9_PTCFG_RATE_1_SAMPLE_SEC 0x00
140#define PRESSURE9_PTCFG_RATE_2_SAMPLES_SEC 0x10
141#define PRESSURE9_PTCFG_RATE_4_SAMPLES_SEC 0x20
142#define PRESSURE9_PTCFG_RATE_8_SAMPLES_SEC 0x30
143#define PRESSURE9_PTCFG_RATE_16_SAMPLES_SEC 0x40
144#define PRESSURE9_PTCFG_RATE_32_SAMPLES_SEC 0x50
145#define PRESSURE9_PTCFG_RATE_64_SAMPLES_SEC 0x60
146#define PRESSURE9_PTCFG_RATE_128_SAMPLES_SEC 0x70
147#define PRESSURE9_PTCFG_RES_X1_256_SAMPLES 0x00
148#define PRESSURE9_PTCFG_RES_X2_512_SAMPLES 0x01
149#define PRESSURE9_PTCFG_RES_X4_1024_SAMPLES 0x02
150#define PRESSURE9_PTCFG_RES_X8_2048_SAMPLES 0x03
151#define PRESSURE9_PTCFG_RES_X16_4096_SAMPLES 0x04
152#define PRESSURE9_PTCFG_RES_X32_8192_SAMPLES 0x05
153#define PRESSURE9_PTCFG_RES_X64_16384_SAMPLES 0x06
154#define PRESSURE9_PTCFG_RES_X128_32768_SAMPLES 0x07
160#define PRESSURE9_MCFG_IDLE_STOP_BACKGROUND 0x00
161#define PRESSURE9_MCFG_PRESSURE_MEASUREMENT 0x01
162#define PRESSURE9_MCFG_TEMPERATURE_MEASUREMENT 0x02
163#define PRESSURE9_MCFG_TEMP_AND_PRESS_ONE_SHOT 0x03
164#define PRESSURE9_MCFG_PRESSURE_MEASUREMENT_CONT 0x05
165#define PRESSURE9_MCFG_TEMPERATURE_MEASUREMENT_CONT 0x06
166#define PRESSURE9_MCFG_TEMP_AND_PRESS_CONT 0x07
172#define PRESSURE9_CFG_SINT_NO_INT_ENABLED 0x00
173#define PRESSURE9_CFG_SINT_PRESS_INT_ENABLED 0x10
174#define PRESSURE9_CFG_SINT_TEMP_INT_ENABLED 0x20
175#define PRESSURE9_CFG_SINT_PRESS_AND_TEMP_INT_EN 0x30
176#define PRESSURE9_CFG_SINT_FIFO_WM_INT_ENABLED 0x40
177#define PRESSURE9_CFG_SINT_FIFO_FULL_INT_ENABLED 0x80
178#define PRESSURE9_CFG_PINT_INT_ACTIVE_LOW 0x00
179#define PRESSURE9_CFG_PINT_INT_ACTIVE_HIGH 0x08
180#define PRESSURE9_CFG_FIFO_SF_STREAMING_MODE 0x00
181#define PRESSURE9_CFG_FIFO_SF_FULL_MODE 0x04
182#define PRESSURE9_CFG_FIFO_EN_ENABLED 0x02
183#define PRESSURE9_CFG_FIFO_EN_DISABLED 0x00
184#define PRESSURE9_CFG_SPI_MODE_4_WIRE 0x00
185#define PRESSURE9_CFG_SPI_MODE_3_WIRE 0x01
191#define PRESSURE9_RESET_CONFIGURATION_REG 0x08
192#define PRESSURE9_FULL_SOFTWARE_RESET 0x09
193#define PRESSURE9_FIFO_FLUSH 0x80
199#define PRESSURE9_DEV_SLAVE_ADR_GND 0x76
200#define PRESSURE9_DEV_SLAVE_ADR_VCC 0x77
201#define PRESSURE9_PRODUCT_ID 0x1A
207#define PRESSURE9_PRESSURE_COEFFICIENT_C00 0x00
208#define PRESSURE9_PRESSURE_COEFFICIENT_C01 0x01
209#define PRESSURE9_PRESSURE_COEFFICIENT_C02 0x02
210#define PRESSURE9_PRESSURE_COEFFICIENT_C10 0x10
211#define PRESSURE9_PRESSURE_COEFFICIENT_C20 0x20
212#define PRESSURE9_PRESSURE_COEFFICIENT_C30 0x30
213#define PRESSURE9_PRESSURE_COEFFICIENT_C11 0x11
214#define PRESSURE9_PRESSURE_COEFFICIENT_C12 0x12
215#define PRESSURE9_PRESSURE_COEFFICIENT_C21 0x21
216#define PRESSURE9_TEMP_COEFFICIENT_T_GAIN 0x03
217#define PRESSURE9_TEMP_COEFFICIENT_T_DVBE 0x04
218#define PRESSURE9_TEMP_COEFFICIENT_T_VBE 0x05
219#define PRESSURE9_COEFF_CAL_00 0x00
220#define PRESSURE9_COEFF_CAL_10 0x10
221#define PRESSURE9_COEFF_CAL_01 0x01
222#define PRESSURE9_COEFF_CAL_02 0x02
223#define PRESSURE9_COEFF_CAL_20 0x20
224#define PRESSURE9_COEFF_CAL_30 0x30
225#define PRESSURE9_COEFF_CAL_11 0x11
226#define PRESSURE9_COEFF_CAL_12 0x12
227#define PRESSURE9_COEFF_CAL_21 0x21
228#define PRESSURE9_COEFF_T_GAIN 0x03
229#define PRESSURE9_COEFF_T_DVBE 0x04
230#define PRESSURE9_COEFF_T_VBE 0x05
233 // End group macro
234// --------------------------------------------------------------- PUBLIC TYPES
243typedef void ( *pressure9_master_io_t )( struct pressure9_s*, uint8_t, uint8_t*, uint8_t );
244
248typedef struct
249{
250 int32_t cal_00;
251 int32_t cal_10;
252 int32_t cal_01;
253 int32_t cal_02;
254 int32_t cal_20;
255 int32_t cal_30;
256 int32_t cal_11;
257 int32_t cal_12;
258 int32_t cal_21;
259
261
265typedef struct
266{
267 int32_t t_gain;
268 int32_t t_dvbe;
269 int32_t t_vbe;
270 float vbe;
271 float dvbe;
272 float adc_val;
273 float vbe_cal;
274 float dvbe_cal;
275 float t_cal;
277 float kptat;
278 float ap;
279 float bp;
280
282
286typedef struct pressure9_s
287{
288 // Output pins
289 digital_out_t cs;
290
291 // Modules
292 i2c_master_t i2c;
293 spi_master_t spi;
294
295 // ctx variable
297 pin_name_t chip_select;
300 uint8_t master_sel;
301
302 // Pressure calibration coefficient
304
305 // Temperature calibration coefficient
307
308 uint32_t pressure_res;
309 uint8_t press_buf[ 20 ];
310 uint8_t temp_buf[ 3 ];
311
313
317typedef struct
318{
319 // Communication gpio pins
320 pin_name_t scl;
321 pin_name_t sda;
322 pin_name_t miso;
323 pin_name_t mosi;
324 pin_name_t sck;
325 pin_name_t cs;
326
327 // static variable
328 uint32_t i2c_speed;
329 uint8_t i2c_address;
330
331 uint32_t spi_speed;
332 spi_master_mode_t spi_mode;
333 spi_master_chip_select_polarity_t cs_polarity;
334
335 uint8_t sel;
336
338
339 // End types group
340// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
346#ifdef __cplusplus
347extern "C"{
348#endif
349
359
369
378
389void pressure9_generic_write ( pressure9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
390
401void pressure9_generic_read ( pressure9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
402
412void pressure9_configuration ( pressure9_t *ctx, uint8_t reg_adr, uint8_t data_in );
413
424int32_t pressure9_get_coefficients ( pressure9_t *ctx, uint8_t coeff );
425
433
441
449
457
465
466#ifdef __cplusplus
467}
468#endif
469#endif // _PRESSURE9_H_
470
471 // End public_function group
473
474// ------------------------------------------------------------------------- END
void pressure9_generic_write(pressure9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void pressure9_default_cfg(pressure9_t *ctx)
Click Default Configuration function.
void pressure9_cfg_setup(pressure9_cfg_t *cfg)
Config Object Initialization function.
int32_t pressure9_get_pressure_raw(pressure9_t *ctx)
Get Pressure Raw data.
void pressure9_configuration(pressure9_t *ctx, uint8_t reg_adr, uint8_t data_in)
Writing data to the configuration registers.
err_t pressure9_init(pressure9_t *ctx, pressure9_cfg_t *cfg)
Initialization function.
int32_t pressure9_get_coefficients(pressure9_t *ctx, uint8_t coeff)
Get calibration coefficients.
float pressure9_get_pressure_data(pressure9_t *ctx)
Get Pressure data in mBar.
void pressure9_generic_read(pressure9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void pressure9_update_calc_coef(pressure9_t *ctx)
Update all calibration coefficients.
float pressure9_get_temperature_data(pressure9_t *ctx)
Get Temperature data in C.
int32_t pressure9_get_temperature_raw(pressure9_t *ctx)
Get Temperature Raw data.
void(* pressure9_master_io_t)(struct pressure9_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition pressure9.h:243
struct pressure9_s pressure9_t
Click ctx object definition.
Click configuration structure definition.
Definition pressure9.h:318
uint32_t i2c_speed
Definition pressure9.h:328
spi_master_chip_select_polarity_t cs_polarity
Definition pressure9.h:333
pin_name_t sck
Definition pressure9.h:324
spi_master_mode_t spi_mode
Definition pressure9.h:332
pin_name_t mosi
Definition pressure9.h:323
uint32_t spi_speed
Definition pressure9.h:331
uint8_t sel
Definition pressure9.h:335
pin_name_t scl
Definition pressure9.h:320
pin_name_t miso
Definition pressure9.h:322
pin_name_t sda
Definition pressure9.h:321
pin_name_t cs
Definition pressure9.h:325
uint8_t i2c_address
Definition pressure9.h:329
Pressure calibration coefficient.
Definition pressure9.h:249
int32_t cal_20
Definition pressure9.h:254
int32_t cal_02
Definition pressure9.h:253
int32_t cal_12
Definition pressure9.h:257
int32_t cal_11
Definition pressure9.h:256
int32_t cal_01
Definition pressure9.h:252
int32_t cal_10
Definition pressure9.h:251
int32_t cal_21
Definition pressure9.h:258
int32_t cal_30
Definition pressure9.h:255
int32_t cal_00
Definition pressure9.h:250
Click ctx object definition.
Definition pressure9.h:287
digital_out_t cs
Definition pressure9.h:289
spi_master_t spi
Definition pressure9.h:293
pressure9_press_cal_coef_t press_coef
Definition pressure9.h:303
uint8_t press_buf[20]
Definition pressure9.h:309
pressure9_temp_cal_coef_t temp_coef
Definition pressure9.h:306
uint8_t master_sel
Definition pressure9.h:300
i2c_master_t i2c
Definition pressure9.h:292
uint32_t pressure_res
Definition pressure9.h:308
uint8_t temp_buf[3]
Definition pressure9.h:310
pressure9_master_io_t read_f
Definition pressure9.h:299
uint8_t slave_address
Definition pressure9.h:296
pin_name_t chip_select
Definition pressure9.h:297
pressure9_master_io_t write_f
Definition pressure9.h:298
Temperature calibration coefficient.
Definition pressure9.h:266
int32_t t_dvbe
Definition pressure9.h:268
int32_t t_gain
Definition pressure9.h:267
float kptat
Definition pressure9.h:277
float vbe_cal_t_ref
Definition pressure9.h:276
int32_t t_vbe
Definition pressure9.h:269
float vbe
Definition pressure9.h:270
float dvbe_cal
Definition pressure9.h:274
float bp
Definition pressure9.h:279
float adc_val
Definition pressure9.h:272
float ap
Definition pressure9.h:278
float vbe_cal
Definition pressure9.h:273
float t_cal
Definition pressure9.h:275
float dvbe
Definition pressure9.h:271