pressure18 2.1.0.0
pressure18.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 PRESSURE18_H
29#define PRESSURE18_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#include "drv_spi_master.h"
53#include "spi_specifics.h"
54
75#define PRESSURE18_REG_CHIP_ID 0x00
76#define PRESSURE18_REG_ERR 0x02
77#define PRESSURE18_REG_STATUS 0x03
78#define PRESSURE18_REG_DATA_0 0x04
79#define PRESSURE18_REG_DATA_1 0x05
80#define PRESSURE18_REG_DATA_2 0x06
81#define PRESSURE18_REG_DATA_3 0x07
82#define PRESSURE18_REG_DATA_4 0x08
83#define PRESSURE18_REG_DATA_5 0x09
84#define PRESSURE18_REG_SENSOR_TIME_0 0x0C
85#define PRESSURE18_REG_SENSOR_TIME_1 0x0D
86#define PRESSURE18_REG_SENSOR_TIME_2 0x0E
87#define PRESSURE18_REG_SENSOR_TIME_3 0x0F
88#define PRESSURE18_REG_EVENT 0x10
89#define PRESSURE18_REG_INT_STATUS 0x11
90#define PRESSURE18_REG_FIFO_LENGTH_0 0x12
91#define PRESSURE18_REG_FIFO_LENGTH_1 0x13
92#define PRESSURE18_REG_FIFO_DATA 0x14
93#define PRESSURE18_REG_FIFO_WTM_0 0x15
94#define PRESSURE18_REG_FIFO_WTM_1 0x16
95#define PRESSURE18_REG_FIFO_CONFIG_1 0x17
96#define PRESSURE18_REG_FIFO_CONFIG_2 0x18
97#define PRESSURE18_REG_INT_CTRL 0x19
98#define PRESSURE18_REG_IF_CONF 0x1A
99#define PRESSURE18_REG_PWR_CTRL 0x1B
100#define PRESSURE18_REG_OSR 0x1C
101#define PRESSURE18_REG_ODR 0x1D
102#define PRESSURE18_REG_CONFIG 0x1F
103#define PRESSURE18_REG_CALIB_DATA 0x31
104#define PRESSURE18_REG_CMD 0x7E
105
106 // pressure18_reg
107
122#define PRESSURE18_CHIP_ID 0x50
123
128#define PRESSURE18_ERR_FATAL 0x01
129#define PRESSURE18_ERR_CMD 0x02
130#define PRESSURE18_ERR_CONF 0x04
131
136#define PRESSURE18_STATUS_CMD_RDY 0x10
137#define PRESSURE18_STATUS_DRDY_PRESS 0x20
138#define PRESSURE18_STATUS_DRDY_TEMP 0x40
139
144#define PRESSURE18_INT_CTRL_OD_PUSH_PULL 0x00
145#define PRESSURE18_INT_CTRL_OD_OPEN_DRAIN 0x01
146#define PRESSURE18_INT_CTRL_LEVEL_ACTIVE_LOW 0x00
147#define PRESSURE18_INT_CTRL_LEVEL_ACTIVE_HIGH 0x02
148#define PRESSURE18_INT_CTRL_LATCH_DISABLED 0x00
149#define PRESSURE18_INT_CTRL_LATCH_ENABLED 0x04
150#define PRESSURE18_INT_CTRL_FWTM_DISABLED 0x00
151#define PRESSURE18_INT_CTRL_FWTM_ENABLED 0x08
152#define PRESSURE18_INT_CTRL_FFULL_DISABLED 0x00
153#define PRESSURE18_INT_CTRL_FFULL_ENABLED 0x10
154#define PRESSURE18_INT_CTRL_DRDY_DISABLED 0x00
155#define PRESSURE18_INT_CTRL_DRDY_ENABLED 0x40
156
161#define PRESSURE18_PWR_CTRL_PRESS_EN 0x01
162#define PRESSURE18_PWR_CTRL_TEMP_EN 0x02
163#define PRESSURE18_PWR_CTRL_MODE_SLEEP 0x00
164#define PRESSURE18_PWR_CTRL_MODE_FORCED 0x10
165#define PRESSURE18_PWR_CTRL_MODE_NORMAL 0x30
166
171#define PRESSURE18_OSR_P_X1 0x00
172#define PRESSURE18_OSR_P_X2 0x01
173#define PRESSURE18_OSR_P_X4 0x02
174#define PRESSURE18_OSR_P_X8 0x03
175#define PRESSURE18_OSR_P_X16 0x04
176#define PRESSURE18_OSR_P_X32 0x05
177#define PRESSURE18_OSR_T_X1 0x00
178#define PRESSURE18_OSR_T_X2 0x08
179#define PRESSURE18_OSR_T_X4 0x10
180#define PRESSURE18_OSR_T_X8 0x18
181#define PRESSURE18_OSR_T_X16 0x20
182#define PRESSURE18_OSR_T_X32 0x28
183
188#define PRESSURE18_ODR_5_MS 0x00
189#define PRESSURE18_ODR_10_MS 0x01
190#define PRESSURE18_ODR_20_MS 0x02
191#define PRESSURE18_ODR_40_MS 0x03
192#define PRESSURE18_ODR_80_MS 0x04
193#define PRESSURE18_ODR_160_MS 0x05
194#define PRESSURE18_ODR_320_MS 0x06
195#define PRESSURE18_ODR_640_MS 0x07
196#define PRESSURE18_ODR_1p280_S 0x08
197#define PRESSURE18_ODR_2p560_S 0x09
198#define PRESSURE18_ODR_5p120_S 0x0A
199#define PRESSURE18_ODR_10p24_S 0x0B
200#define PRESSURE18_ODR_20p48_S 0x0C
201#define PRESSURE18_ODR_40p96_S 0x0D
202#define PRESSURE18_ODR_81p92_S 0x0E
203#define PRESSURE18_ODR_163p84_S 0x0F
204#define PRESSURE18_ODR_327p68_S 0x10
205#define PRESSURE18_ODR_655p36_S 0x11
206
211#define PRESSURE18_CMD_NOP 0x00
212#define PRESSURE18_CMD_EXTMODE_EN_MIDDLE 0x34
213#define PRESSURE18_CMD_FIFO_FLUSH 0xB0
214#define PRESSURE18_CMD_SOFT_RESET 0xB6
215
220#define PRESSURE18_PA_TO_MBAR 0.01
221
227#define PRESSURE18_DEVICE_ADDRESS_0 0x76
228#define PRESSURE18_DEVICE_ADDRESS_1 0x77
229
238#define PRESSURE18_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
239#define PRESSURE18_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
240
241 // pressure18_set
242
257#define PRESSURE18_MAP_MIKROBUS( cfg, mikrobus ) \
258 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
259 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
260 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
261 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
262 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
263 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
264 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
265
266 // pressure18_map
267 // pressure18
268
279
284typedef err_t ( *pressure18_master_io_t )( struct pressure18_s*, uint8_t, uint8_t*, uint8_t );
290typedef struct
291{
292 float par_t1;
293 float par_t2;
294 float par_t3;
295 float par_p1;
296 float par_p2;
297 float par_p3;
298 float par_p4;
299 float par_p5;
300 float par_p6;
301 float par_p7;
302 float par_p8;
303 float par_p9;
304 float par_p10;
305 float par_p11;
306 float t_lin;
307
309
331
336typedef struct
337{
338 pin_name_t scl;
339 pin_name_t sda;
340 pin_name_t miso;
341 pin_name_t mosi;
342 pin_name_t sck;
343 pin_name_t cs;
344 pin_name_t int_pin;
346 uint32_t i2c_speed;
347 uint8_t i2c_address;
349 uint32_t spi_speed;
350 spi_master_mode_t spi_mode;
351 spi_master_chip_select_polarity_t cs_polarity;
356
367
384
400
415
429
444err_t pressure18_generic_write ( pressure18_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
445
460err_t pressure18_generic_read ( pressure18_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
461
474err_t pressure18_write_register ( pressure18_t *ctx, uint8_t reg, uint8_t data_in );
475
488err_t pressure18_read_register ( pressure18_t *ctx, uint8_t reg, uint8_t *data_out );
489
501
511
523
536err_t pressure18_read_data ( pressure18_t *ctx, float *pressure, float *temperature );
537
538#ifdef __cplusplus
539}
540#endif
541#endif // PRESSURE18_H
542
543 // pressure18
544
545// ------------------------------------------------------------------------ END
err_t pressure18_generic_read(pressure18_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Pressure 18 data reading function.
uint8_t pressure18_get_int_pin(pressure18_t *ctx)
Pressure 18 get int pin function.
err_t pressure18_write_register(pressure18_t *ctx, uint8_t reg, uint8_t data_in)
Pressure 18 write register function.
err_t pressure18_check_communication(pressure18_t *ctx)
Pressure 18 check communication function.
err_t pressure18_read_register(pressure18_t *ctx, uint8_t reg, uint8_t *data_out)
Pressure 18 read register function.
err_t pressure18_generic_write(pressure18_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Pressure 18 data writing function.
err_t pressure18_read_data(pressure18_t *ctx, float *pressure, float *temperature)
Pressure 18 read data function.
err_t pressure18_soft_reset(pressure18_t *ctx)
Pressure 18 soft reset function.
void pressure18_cfg_setup(pressure18_cfg_t *cfg)
Pressure 18 configuration object setup function.
void pressure18_drv_interface_selection(pressure18_cfg_t *cfg, pressure18_drv_t drv_sel)
Pressure 18 driver interface setup function.
err_t pressure18_init(pressure18_t *ctx, pressure18_cfg_t *cfg)
Pressure 18 initialization function.
err_t pressure18_default_cfg(pressure18_t *ctx)
Pressure 18 default configuration function.
err_t(* pressure18_master_io_t)(struct pressure18_s *, uint8_t, uint8_t *, uint8_t)
Pressure 18 Click driver interface.
Definition pressure18.h:284
struct pressure18_s pressure18_t
Pressure 18 Click context object.
pressure18_drv_t
Pressure 18 Click driver selector.
Definition pressure18.h:274
@ PRESSURE18_DRV_SEL_SPI
Definition pressure18.h:275
@ PRESSURE18_DRV_SEL_I2C
Definition pressure18.h:276
pressure18_return_value_t
Pressure 18 Click return value data.
Definition pressure18.h:362
@ PRESSURE18_OK
Definition pressure18.h:363
@ PRESSURE18_ERROR
Definition pressure18.h:364
This file contains SPI specific macros, functions, etc.
Pressure 18 Click calibration coefficients object.
Definition pressure18.h:291
float par_t2
Definition pressure18.h:293
float t_lin
Definition pressure18.h:306
float par_p7
Definition pressure18.h:301
float par_p8
Definition pressure18.h:302
float par_p2
Definition pressure18.h:296
float par_t1
Definition pressure18.h:292
float par_p3
Definition pressure18.h:297
float par_p9
Definition pressure18.h:303
float par_p5
Definition pressure18.h:299
float par_p4
Definition pressure18.h:298
float par_p10
Definition pressure18.h:304
float par_p6
Definition pressure18.h:300
float par_p11
Definition pressure18.h:305
float par_p1
Definition pressure18.h:295
float par_t3
Definition pressure18.h:294
Pressure 18 Click configuration object.
Definition pressure18.h:337
pressure18_drv_t drv_sel
Definition pressure18.h:353
uint32_t i2c_speed
Definition pressure18.h:346
spi_master_chip_select_polarity_t cs_polarity
Definition pressure18.h:351
pin_name_t sck
Definition pressure18.h:342
spi_master_mode_t spi_mode
Definition pressure18.h:350
pin_name_t mosi
Definition pressure18.h:341
uint32_t spi_speed
Definition pressure18.h:349
pin_name_t scl
Definition pressure18.h:338
pin_name_t int_pin
Definition pressure18.h:344
pin_name_t miso
Definition pressure18.h:340
pin_name_t sda
Definition pressure18.h:339
pin_name_t cs
Definition pressure18.h:343
uint8_t i2c_address
Definition pressure18.h:347
Pressure 18 Click context object.
Definition pressure18.h:315
spi_master_t spi
Definition pressure18.h:319
pressure18_calib_coef_t calib_coef
Definition pressure18.h:328
pressure18_master_io_t write_f
Definition pressure18.h:325
pressure18_drv_t drv_sel
Definition pressure18.h:323
pressure18_master_io_t read_f
Definition pressure18.h:326
digital_in_t int_pin
Definition pressure18.h:316
i2c_master_t i2c
Definition pressure18.h:318
uint8_t slave_address
Definition pressure18.h:321
pin_name_t chip_select
Definition pressure18.h:322