barometer5  2.0.0.0
barometer5.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 BAROMETER5_H
29 #define BAROMETER5_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 
49 
70 #define BAROMETER5_CMD_RESET 0x1E
71 #define BAROMETER5_CMD_CONV_D1_OSR_256 0x40
72 #define BAROMETER5_CMD_CONV_D1_OSR_512 0x42
73 #define BAROMETER5_CMD_CONV_D1_OSR_1024 0x44
74 #define BAROMETER5_CMD_CONV_D1_OSR_2048 0x46
75 #define BAROMETER5_CMD_CONV_D1_OSR_4096 0x48
76 #define BAROMETER5_CMD_CONV_D2_OSR_256 0x50
77 #define BAROMETER5_CMD_CONV_D2_OSR_512 0x52
78 #define BAROMETER5_CMD_CONV_D2_OSR_1024 0x54
79 #define BAROMETER5_CMD_CONV_D2_OSR_2048 0x56
80 #define BAROMETER5_CMD_CONV_D2_OSR_4096 0x58
81 #define BAROMETER5_CMD_ADC_READ 0x00
82 #define BAROMETER5_CMD_PROM_READ_START 0xA0
83  // barometer5_reg
85 
100 #define BAROMETER5_RATIO_256 0x00
101 #define BAROMETER5_RATIO_512 0x01
102 #define BAROMETER5_RATIO_1024 0x02
103 #define BAROMETER5_RATIO_2048 0x03
104 #define BAROMETER5_RATIO_4096 0x04
105 
111 #define BAROMETER5_SET_DEV_ADDR 0x76
112  // barometer5_set
114 
129 #define BAROMETER5_MAP_MIKROBUS( cfg, mikrobus ) \
130  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
131  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
132  // barometer5_map // barometer5
135 
140 typedef struct
141 {
142  // Modules
143  i2c_master_t i2c;
145  // I2C slave address
146  uint8_t slave_address;
150  uint16_t press_sens_c1;
151  uint16_t press_off_c2;
152  uint16_t press_tcs_c3;
153  uint16_t press_tco_c4;
154  uint16_t press_tref_c5;
155  uint16_t press_tempsens_c6;
157  uint8_t ratio_temp;
158  uint8_t ratio_press;
160 } barometer5_t;
161 
166 typedef struct
167 {
168  pin_name_t scl;
169  pin_name_t sda;
171  uint32_t i2c_speed;
172  uint8_t i2c_address;
177 
182 typedef enum
183 {
185  BAROMETER5_ERROR = -1
186 
188 
205 
221 
236 
252 err_t barometer5_generic_write ( barometer5_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
253 
269 err_t barometer5_generic_read ( barometer5_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
270 
285 err_t barometer5_set_command ( barometer5_t *ctx, uint8_t cmd );
286 
302 err_t barometer5_set_ratio ( barometer5_t *ctx, uint8_t temp_ratio, uint8_t press_ratio );
303 
318 
333 
349 err_t barometer5_get_raw_data ( barometer5_t *ctx, uint32_t *temp_data, uint32_t *press_data );
350 
365 err_t barometer5_get_temperature ( barometer5_t *ctx, float *temperature );
366 
381 err_t barometer5_get_pressure ( barometer5_t *ctx, float *pressure );
382 
399 err_t barometer5_calculate_altitude ( barometer5_t *ctx, float *altitude );
400 
417 err_t barometer5_get_data ( barometer5_t *ctx, float *temperature, float *pressure );
418 
419 
420 #ifdef __cplusplus
421 }
422 #endif
423 #endif // BAROMETER5_H
424  // barometer5
426 
427 // ------------------------------------------------------------------------ END
barometer5_t::press_off_c2
uint16_t press_off_c2
Definition: barometer5.h:151
barometer5_t::press_tref_c5
uint16_t press_tref_c5
Definition: barometer5.h:154
barometer5_t
Barometer 5 Click context object.
Definition: barometer5.h:141
barometer5_generic_read
err_t barometer5_generic_read(barometer5_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Barometer 5 I2C reading function.
barometer5_t::sea_lvl_pressure
float sea_lvl_pressure
Definition: barometer5.h:148
barometer5_cfg_t
Barometer 5 Click configuration object.
Definition: barometer5.h:167
barometer5_default_cfg
err_t barometer5_default_cfg(barometer5_t *ctx)
Barometer 5 default configuration function.
barometer5_cfg_t::sda
pin_name_t sda
Definition: barometer5.h:169
barometer5_get_raw_data
err_t barometer5_get_raw_data(barometer5_t *ctx, uint32_t *temp_data, uint32_t *press_data)
Barometer 5 get raw data function.
barometer5_t::press_tco_c4
uint16_t press_tco_c4
Definition: barometer5.h:153
barometer5_sw_reset
err_t barometer5_sw_reset(barometer5_t *ctx)
Barometer 5 software reset function.
barometer5_t::i2c
i2c_master_t i2c
Definition: barometer5.h:143
barometer5_set_command
err_t barometer5_set_command(barometer5_t *ctx, uint8_t cmd)
Barometer 5 set command function.
barometer5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: barometer5.h:171
barometer5_cfg_t::scl
pin_name_t scl
Definition: barometer5.h:168
barometer5_cfg_t::i2c_address
uint8_t i2c_address
Definition: barometer5.h:172
barometer5_init
err_t barometer5_init(barometer5_t *ctx, barometer5_cfg_t *cfg)
Barometer 5 initialization function.
barometer5_t::press_sens_c1
uint16_t press_sens_c1
Definition: barometer5.h:150
barometer5_return_value_t
barometer5_return_value_t
Barometer 5 Click return value data.
Definition: barometer5.h:183
barometer5_t::press_tcs_c3
uint16_t press_tcs_c3
Definition: barometer5.h:152
barometer5_get_pressure
err_t barometer5_get_pressure(barometer5_t *ctx, float *pressure)
Barometer 5 get pressure data function.
barometer5_get_temperature
err_t barometer5_get_temperature(barometer5_t *ctx, float *temperature)
Barometer 5 get temperature data function.
barometer5_t::press_tempsens_c6
uint16_t press_tempsens_c6
Definition: barometer5.h:155
BAROMETER5_OK
@ BAROMETER5_OK
Definition: barometer5.h:184
barometer5_set_ratio
err_t barometer5_set_ratio(barometer5_t *ctx, uint8_t temp_ratio, uint8_t press_ratio)
Barometer 5 set data ratio function.
barometer5_cfg_t::sea_level_pressure
float sea_level_pressure
Definition: barometer5.h:174
barometer5_calculate_altitude
err_t barometer5_calculate_altitude(barometer5_t *ctx, float *altitude)
Barometer 5 calculate altitude function.
barometer5_cfg_setup
void barometer5_cfg_setup(barometer5_cfg_t *cfg)
Barometer 5 configuration object setup function.
BAROMETER5_ERROR
@ BAROMETER5_ERROR
Definition: barometer5.h:185
barometer5_get_data
err_t barometer5_get_data(barometer5_t *ctx, float *temperature, float *pressure)
Barometer 5 get data function.
barometer5_t::ratio_temp
uint8_t ratio_temp
Definition: barometer5.h:157
barometer5_t::slave_address
uint8_t slave_address
Definition: barometer5.h:146
barometer5_generic_write
err_t barometer5_generic_write(barometer5_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Barometer 5 I2C writing function.
barometer5_t::ratio_press
uint8_t ratio_press
Definition: barometer5.h:158
barometer5_get_calibration_data
err_t barometer5_get_calibration_data(barometer5_t *ctx)
Barometer 5 get calibration data function.