BME680 driver trailing whitespaces removed

This commit is contained in:
Gunar Schorcht 2017-10-28 17:17:54 +02:00
parent 1af3f2e033
commit f431f831f6
8 changed files with 318 additions and 325 deletions

View file

@ -18,9 +18,9 @@ Interface selection is done automatically by the sensor using the SPI CS signal.
## Measurement process
Once the BME680 has been initialized, it can be used for measurements. The BME680 operates in two different modes, the **sleep mode** and the **forced mode**.
Once the BME680 has been initialized, it can be used for measurements. The BME680 operates in two different modes, the **sleep mode** and the **forced mode**.
The sensor starts after power-up automatically in the *sleep mode* where it does not perform any measurement and consumes only 0.15 μA. Measurements are only done in *forced mode*.
The sensor starts after power-up automatically in the *sleep mode* where it does not perform any measurement and consumes only 0.15 μA. Measurements are only done in *forced mode*.
**Please note:** There are two further undocumented modes, the *parallel* and the *sequential* mode. They can't be supported by the driver, since it is not clear what they do and how to use them.
@ -47,7 +47,7 @@ if (bme680_force_measurement (sensor)) // STEP 1
{
// STEP 2: passive waiting until measurement results are available
vTaskDelay (duration);
// STEP 3: get the results and do something with them
if (bme680_get_results_float (sensor, &values))
...
@ -61,7 +61,7 @@ if (bme680_force_measurement (sensor)) // STEP 1
{
// STEP 2: busy waiting until measurement results are available
while (bme680_is_measuring (sensor)) ;
// STEP 3: get the results and do something with them
if (bme680_get_results_float (sensor, &values))
...
@ -81,7 +81,7 @@ if (bme680_measure_float (sensor, &values))
#### Measurement results
Once the sensor has finished the measurement raw data are available at the sensor. Either function ```bme680_get_results_fixed``` or function ```bme680_get_results_float``` can be used to fetch the results. Both functions read raw data from the sensor and converts them into utilizable fixed point or floating point sensor values.
Once the sensor has finished the measurement raw data are available at the sensor. Either function ```bme680_get_results_fixed``` or function ```bme680_get_results_float``` can be used to fetch the results. Both functions read raw data from the sensor and converts them into utilizable fixed point or floating point sensor values.
**Please note:** Conversion of raw sensor data into the final sensor values is based on very complex calculations that use a large number of calibration parameters. Therefore, the driver does not provide functions that only return the raw sensor data.
@ -112,7 +112,7 @@ The sensor allows to change a lot of measurement parameters.
#### Oversampling rates
To increase the resolution of raw sensor data, the sensor supports oversampling for temperature, pressure, and humidity measurements. Using function ```bme680_set_oversampling_rates```, individual **oversampling rates** can be defined for these measurements. With an oversampling rate *osr*, the resolution of the according raw sensor data can be increased from 16 bit to 16+ld(*osr*) bit.
To increase the resolution of raw sensor data, the sensor supports oversampling for temperature, pressure, and humidity measurements. Using function ```bme680_set_oversampling_rates```, individual **oversampling rates** can be defined for these measurements. With an oversampling rate *osr*, the resolution of the according raw sensor data can be increased from 16 bit to 16+ld(*osr*) bit.
Possible oversampling rates are 1x (default by the driver) 2x, 4x, 8x and 16x. It is also possible to define an oversampling rate of 0. This **deactivates** the corresponding measurement and the output values become invalid.
@ -140,11 +140,11 @@ bme680_set_filter_size(sensor, iir_size_7);
bme680_set_filter_size(sensor, iir_size_0);
...
```
#### Heater profile
For the gas measurement, the sensor integrates a heater. Parameters for this heater are defined by **heater profiles**. The sensor supports up to 10 such heater profiles, which are numbered from 0 to 9. Each profile consists of a temperature set-point (the target temperature) and a heating duration. By default, only the heater profile 0 with 320 degree Celsius as target temperature and 150 ms heating duration is defined.
**Please note:** According to the data sheet, target temperatures between 200 and 400 degrees Celsius are typical and about 20 to 30 ms are necessary for the heater to reach the desired target temperature.
Function ```bme680_set_heater_profile``` can be used to set the parameters for one of the heater profiles 0 ... 9. Once the parameters of a heater profile are defined, the gas measurement can be activated with that heater profile using function ```bme680_use_heater_profile```. If -1 or ```BME680_HEATER_NOT_USED``` is used as heater profile, gas measurement is deactivated completely.
@ -176,7 +176,7 @@ the user task could use them as a sequence like following:
```
...
while (1)
while (1)
{
switch (count++ % 5)
{
@ -190,11 +190,11 @@ while (1)
// measurement duration changes in each cycle
uint32_t duration = bme680_get_measurement_duration(sensor);
// trigger the sensor to start one TPHG measurement cycle
// trigger the sensor to start one TPHG measurement cycle
if (bme680_force_measurement (sensor))
{
vTaskDelay (duration);
// get the results and do something with them
if (bme680_get_results_float (sensor, &values))
...
@ -216,7 +216,7 @@ bme680_set_ambient_temperature (sensor, ambient);
## Error Handling
Most driver functions return a simple boolean value to indicate whether its execution was successful or an error happened. In the latter case, the member ```error_code``` of the sensor device data structure is set which indicates what error happened.
Most driver functions return a simple boolean value to indicate whether its execution was successful or an error happened. In the latter case, the member ```error_code``` of the sensor device data structure is set which indicates what error happened.
There are two different error levels that are ORed into one single *error_code*, errors in the I2C or SPI communication and errors of the BME680 sensor itself. To test for a certain error, first you can AND the *error_code* with one of the error masks, ```BME680_INT_ERROR_MASK``` for I2C or SPI errors and ```BME680_DRV_ERROR_MASK``` for other errors. Then you can test the result for a certain error code.
@ -231,11 +231,11 @@ if (bme680_get_results_float (sensor, &values))
else
{
// error happened
switch (sensor->error_code & BME680_INT_ERROR_MASK)
{
case BME680_I2C_BUSY: ...
case BME680_I2C_READ_FAILED: ...
case BME680_INT_BUSY: ...
case BME680_INT_READ_FAILED: ...
...
}
switch (sensor->error_code & BME680_DRV_ERROR_MASK)
@ -247,7 +247,7 @@ else
}
```
## Usage
## Usage
First, the hardware configuration has to be established. This can differ dependent on the communication interface and the number of sensors used.
@ -278,9 +278,9 @@ Next figure shows the configuration with only one sensor at SPI bus using GPIO2
+-------------------------+ +--------+
```
**Please note:**
**Please note:**
1. Since the system flash memory is connected to SPI bus 0, the sensor has to be connected to SPI bus 1.
1. Since the system flash memory is connected to SPI bus 0, the sensor has to be connected to SPI bus 1.
2. GPIO15 which is used as CS signal of SPI bus 1 does not work correctly together with the BME680. Therefore, the user has to specify another GPIO pin as CS signal, e.g., GPIO2.
Next figure shows a possible configuration with two I2C buses. In that case, the sensors can have same or different I2C slave addresses.
@ -332,7 +332,7 @@ Dependent on the hardware configuration, the communication interface settings ha
```
### Main programm
### Main program
If I2C interfaces are used, they have to be initialized first.
@ -375,18 +375,18 @@ if (sensor)
xTaskCreate(user_task, "user_task", 256, NULL, 2, NULL);
/** -- OPTIONAL PART -- */
// Changes the oversampling rates to 4x oversampling for temperature
// and 2x oversampling for humidity. Pressure measurement is skipped.
bme680_set_oversampling_rates(sensor, osr_4x, osr_none, osr_2x);
// Change the IIR filter size for temperature and pressure to 7.
bme680_set_filter_size(sensor, iir_size_7);
// Change the heater profile 0 to 200 degree Celsius for 100 ms.
bme680_set_heater_profile (sensor, 0, 200, 100);
bme680_use_heater_profile (sensor, 0);
...
}
```
@ -407,26 +407,26 @@ void user_task(void *pvParameters)
bme680_values_float_t values;
TickType_t last_wakeup = xTaskGetTickCount();
// as long as sensor configuration isn't changed, duration is constant
uint32_t duration = bme680_get_measurement_duration(sensor);
while (1)
while (1)
{
// trigger the sensor to start one TPHG measurement cycle
// trigger the sensor to start one TPHG measurement cycle
bme680_force_measurement (sensor);
// passive waiting until measurement results are available
vTaskDelay (duration);
// alternatively: busy waiting until measurement results are available
// while (bme680_is_measuring (sensor)) ;
// get the results and do something with them
if (bme680_get_results_float (sensor, &values))
printf("%.3f BME680 Sensor: %.2f °C, %.2f %%, %.2f hPa, %.2f Ohm\n",
printf("%.3f BME680 Sensor: %.2f °C, %.2f %%, %.2f hPa, %.2f Ohm\n",
(double)sdk_system_get_time()*1e-3,
values.temperature, values.humidity,
values.temperature, values.humidity,
values.pressure, values.gas_resistance);
// passive waiting until 1 second is over
@ -435,7 +435,7 @@ void user_task(void *pvParameters)
}
```
Function ```bme680_force_measurement``` is called inside the task loop to perform exactly one measurement in each cycle.
Function ```bme680_force_measurement``` is called inside the task loop to perform exactly one measurement in each cycle.
The task is then delayed using function ```vTaskDelay``` and the value returned from function ```bme680_get_measurement_duration``` or as long as function ```bme680_is_measuring``` returns true.
@ -448,7 +448,7 @@ Once the measurement results are available, they can be fetched as fixed point o
```
// Uncomment to use SPI
// #define SPI_USED
#include "espressif/esp_common.h"
#include "esp/uart.h"
@ -476,7 +476,7 @@ Once the measurement results are available, they can be fetched as fixed point o
static bme680_sensor_t* sensor;
/*
* User task that triggers measurements of sensor every seconds. It uses
* User task that triggers measurements of sensor every seconds. It uses
* function *vTaskDelay* to wait for measurement results. Busy waiting
* alternative is shown in comments
*/
@ -485,26 +485,26 @@ void user_task(void *pvParameters)
bme680_values_float_t values;
TickType_t last_wakeup = xTaskGetTickCount();
// as long as sensor configuration isn't changed, duration is constant
uint32_t duration = bme680_get_measurement_duration(sensor);
while (1)
while (1)
{
// trigger the sensor to start one TPHG measurement cycle
// trigger the sensor to start one TPHG measurement cycle
bme680_force_measurement (sensor);
// passive waiting until measurement results are available
vTaskDelay (duration);
// alternatively: busy waiting until measurement results are available
// while (bme680_is_measuring (sensor)) ;
// get the results and do something with them
if (bme680_get_results_float (sensor, &values))
printf("%.3f BME680 Sensor: %.2f °C, %.2f %%, %.2f hPa, %.2f Ohm\n",
printf("%.3f BME680 Sensor: %.2f °C, %.2f %%, %.2f hPa, %.2f Ohm\n",
(double)sdk_system_get_time()*1e-3,
values.temperature, values.humidity,
values.temperature, values.humidity,
values.pressure, values.gas_resistance);
// passive waiting until 1 second is over
@ -519,9 +519,9 @@ void user_init(void)
uart_set_baud(0, 115200);
// Give the UART some time to settle
sdk_os_delay_us(500);
/** -- MANDATORY PART -- */
#ifdef SPI_USED
// Init the sensor connected either to SPI.
sensor = bme680_init_sensor (SPI_BUS, 0, SPI_CS_GPIO);
@ -539,11 +539,11 @@ void user_init(void)
xTaskCreate(user_task, "user_task", 256, NULL, 2, NULL);
/** -- OPTIONAL PART -- */
// Changes the oversampling rates to 4x oversampling for temperature
// and 2x oversampling for humidity. Pressure measurement is skipped.
bme680_set_oversampling_rates(sensor, osr_4x, osr_none, osr_2x);
// Change the IIR filter size for temperature and pressure to 7.
bme680_set_filter_size(sensor, iir_size_7);
@ -553,4 +553,3 @@ void user_init(void)
}
}
```