barometer13  2.1.0.0
barometer13.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 BAROMETER13_H
29 #define BAROMETER13_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 #include "drv_spi_master.h"
49 #include "spi_specifics.h"
50 
71 #define BAROMETER13_REG_CHIP_ID 0x01
72 #define BAROMETER13_REG_REV_ID 0x02
73 #define BAROMETER13_REG_CHIP_STATUS 0x11
74 #define BAROMETER13_REG_DRIVE_CONFIG 0x13
75 #define BAROMETER13_REG_INT_CONFIG 0x14
76 #define BAROMETER13_REG_INT_SOURCE 0x15
77 #define BAROMETER13_REG_FIFO_CONFIG 0x16
78 #define BAROMETER13_REG_FIFO_COUNT 0x17
79 #define BAROMETER13_REG_FIFO_SEL 0x18
80 #define BAROMETER13_REG_TEMP_DATA_XLSB 0x1D
81 #define BAROMETER13_REG_TEMP_DATA_LSB 0x1E
82 #define BAROMETER13_REG_TEMP_DATA_MSB 0x1F
83 #define BAROMETER13_REG_PRESS_DATA_XLSB 0x20
84 #define BAROMETER13_REG_PRESS_DATA_LSB 0x21
85 #define BAROMETER13_REG_PRESS_DATA_MSB 0x22
86 #define BAROMETER13_REG_INT_STATUS 0x27
87 #define BAROMETER13_REG_STATUS 0x28
88 #define BAROMETER13_REG_FIFO_DATA 0x29
89 #define BAROMETER13_REG_NVM_ADDR 0x2B
90 #define BAROMETER13_REG_NVM_DATA_LSB 0x2C
91 #define BAROMETER13_REG_NVM_DATA_MSB 0x2D
92 #define BAROMETER13_REG_DSP_CONFIG 0x30
93 #define BAROMETER13_REG_DSP_IIR 0x31
94 #define BAROMETER13_REG_OOR_THR_P_LSB 0x32
95 #define BAROMETER13_REG_OOR_THR_P_MSB 0x33
96 #define BAROMETER13_REG_OOR_RANGE 0x34
97 #define BAROMETER13_REG_OOR_CONFIG 0x35
98 #define BAROMETER13_REG_OSR_CONFIG 0x36
99 #define BAROMETER13_REG_ODR_CONFIG 0x37
100 #define BAROMETER13_REG_OSR_EFF 0x38
101 #define BAROMETER13_REG_CMD 0x7E
102  // barometer13_reg
104 
119 #define BAROMETER13_CHIP_ID 0x51
120 #define BAROMETER13_REV_ID 0x32
121 
126 #define BAROMETER13_INT_ENABLE 0x08
127 #define BAROMETER13_INT_DISABLE 0x00
128 #define BAROMETER13_INT_OPEN_DRAIN 0x04
129 #define BAROMETER13_INT_PUSH_PULL 0x00
130 #define BAROMETER13_INT_ACTIVE_HIGH 0x02
131 #define BAROMETER13_INT_ACTIVE_LOW 0x00
132 #define BAROMETER13_INT_LATCHED 0x01
133 #define BAROMETER13_INT_PULSED 0x00
134 
139 #define BAROMETER13_OOR_P_EN 0x08
140 #define BAROMETER13_FIFO_THS_EN 0x04
141 #define BAROMETER13_FIFO_FULL_EN 0x02
142 #define BAROMETER13_DRDY_DATA_EN 0x01
143 #define BAROMETER13_DRDY_DATA_DIS 0x00
144 
149 #define BAROMETER13_INT_STATUS_POR 0x10
150 #define BAROMETER13_INT_STATUS_OOR_P 0x08
151 #define BAROMETER13_INT_STATUS_FIFO_THS 0x04
152 #define BAROMETER13_INT_STATUS_FIFO_FULL 0x02
153 #define BAROMETER13_INT_STATUS_DRDY_DATA_REG 0x01
154 
159 #define BAROMETER13_OOR_SEL_IIR_P 0x80
160 #define BAROMETER13_FIFO_SEL_IIR_P 0x40
161 #define BAROMETER13_SHDW_SEL_IIR_P 0x20
162 #define BAROMETER13_FIFO_SEL_IIR_T 0x10
163 #define BAROMETER13_SHDW_SEL_IIR_T 0x08
164 #define BAROMETER13_IIR_FLUSH_FORCED_EN 0x04
165 #define BAROMETER13_DSP_CFG_RESERVED_BITS 0x03
166 
171 #define BAROMETER13_SET_IIR_P_BYPASS 0x00
172 #define BAROMETER13_SET_IIR_P_FLT_COEF_1 0x08
173 #define BAROMETER13_SET_IIR_P_FLT_COEF_3 0x10
174 #define BAROMETER13_SET_IIR_P_FLT_COEF_7 0x18
175 #define BAROMETER13_SET_IIR_P_FLT_COEF_15 0x20
176 #define BAROMETER13_SET_IIR_P_FLT_COEF_31 0x28
177 #define BAROMETER13_SET_IIR_P_FLT_COEF_63 0x30
178 #define BAROMETER13_SET_IIR_P_FLT_COEF_127 0x38
179 #define BAROMETER13_SET_IIR_T_BYPASS 0x00
180 #define BAROMETER13_SET_IIR_T_FLT_COEF_1 0x01
181 #define BAROMETER13_SET_IIR_T_FLT_COEF_3 0x02
182 #define BAROMETER13_SET_IIR_T_FLT_COEF_7 0x03
183 #define BAROMETER13_SET_IIR_T_FLT_COEF_15 0x04
184 #define BAROMETER13_SET_IIR_T_FLT_COEF_31 0x05
185 #define BAROMETER13_SET_IIR_T_FLT_COEF_63 0x06
186 #define BAROMETER13_SET_IIR_T_FLT_COEF_127 0x07
187 
192 #define BAROMETER13_PRESS_EN 0x40
193 #define BAROMETER13_OSR_P_1X 0x00
194 #define BAROMETER13_OSR_P_2X 0x08
195 #define BAROMETER13_OSR_P_4X 0x10
196 #define BAROMETER13_OSR_P_8X 0x18
197 #define BAROMETER13_OSR_P_16X 0x20
198 #define BAROMETER13_OSR_P_32X 0x28
199 #define BAROMETER13_OSR_P_64X 0x30
200 #define BAROMETER13_OSR_P_128X 0x38
201 #define BAROMETER13_OSR_T_1X 0x00
202 #define BAROMETER13_OSR_T_2X 0x01
203 #define BAROMETER13_OSR_T_4X 0x02
204 #define BAROMETER13_OSR_T_8X 0x03
205 #define BAROMETER13_OSR_T_16X 0x04
206 #define BAROMETER13_OSR_T_32X 0x05
207 #define BAROMETER13_OSR_T_64X 0x06
208 #define BAROMETER13_OSR_T_128X 0x07
209 
214 #define BAROMETER13_DEEP_DIS 0x80
215 #define BAROMETER13_ODR_240_HZ 0x00
216 #define BAROMETER13_ODR_218_537_HZ 0x04
217 #define BAROMETER13_ODR_199_111_HZ 0x08
218 #define BAROMETER13_ODR_179_2_HZ 0x0C
219 #define BAROMETER13_ODR_160_HZ 0x10
220 #define BAROMETER13_ODR_149_333_HZ 0x14
221 #define BAROMETER13_ODR_140_HZ 0x18
222 #define BAROMETER13_ODR_129_855_HZ 0x1C
223 #define BAROMETER13_ODR_120_HZ 0x20
224 #define BAROMETER13_ODR_110_164_HZ 0x24
225 #define BAROMETER13_ODR_100_299_HZ 0x28
226 #define BAROMETER13_ODR_89p6_HZ 0x2C
227 #define BAROMETER13_ODR_80_HZ 0x30
228 #define BAROMETER13_ODR_70_HZ 0x34
229 #define BAROMETER13_ODR_60_HZ 0x38
230 #define BAROMETER13_ODR_50_056_HZ 0x3C
231 #define BAROMETER13_ODR_45_025_HZ 0x40
232 #define BAROMETER13_ODR_40_HZ 0x44
233 #define BAROMETER13_ODR_35_HZ 0x48
234 #define BAROMETER13_ODR_30_HZ 0x4C
235 #define BAROMETER13_ODR_25_005_HZ 0x50
236 #define BAROMETER13_ODR_20_HZ 0x54
237 #define BAROMETER13_ODR_15_HZ 0x58
238 #define BAROMETER13_ODR_10_HZ 0x5C
239 #define BAROMETER13_ODR_5_HZ 0x60
240 #define BAROMETER13_ODR_4_HZ 0x64
241 #define BAROMETER13_ODR_3_HZ 0x68
242 #define BAROMETER13_ODR_2_HZ 0x6C
243 #define BAROMETER13_ODR_1_HZ 0x70
244 #define BAROMETER13_ODR_0_5_HZ 0x74
245 #define BAROMETER13_ODR_0_25_HZ 0x78
246 #define BAROMETER13_ODR_0_125_HZ 0x7C
247 #define BAROMETER13_PWR_MODE_STANDBY 0x00
248 #define BAROMETER13_PWR_MODE_NORMAL 0x01
249 #define BAROMETER13_PWR_MODE_FORCE 0x02
250 #define BAROMETER13_PWR_MODE_NON_STOP 0x03
251 
256 #define BAROMETER13_INT_STATE_HIGH 0x01
257 #define BAROMETER13_INT_STATE_LOW 0x00
258 
263 #define BAROMETER13_PRESS_DATA_RES 64.0f
264 #define BAROMETER13_TEMP_DATA_RES 65536.0f
265 #define BAROMETER13_PA_TO_MBAR 100.0f
266 
272 #define BAROMETER13_DEVICE_ADDRESS_1 0x46
273 #define BAROMETER13_DEVICE_ADDRESS_0 0x47
274 
283 #define BAROMETER13_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
284 #define BAROMETER13_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
285  // barometer13_set
287 
302 #define BAROMETER13_MAP_MIKROBUS( cfg, mikrobus ) \
303  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
304  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
305  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
306  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
307  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
308  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
309  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
310  // barometer13_map // barometer13
313 
318 typedef enum
319 {
324 
329 typedef err_t ( *barometer13_master_io_t )( struct barometer13_s*, uint8_t, uint8_t*, uint8_t );
335 typedef struct barometer13_s
336 {
337  digital_in_t int_pin;
339  i2c_master_t i2c;
340  spi_master_t spi;
342  uint8_t slave_address;
343  pin_name_t chip_select;
350 
355 typedef struct
356 {
357  pin_name_t scl;
358  pin_name_t sda;
359  pin_name_t miso;
360  pin_name_t mosi;
361  pin_name_t sck;
362  pin_name_t cs;
363  pin_name_t int_pin;
365  uint32_t i2c_speed;
366  uint8_t i2c_address;
368  uint32_t spi_speed;
369  spi_master_mode_t spi_mode;
370  spi_master_chip_select_polarity_t cs_polarity;
375 
380 typedef enum
381 {
383  BAROMETER13_ERROR = -1
384 
386 
403 
419 
434 
448 
463 err_t barometer13_generic_write ( barometer13_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
464 
479 err_t barometer13_generic_read ( barometer13_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
480 
495 err_t barometer13_reg_write ( barometer13_t *ctx, uint8_t reg, uint8_t data_in );
496 
511 err_t barometer13_reg_read ( barometer13_t *ctx, uint8_t reg, uint8_t *data_out );
512 
527 err_t barometer13_get_device_id ( barometer13_t *ctx, uint8_t *chip_id, uint8_t *rev_id );
528 
545 err_t barometer13_set_int_cfg ( barometer13_t *ctx, uint8_t int_en, uint8_t int_od,
546  uint8_t int_pol, uint8_t int_mode );
547 
561 err_t barometer13_set_drdy_data ( barometer13_t *ctx, uint8_t en_drdy_data );
562 
576 err_t barometer13_get_int_status ( barometer13_t *ctx, uint8_t *int_status );
577 
593 err_t barometer13_set_shdw_sel ( barometer13_t *ctx, uint8_t shdw_sel_iir_p, uint8_t shdw_sel_iir_t );
594 
610 err_t barometer13_set_lpf_band_flt ( barometer13_t *ctx, uint8_t set_iir_p, uint8_t set_iir_t );
611 
626 err_t barometer13_set_osr ( barometer13_t *ctx, uint8_t osr_p, uint8_t osr_t );
627 
641 
655 err_t barometer13_set_odr ( barometer13_t *ctx, uint8_t odr );
656 
670 err_t barometer13_set_pwr_mode ( barometer13_t *ctx, uint8_t pwr_mode );
671 
686 err_t barometer13_get_raw_data ( barometer13_t *ctx, int32_t *press_data, int32_t *temp_data );
687 
702 err_t barometer13_get_measurement ( barometer13_t *ctx, float *pressure, float *temperature );
703 
717 err_t barometer13_get_pressure ( barometer13_t *ctx, float *pressure );
718 
731 
732 #ifdef __cplusplus
733 }
734 #endif
735 #endif // BAROMETER13_H
736  // barometer13
738 
739 // ------------------------------------------------------------------------ END
barometer13_t
struct barometer13_s barometer13_t
Barometer 13 Click context object.
barometer13_get_int_status
err_t barometer13_get_int_status(barometer13_t *ctx, uint8_t *int_status)
Barometer 13 get interrupt status function.
barometer13_get_measurement
err_t barometer13_get_measurement(barometer13_t *ctx, float *pressure, float *temperature)
Barometer 13 get the measurement data function.
barometer13_s::i2c
i2c_master_t i2c
Definition: barometer13.h:339
barometer13_cfg_t::drv_sel
barometer13_drv_t drv_sel
Definition: barometer13.h:372
barometer13_cfg_t::miso
pin_name_t miso
Definition: barometer13.h:359
barometer13_set_shdw_sel
err_t barometer13_set_shdw_sel(barometer13_t *ctx, uint8_t shdw_sel_iir_p, uint8_t shdw_sel_iir_t)
Barometer 13 set shadow IIR selection function.
barometer13_cfg_t::mosi
pin_name_t mosi
Definition: barometer13.h:360
barometer13_cfg_setup
void barometer13_cfg_setup(barometer13_cfg_t *cfg)
Barometer 13 configuration object setup function.
barometer13_get_interrupt
uint8_t barometer13_get_interrupt(barometer13_t *ctx)
Barometer 13 get the interrupt function.
barometer13_cfg_t::sda
pin_name_t sda
Definition: barometer13.h:358
barometer13_reg_write
err_t barometer13_reg_write(barometer13_t *ctx, uint8_t reg, uint8_t data_in)
Barometer 13 register data writing function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
barometer13_default_cfg
err_t barometer13_default_cfg(barometer13_t *ctx)
Barometer 13 default configuration function.
barometer13_set_lpf_band_flt
err_t barometer13_set_lpf_band_flt(barometer13_t *ctx, uint8_t set_iir_p, uint8_t set_iir_t)
Barometer 13 set LPF band filter function.
barometer13_cfg_t::spi_speed
uint32_t spi_speed
Definition: barometer13.h:368
barometer13_s::chip_select
pin_name_t chip_select
Definition: barometer13.h:343
barometer13_s::int_pin
digital_in_t int_pin
Definition: barometer13.h:337
BAROMETER13_DRV_SEL_SPI
@ BAROMETER13_DRV_SEL_SPI
Definition: barometer13.h:320
barometer13_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: barometer13.h:370
barometer13_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: barometer13.h:369
barometer13_generic_write
err_t barometer13_generic_write(barometer13_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Barometer 13 data writing function.
barometer13_set_odr
err_t barometer13_set_odr(barometer13_t *ctx, uint8_t odr)
Barometer 13 set the output data rate function.
barometer13_s::spi
spi_master_t spi
Definition: barometer13.h:340
barometer13_cfg_t::i2c_address
uint8_t i2c_address
Definition: barometer13.h:366
barometer13_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: barometer13.h:365
barometer13_press_enable
err_t barometer13_press_enable(barometer13_t *ctx)
Barometer 13 enable pressure data function.
barometer13_cfg_t
Barometer 13 Click configuration object.
Definition: barometer13.h:356
barometer13_s::drv_sel
barometer13_drv_t drv_sel
Definition: barometer13.h:344
barometer13_get_raw_data
err_t barometer13_get_raw_data(barometer13_t *ctx, int32_t *press_data, int32_t *temp_data)
Barometer 13 get raw data function.
barometer13_drv_t
barometer13_drv_t
Barometer 13 Click driver selector.
Definition: barometer13.h:319
barometer13_cfg_t::scl
pin_name_t scl
Definition: barometer13.h:357
BAROMETER13_ERROR
@ BAROMETER13_ERROR
Definition: barometer13.h:383
barometer13_set_pwr_mode
err_t barometer13_set_pwr_mode(barometer13_t *ctx, uint8_t pwr_mode)
Barometer 13 set power mode configuration function.
barometer13_init
err_t barometer13_init(barometer13_t *ctx, barometer13_cfg_t *cfg)
Barometer 13 initialization function.
barometer13_set_osr
err_t barometer13_set_osr(barometer13_t *ctx, uint8_t osr_p, uint8_t osr_t)
Barometer 13 set over-sampling rate function.
BAROMETER13_DRV_SEL_I2C
@ BAROMETER13_DRV_SEL_I2C
Definition: barometer13.h:321
barometer13_drv_interface_sel
void barometer13_drv_interface_sel(barometer13_cfg_t *cfg, barometer13_drv_t drv_sel)
Barometer 13 driver interface setup function.
barometer13_set_drdy_data
err_t barometer13_set_drdy_data(barometer13_t *ctx, uint8_t en_drdy_data)
Barometer 13 set data ready function.
barometer13_generic_read
err_t barometer13_generic_read(barometer13_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Barometer 13 data reading function.
BAROMETER13_OK
@ BAROMETER13_OK
Definition: barometer13.h:382
barometer13_set_int_cfg
err_t barometer13_set_int_cfg(barometer13_t *ctx, uint8_t int_en, uint8_t int_od, uint8_t int_pol, uint8_t int_mode)
Barometer 13 set the interrupt config function.
barometer13_s
Barometer 13 Click context object.
Definition: barometer13.h:336
barometer13_s::slave_address
uint8_t slave_address
Definition: barometer13.h:342
barometer13_master_io_t
err_t(* barometer13_master_io_t)(struct barometer13_s *, uint8_t, uint8_t *, uint8_t)
Barometer 13 Click driver interface.
Definition: barometer13.h:329
barometer13_cfg_t::cs
pin_name_t cs
Definition: barometer13.h:362
barometer13_cfg_t::sck
pin_name_t sck
Definition: barometer13.h:361
barometer13_s::read_f
barometer13_master_io_t read_f
Definition: barometer13.h:347
barometer13_s::write_f
barometer13_master_io_t write_f
Definition: barometer13.h:346
barometer13_get_device_id
err_t barometer13_get_device_id(barometer13_t *ctx, uint8_t *chip_id, uint8_t *rev_id)
Barometer 13 get device ID function.
barometer13_cfg_t::int_pin
pin_name_t int_pin
Definition: barometer13.h:363
barometer13_get_pressure
err_t barometer13_get_pressure(barometer13_t *ctx, float *pressure)
Barometer 13 get the pressure data function.
barometer13_reg_read
err_t barometer13_reg_read(barometer13_t *ctx, uint8_t reg, uint8_t *data_out)
Barometer 13 register data reading function.
barometer13_return_value_t
barometer13_return_value_t
Barometer 13 Click return value data.
Definition: barometer13.h:381