You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: libs/bme68x/bme68x.md
+9-20Lines changed: 9 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,26 +16,26 @@ In addition, the Bosch library github repo contained an Arduino library written
16
16
17
17
### Example Usage
18
18
19
-
The following example shows creation and initialization of a `bme68x_sensor_t` struct, which contains a pointer to an I2C handle previously initialized in application code. The struct also contains status, a BME68x device struct, configuration, sensor data, and the last operation mode.
19
+
The following example shows creation and initialization of a `bme68x_sensor_t` struct, which contains a pointer to an I2C handle previously initialized in application code, in addition to a pointer to a function from the application that should be used when a microsecond delay is needed. The struct also contains status, a BME68x device struct, configuration, sensor data, and the last operation mode.
20
20
21
21
After initialization, configuration is performed, using default oversampling values for the temperature, pressure, and humidity measurements, and a heater configuration of 300 deg C for 100ms in forced mode.
22
22
23
-
Data is then fetched from the sensor repeatedly in a loop. The specific delay function may be adjusted to use a hardware timer, but the microsecond delay should still be based on the return value from the `bme_get_meas_dur` function.
23
+
Data is then fetched from the sensor repeatedly in a loop. As noted above, the delay function should be implemented in application code, for example using a hardware timer and function defined in `tim.c`, but the microsecond delay should still be based on the return value from the `bme_get_meas_dur` function.
24
24
25
25
```c
26
26
#include"bme68x_driver.h"
27
27
28
28
intmain(void) {
29
29
bme68x_sensor_t bme;
30
-
bme_init(&bme, &hi2c1);
30
+
bme_init(&bme, &hi2c1, &delay_us_timer);
31
31
bme_set_TPH_default(&bme);
32
32
bme_set_heaterprof(&bme, 300, 100);
33
33
34
34
while (1)
35
35
{
36
36
bme_set_opmode(&bme, BME68X_FORCED_MODE);
37
37
/**@todo: May adjust the specific timing function called here, but it should be based on bme_get_meas_dur */
Structure to store necessary configuration and data to interact with the sensor over I2C. Contains as members the structs `bme68x_dev`, `bme68x_conf`, `bme68x_heatr_conf`, and `bme68x_data`, which are defined in `bme68x_defs.h`. Also contains an `I2C_HandleTypeDef` pointer to allow I2C communication using STM32 HAL I2C functions.
56
+
Structure to store necessary configuration and data to interact with the sensor over I2C. Contains as members the structs `bme68x_dev`, `bme68x_conf`, `bme68x_heatr_conf`, and `bme68x_data`, which are defined in `bme68x_defs.h`. Also contains an `I2C_HandleTypeDef` pointer to allow I2C communication using STM32 HAL I2C functions, and a pointer to a microsecond delay function defined by the application.
57
+
58
+
**NOTE**: The delay function signature is currently determined by the original one used by the Bosch library developers. The function signature is fairly simple (it accepts a `uint32_t` microsecond delay value and a `void *` interface pointer), but if desired, the Bosch library code may be modified to accommodate an alternate signature.
57
59
58
60
### `bme_init()`
59
61
@@ -62,6 +64,7 @@ Configures the sensor with default settings.
62
64
**Parameters:**
63
65
- `bme`: Pointer to newly initialized bme68x sensor interface
64
66
- `i2c_handle`: Pointer to I2C handle
67
+
- `delay_fn`: Pointer to a microsecond delay function
65
68
66
69
### `bme_check_status()`
67
70
@@ -128,14 +131,6 @@ Get the measurement duration in microseconds. This is the total measurement dura
128
131
**Returns:**
129
132
- `uint32_t`: Measurement duration in microseconds
130
133
131
-
### `bme_delay_us()`
132
-
133
-
Implements the default microsecond delay callback, as called from the Bosch library. **NOTE**: This function signature is currently determined by the original one used by the Bosch library developers. We may wish to modify it in the future to better accommodate our usage of the STM32 HAL timing functions.
134
-
135
-
**Parameters:**
136
-
- `period_us`: Duration of the delay in microseconds
137
-
- `intf_ptr`: Pointer to the interface descriptor for I2C
138
-
139
134
### `bme_write()`
140
135
141
136
Implements the default I2C write transaction. This is leveraged by the Bosch library to perform writes to the device over I2C. It should typically not be necessary for application code to call this function directly, though it may be useful in troubleshooting.
@@ -196,15 +191,9 @@ There are a few functions from the Bosch library that are not currently in use,
196
191
197
192
## Next Steps
198
193
199
-
**Update delay function**
200
-
201
-
The current delay function was added to allow for retrieval of data in a prototyping context. It should be replaced, probably with a hardware timer. Usage of the `HAL_Delay` function was attempted, but that function provides millisecond delays, rather that the microsecond delays required by this driver.
202
-
203
-
Other alternatives might be using the DWT as a cycle counter, or modifying the Bosch library callback signature to be more specific to our needs.
204
-
205
194
**Validate humidity measurements**
206
195
207
-
The humidity measurements currently appear to be returning the max value consistently. This may be the result of the above prototyping-level delay function, or possibly an individual sensor-specific problem. First steps to resolve are to update the above delay function, test on additional sensors, and adjust the oversampling setting.
196
+
The humidity measurements currently appear to be returning the max value consistently. This may be an individual sensor-specific problem, it could be related to a timing issue, or possibly an oversampling setting. First steps to resolve are to test on additional sensors, adjust the oversampling setting, or simply step through the code with a debugger and see if it's possible to retrieve a valid humidity measurement at any stage.
0 commit comments