pressure23 2.1.0.0
pressure23.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 PRESSURE23_H
29#define PRESSURE23_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 PRESSURE23_REG_SERIAL_NUMBER_MSB 0x02
76#define PRESSURE23_REG_SERIAL_NUMBER_LSB 0x03
77#define PRESSURE23_REG_COEF_C1 0x04
78#define PRESSURE23_REG_COEF_C2 0x05
79#define PRESSURE23_REG_COEF_C3 0x06
80#define PRESSURE23_REG_COEF_C4 0x07
81#define PRESSURE23_REG_COEF_C5 0x08
82#define PRESSURE23_REG_COEF_C6 0x09
83#define PRESSURE23_REG_COEF_C7 0x0A
84#define PRESSURE23_REG_COEF_C8 0x0B
85#define PRESSURE23_REG_COEF_C9 0x0C
86#define PRESSURE23_REG_COEF_C10 0x0D
87#define PRESSURE23_REG_PROM_ID_CRC 0x0F
88
89 // pressure23_reg
90
105#define PRESSURE23_CMD_RESET 0x10
106#define PRESSURE23_CMD_WRITE_CONFIG_PRESS 0x20
107#define PRESSURE23_CMD_WRITE_CONFIG_TEMP 0x22
108#define PRESSURE23_CMD_READ_CONFIG_PRESS 0x28
109#define PRESSURE23_CMD_READ_CONFIG_TEMP 0x2A
110#define PRESSURE23_CMD_READ_MEMORY 0xE0
111#define PRESSURE23_CMD_START_CONVERSION 0x40
112#define PRESSURE23_CMD_START_CONVERSION_PRESS 0x44
113#define PRESSURE23_CMD_START_CONVERSION_TEMP 0x48
114#define PRESSURE23_CMD_READ_ADC_REG 0x50
115#define PRESSURE23_CMD_READ_ADC_REG_PRESS 0x54
116#define PRESSURE23_CMD_READ_ADC_REG_TEMP 0x58
117#define PRESSURE23_CMD_WRITE_OPERATION_REG 0x14
118#define PRESSURE23_CMD_READ_OPERATION_REG 0x16
119#define PRESSURE23_CMD_WRITE_INTERRUPT_MASK 0x18
120#define PRESSURE23_CMD_READ_INTERRUPT_MASK 0x1A
121#define PRESSURE23_CMD_WRITE_INTERRUPT_REG 0x1C
122#define PRESSURE23_CMD_READ_INTERRUPT_REG 0x1E
123#define PRESSURE23_CMD_WRITE_LIMIT_REG_TEMP_L 0x30
124#define PRESSURE23_CMD_WRITE_LIMIT_REG_TEMP_H 0x32
125#define PRESSURE23_CMD_WRITE_LIMIT_REG_PRESS_L 0x34
126#define PRESSURE23_CMD_WRITE_LIMIT_REG_PRESS_H 0x36
127#define PRESSURE23_CMD_READ_LIMIT_REG_TEMP_L 0x38
128#define PRESSURE23_CMD_READ_LIMIT_REG_TEMP_H 0x3A
129#define PRESSURE23_CMD_READ_LIMIT_REG_PRESS_L 0x3C
130#define PRESSURE23_CMD_READ_LIMIT_REG_PRESS_H 0x3E
131
132 // pressure23_cmd
133
148#define PRESSURE23_SNSR_CFG_SEL_PRESS 0x00
149#define PRESSURE23_SNSR_CFG_SEL_TEMP 0x01
150#define PRESSURE23_SNSR_CFG_SEL_BIT_MASK 0x01
151#define PRESSURE23_SNSR_CFG_RATIO_OFF 0x00
152#define PRESSURE23_SNSR_CFG_RATIO_1 0x01
153#define PRESSURE23_SNSR_CFG_RATIO_2 0x02
154#define PRESSURE23_SNSR_CFG_RATIO_4 0x03
155#define PRESSURE23_SNSR_CFG_RATIO_8 0x04
156#define PRESSURE23_SNSR_CFG_RATIO_16 0x05
157#define PRESSURE23_SNSR_CFG_RATIO_32 0x06
158#define PRESSURE23_SNSR_CFG_RATIO_BIT_MASK 0x07
159#define PRESSURE23_SNSR_CFG_FILTER_OFF 0x00
160#define PRESSURE23_SNSR_CFG_FILTER_2 0x01
161#define PRESSURE23_SNSR_CFG_FILTER_4 0x02
162#define PRESSURE23_SNSR_CFG_FILTER_8 0x03
163#define PRESSURE23_SNSR_CFG_FILTER_16 0x04
164#define PRESSURE23_SNSR_CFG_FILTER_32 0x05
165#define PRESSURE23_SNSR_CFG_FILTER_BIT_MASK 0x07
166#define PRESSURE23_SNSR_CFG_RES_24_BIT 0x00
167#define PRESSURE23_SNSR_CFG_RES_16_BIT 0x01
168#define PRESSURE23_SNSR_CFG_RES_8_BIT 0x02
169#define PRESSURE23_SNSR_CFG_RES_BIT_MASK 0x03
170#define PRESSURE23_SNSR_CFG_OSR_0 0x00
171#define PRESSURE23_SNSR_CFG_OSR_1 0x01
172#define PRESSURE23_SNSR_CFG_OSR_2 0x02
173#define PRESSURE23_SNSR_CFG_OSR_3 0x03
174#define PRESSURE23_SNSR_CFG_OSR_4 0x04
175#define PRESSURE23_SNSR_CFG_OSR_5 0x05
176#define PRESSURE23_SNSR_CFG_OSR_6 0x06
177#define PRESSURE23_SNSR_CFG_OSR_BIT_MASK 0x07
178
183#define PRESSURE23_CNV_ADC_SEL_PRESS 0x00
184#define PRESSURE23_CNV_ADC_SEL_TEMP 0x01
185#define PRESSURE23_CNV_ADC_BIT_MASK 0x01
186#define PRESSURE23_CNV_ADC_REG_BIT_MASK 0x04
187
192#define PRESSURE23_OP_REG_FIFO_INT_TH_OFF 0x00
193#define PRESSURE23_OP_REG_FIFO_INT_TH_BIT_MASK 0x1F
194#define PRESSURE23_OP_REG_FIFO_MODE_OFF 0x00
195#define PRESSURE23_OP_REG_FIFO_MODE_BIT_MASK 0x03
196#define PRESSURE23_OP_REG_DELAY_OFF 0x00
197#define PRESSURE23_OP_REG_DELAY_5_MS 0x01
198#define PRESSURE23_OP_REG_DELAY_10_MS 0x02
199#define PRESSURE23_OP_REG_DELAY_20_MS 0x03
200#define PRESSURE23_OP_REG_DELAY_50_MS 0x04
201#define PRESSURE23_OP_REG_DELAY_100_MS 0x05
202#define PRESSURE23_OP_REG_DELAY_200_MS 0x06
203#define PRESSURE23_OP_REG_DELAY_500_MS 0x07
204#define PRESSURE23_OP_REG_DELAY_1_SEC 0x08
205#define PRESSURE23_OP_REG_DELAY_2_SEC 0x09
206#define PRESSURE23_OP_REG_DELAY_5_SEC 0x0A
207#define PRESSURE23_OP_REG_DELAY_10_SEC 0x0B
208#define PRESSURE23_OP_REG_DELAY_20_SEC 0x0C
209#define PRESSURE23_OP_REG_DELAY_60_SEC 0x0D
210#define PRESSURE23_OP_REG_DELAY_BIT_MASK 0x0F
211
216#define PRESSURE23_LIM_REG_SEL_TEMP 0x00
217#define PRESSURE23_LIM_REG_SEL_PRESS 0x01
218#define PRESSURE23_LIM_REG_SEL_BIT_MASK 0x01
219#define PRESSURE23_LIM_REG_LIM_LOW 0x00
220#define PRESSURE23_LIM_REG_LIM_HIGH 0x01
221#define PRESSURE23_LIM_REG_LIM_BIT_MASK 0x01
222
227#define PRESSURE23_COEF_TEMP_D2_DIV 536870912.0f
228#define PRESSURE23_COEF_TEMP_D1_DIV 34359738368.0f
229#define PRESSURE23_COEF_TEMP_C2_DIV 64.0f
230#define PRESSURE23_COEF_OFF_SENS_DIV 512.0f
231#define PRESSURE23_COEF_PRESS_DIV 4194304.0f
232
238#define PRESSURE23_DEVICE_ADDRESS_GND 0x77
239#define PRESSURE23_DEVICE_ADDRESS_VCC 0x76
240
249#define PRESSURE23_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
250#define PRESSURE23_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
251
252 // pressure23_set
253
268#define PRESSURE23_MAP_MIKROBUS( cfg, mikrobus ) \
269 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
270 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
271 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
272 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
273 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
274 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
275 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
276
277 // pressure23_map
278 // pressure23
279
290
295typedef err_t ( *pressure23_master_io_t )( struct pressure23_s*, uint8_t, uint8_t*, uint8_t );
301typedef struct pressure23_s
302{
303 digital_in_t int_pin;
305 i2c_master_t i2c;
306 spi_master_t spi;
309 pin_name_t chip_select;
312 // Calibration data (factory calibrated) from PROM
315 uint8_t prom_crc;
317 uint16_t prom_c1;
318 uint16_t prom_c2;
319 uint16_t prom_c3;
320 uint16_t prom_c4;
321 uint16_t prom_c5;
322 uint16_t prom_c6;
323 uint16_t prom_c7;
324 uint16_t prom_c8;
325 uint16_t prom_c9;
326 uint16_t prom_c10;
328 uint8_t osr_press;
329 uint8_t osr_temp;
335
340typedef struct
341{
342 pin_name_t scl;
343 pin_name_t sda;
344 pin_name_t miso;
345 pin_name_t mosi;
346 pin_name_t sck;
347 pin_name_t cs;
348 pin_name_t int_pin;
350 uint32_t i2c_speed;
351 uint8_t i2c_address;
353 uint32_t spi_speed;
354 spi_master_mode_t spi_mode;
355 spi_master_chip_select_polarity_t cs_polarity;
360
365typedef struct
366{
367 uint8_t sel;
368 uint8_t ratio;
369 uint8_t filter;
370 uint8_t resolution;
371 uint8_t osr;
374
385
402
418
433
447
462err_t pressure23_generic_write ( pressure23_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
463
478err_t pressure23_generic_read ( pressure23_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
479
493err_t pressure23_set_command ( pressure23_t *ctx, uint8_t cmd );
494
509
525err_t pressure23_read_memory ( pressure23_t *ctx, uint8_t reg, uint16_t *prom );
526
542err_t pressure23_start_conversion ( pressure23_t *ctx, uint8_t sel_cnv );
543
559
574err_t pressure23_read_config ( pressure23_t *ctx, uint8_t sel_cfg, pressure23_sensor_cfg_t *config );
575
592err_t pressure23_read_adc ( pressure23_t *ctx, uint8_t sel_data, uint32_t *adc_data );
593
609err_t pressure23_write_op_reg ( pressure23_t *ctx, uint8_t fifo_int_th, uint8_t fifo_mode, uint8_t delay );
610
626err_t pressure23_read_op_reg ( pressure23_t *ctx, uint8_t *fifo_int_th, uint8_t *fifo_mode, uint8_t *delay );
627
642err_t pressure23_write_int_mask ( pressure23_t *ctx, uint16_t int_mask_data );
643
658err_t pressure23_read_int_mask ( pressure23_t *ctx, uint16_t *int_mask_data );
659
674err_t pressure23_write_int_reg ( pressure23_t *ctx, uint16_t int_reg_data );
675
690err_t pressure23_read_int_reg ( pressure23_t *ctx, uint16_t *int_reg_data );
691
714err_t pressure23_write_lim_reg ( pressure23_t *ctx, uint8_t sel_adr, uint8_t sel_lim, uint16_t lim_reg_data );
715
735err_t pressure23_read_lim_reg ( pressure23_t *ctx, uint8_t sel_adr, uint8_t sel_lim, uint16_t *lim_reg_data );
736
750err_t pressure23_get_adc_data_press ( pressure23_t *ctx, uint32_t *pressure );
751
765err_t pressure23_get_adc_data_temp ( pressure23_t *ctx, uint32_t *temperature );
766
780
795err_t pressure23_get_measurement_data ( pressure23_t *ctx, float *pressure, float *temperature );
796
809
810#ifdef __cplusplus
811}
812#endif
813#endif // PRESSURE23_H
814
815 // pressure23
816
817// ------------------------------------------------------------------------ END
void pressure23_drv_interface_selection(pressure23_cfg_t *cfg, pressure23_drv_t drv_sel)
Pressure 23 driver interface setup function.
err_t pressure23_read_memory(pressure23_t *ctx, uint8_t reg, uint16_t *prom)
Pressure 23 read memory function.
err_t pressure23_read_op_reg(pressure23_t *ctx, uint8_t *fifo_int_th, uint8_t *fifo_mode, uint8_t *delay)
Pressure 23 operation register data reading function.
err_t pressure23_get_measurement_data(pressure23_t *ctx, float *pressure, float *temperature)
Pressure 23 gets the measurement data function.
err_t pressure23_generic_write(pressure23_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Pressure 23 data writing function.
err_t pressure23_read_int_reg(pressure23_t *ctx, uint16_t *int_reg_data)
Pressure 23 interrupt register data reading function.
err_t pressure23_init(pressure23_t *ctx, pressure23_cfg_t *cfg)
Pressure 23 initialization function.
err_t pressure23_generic_read(pressure23_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Pressure 23 data reading function.
err_t pressure23_sw_reset(pressure23_t *ctx)
Pressure 23 software reset function.
err_t pressure23_write_op_reg(pressure23_t *ctx, uint8_t fifo_int_th, uint8_t fifo_mode, uint8_t delay)
Pressure 23 operation register data writing function.
err_t pressure23_write_lim_reg(pressure23_t *ctx, uint8_t sel_adr, uint8_t sel_lim, uint16_t lim_reg_data)
Pressure 23 limit register data writing function.
uint8_t pressure23_get_interrupt(pressure23_t *ctx)
Pressure 23 gets the interrupt function.
err_t pressure23_read_int_mask(pressure23_t *ctx, uint16_t *int_mask_data)
Pressure 23 interrupt mask data reading function.
err_t pressure23_default_cfg(pressure23_t *ctx)
Pressure 23 default configuration function.
err_t pressure23_set_command(pressure23_t *ctx, uint8_t cmd)
Pressure 23 set the command function.
err_t pressure23_write_int_mask(pressure23_t *ctx, uint16_t int_mask_data)
Pressure 23 interrupt mask data writing function.
err_t pressure23_start_conversion(pressure23_t *ctx, uint8_t sel_cnv)
Pressure 23 start the conversion function.
err_t pressure23_write_int_reg(pressure23_t *ctx, uint16_t int_reg_data)
Pressure 23 interrupt register data writing function.
err_t pressure23_get_adc_data_temp(pressure23_t *ctx, uint32_t *temperature)
Pressure 23 get the ADC temperature data function.
err_t pressure23_read_lim_reg(pressure23_t *ctx, uint8_t sel_adr, uint8_t sel_lim, uint16_t *lim_reg_data)
Pressure 23 limit register data reading function.
err_t pressure23_read_adc(pressure23_t *ctx, uint8_t sel_data, uint32_t *adc_data)
Pressure 23 ADC data reading function.
void pressure23_cfg_setup(pressure23_cfg_t *cfg)
Pressure 23 configuration object setup function.
err_t pressure23_get_calibration_data(pressure23_t *ctx)
Pressure 23 gets the calibration data function.
err_t pressure23_write_config(pressure23_t *ctx, pressure23_sensor_cfg_t config)
Pressure 23 configuration data writing function.
err_t pressure23_get_adc_data_press(pressure23_t *ctx, uint32_t *pressure)
Pressure 23 get the ADC pressure data function.
err_t pressure23_read_config(pressure23_t *ctx, uint8_t sel_cfg, pressure23_sensor_cfg_t *config)
Pressure 23 configuration data reading function.
pressure23_drv_t
Pressure 23 Click driver selector.
Definition pressure23.h:285
@ PRESSURE23_DRV_SEL_SPI
Definition pressure23.h:286
@ PRESSURE23_DRV_SEL_I2C
Definition pressure23.h:287
err_t(* pressure23_master_io_t)(struct pressure23_s *, uint8_t, uint8_t *, uint8_t)
Pressure 23 Click driver interface.
Definition pressure23.h:295
struct pressure23_s pressure23_t
Pressure 23 Click context object.
pressure23_return_value_t
Pressure 23 Click return value data.
Definition pressure23.h:380
@ PRESSURE23_ERROR
Definition pressure23.h:382
@ PRESSURE23_OK
Definition pressure23.h:381
This file contains SPI specific macros, functions, etc.
Pressure 23 Click configuration object.
Definition pressure23.h:341
uint32_t i2c_speed
Definition pressure23.h:350
spi_master_chip_select_polarity_t cs_polarity
Definition pressure23.h:355
pressure23_drv_t drv_sel
Definition pressure23.h:357
pin_name_t sck
Definition pressure23.h:346
spi_master_mode_t spi_mode
Definition pressure23.h:354
pin_name_t mosi
Definition pressure23.h:345
uint32_t spi_speed
Definition pressure23.h:353
pin_name_t scl
Definition pressure23.h:342
pin_name_t int_pin
Definition pressure23.h:348
pin_name_t miso
Definition pressure23.h:344
pin_name_t sda
Definition pressure23.h:343
pin_name_t cs
Definition pressure23.h:347
uint8_t i2c_address
Definition pressure23.h:351
Pressure 23 Click context object.
Definition pressure23.h:302
uint8_t osr_press
Definition pressure23.h:328
uint16_t prom_c1
Definition pressure23.h:317
spi_master_t spi
Definition pressure23.h:306
pressure23_master_io_t write_f
Definition pressure23.h:331
uint32_t prom_serial_num
Definition pressure23.h:313
uint8_t osr_temp
Definition pressure23.h:329
uint16_t prom_c6
Definition pressure23.h:322
uint16_t prom_c3
Definition pressure23.h:319
uint16_t prom_c4
Definition pressure23.h:320
pressure23_drv_t drv_sel
Definition pressure23.h:310
uint16_t prom_c8
Definition pressure23.h:324
uint16_t prom_c10
Definition pressure23.h:326
digital_in_t int_pin
Definition pressure23.h:303
pressure23_master_io_t read_f
Definition pressure23.h:332
i2c_master_t i2c
Definition pressure23.h:305
uint16_t prom_c2
Definition pressure23.h:318
uint16_t prom_c9
Definition pressure23.h:325
uint16_t prom_c5
Definition pressure23.h:321
uint8_t slave_address
Definition pressure23.h:308
uint16_t prom_c7
Definition pressure23.h:323
uint8_t prom_product_id
Definition pressure23.h:314
pin_name_t chip_select
Definition pressure23.h:309
uint8_t prom_crc
Definition pressure23.h:315
Pressure 23 Click sensor configuration object.
Definition pressure23.h:366
uint8_t resolution
Definition pressure23.h:370
uint8_t osr
Definition pressure23.h:371
uint8_t filter
Definition pressure23.h:369
uint8_t sel
Definition pressure23.h:367
uint8_t ratio
Definition pressure23.h:368