SPI and I2C pressure and temperature sensor driver. More...
SPI and I2C pressure and temperature sensor driver.
The unit and the range depend on the part number of the sensor. The default parameters assume a 0..160 mbar model. It is the responsibility of the user to use homogeneous units, depending on the actual sensor being used. The pressure range is set when calling abp2_init().
This driver provides [S]ensor [A]ctuator [U]ber [L]ayer capabilities. The functions return 0 on success or a negative value made from errno.h
on error.
See RIOT/tests/drivers/abp2
for an example application using this driver.
Add the following modules to the application makefile:
When the I2C version is supported, abp2_i2c
can be used for I2C sensors instead of abp2_spi
.
To use the SAUL interface, add also to the makefile:
Initialize the driver by calling abp2_init().
When a measurement is started on the sensor, its internal ADC converts both pressure and temperature. The conversion takes about 5ms. These two values are retrieved in a single bus transfer.
There are three ways to use the driver:
The first one will block for about 5ms and return the latest data, while the second one will return almost immediately but will return data from the previous ADC conversion.
This driver currently doesn't support the I2C flavor of these sensors.
Topics | |
Status bits | |
Macro definitions to manipulate the bits of the status byte. | |
Files | |
file | abp2_params.h |
Default configuration for ABP2 capaticance-to-digital converter. | |
file | abp2.h |
Honeywell ABP2 series pressure and temperature sensor driver. | |
Data Structures | |
struct | abp2_params |
Parameters for ABP2 sensors. More... | |
struct | abp2 |
Device descriptor for ABP2 sensors. More... | |
struct | abp2_raw |
Raw values read from a ABP2 sensor. More... | |
Typedefs | |
typedef struct abp2_params | abp2_params_t |
Parameters for ABP2 sensors. | |
typedef struct abp2 | abp2_t |
Device descriptor for ABP2 sensors. | |
typedef struct abp2_raw | abp2_raw_t |
Raw values read from a ABP2 sensor. | |
Functions | |
int | abp2_init (abp2_t *dev, const abp2_params_t *params) |
Initialize the ABP2 sensor. | |
int | abp2_measure (const abp2_t *dev) |
Let the sensor make one measurement. | |
int | abp2_read (const abp2_t *dev, int32_t *press, int32_t *temp) |
Measure pressure and temperature (blocking version). | |
int | abp2_read_nb (const abp2_t *dev, int32_t *press, int32_t *temp) |
Measure pressure and temperature (non-blocking version). | |
uint8_t | abp2_getstatus (const abp2_t *dev) |
Read the status byte of the sensor. | |
int | abp2_read_raw (const abp2_t *dev, abp2_raw_t *raw_values) |
Read pressure and temperature raw values. | |
int | abp2_measure_read (const abp2_t *dev, abp2_raw_t *raw_values) |
Start measurement and read previous pressure and temperature raw values. | |
int32_t | abp2_pressure (const abp2_t *dev, const abp2_raw_t *raw_values) |
Convert ADC counts to pressure. | |
int32_t | abp2_temperature (const abp2_t *dev, const abp2_raw_t *raw_values) |
Convert ADC counts to temperature . | |
typedef struct abp2_params abp2_params_t |
Parameters for ABP2 sensors.
The range must be set in thousandths of sensor unit. For example, if the sensor unit is mbar, set the rangeMin and rangeMax properties in µbar.
uint8_t abp2_getstatus | ( | const abp2_t * | dev | ) |
Read the status byte of the sensor.
[in] | dev | Sensor device descriptor. |
int abp2_init | ( | abp2_t * | dev, |
const abp2_params_t * | params ) |
Initialize the ABP2 sensor.
[in] | dev | Sensor device descriptor. |
[in] | params | Sensor parameters. |
Assign the parameters params to the device descriptor dev. Poll the device until the busy flag clears or the operation times out. On SPI version, init the chip select pin.
int abp2_measure | ( | const abp2_t * | dev | ) |
Let the sensor make one measurement.
[in] | dev | Sensor device descriptor. |
This function lets the sensor transition from standby to operation mode and make one measurement, after which it will automatically return to standby mode. Call abp2_read_raw() to retrieve the data.
int abp2_measure_read | ( | const abp2_t * | dev, |
abp2_raw_t * | raw_values ) |
Start measurement and read previous pressure and temperature raw values.
[in] | dev | Sensor device descriptor. |
[out] | raw_values | Raw values read from the sensor. |
Read the raw values, i.e. ADC counts that result from the previous measurement. Then, populate raw_values. The raw values can be converted to physical quantities with abp2_pressure() and abp2_temperature().
int32_t abp2_pressure | ( | const abp2_t * | dev, |
const abp2_raw_t * | raw_values ) |
Convert ADC counts to pressure.
[in] | dev | Sensor device descriptor. |
[in] | raw_values | Raw values read from the sensor. |
int abp2_read | ( | const abp2_t * | dev, |
int32_t * | press, | ||
int32_t * | temp ) |
Measure pressure and temperature (blocking version).
[in] | dev | Sensor device descriptor. |
[out] | press | Pressure value read from the sensor (thousandths of sensor unit). |
[out] | temp | Temperature read from the sensor (milli-degrees Celsius). |
This function is blocking. It starts a conversion on the sensor ADC for both pressure and temperature, waits until the busy flag clears or for a 10ms timeout, reads the values from the sensor and converts them to physical quantities.
int abp2_read_nb | ( | const abp2_t * | dev, |
int32_t * | press, | ||
int32_t * | temp ) |
Measure pressure and temperature (non-blocking version).
[in] | dev | Sensor device descriptor. |
[out] | press | Pressure value read from the sensor (thousandths of sensor unit). |
[out] | temp | Temperature read from the sensor (milli-degrees Celsius). |
This function starts a conversion on the sensor ADC and reads the values from the previous conversion in a single bus transfer and converts them to physical quantities.
int abp2_read_raw | ( | const abp2_t * | dev, |
abp2_raw_t * | raw_values ) |
Read pressure and temperature raw values.
[in] | dev | Sensor device descriptor. |
[out] | raw_values | Raw values read from the sensor. |
Read the raw values, i.e. ADC counts and populate raw_values. The raw values can be converted to physical quantities with abp2_pressure() and abp2_temperature().
int32_t abp2_temperature | ( | const abp2_t * | dev, |
const abp2_raw_t * | raw_values ) |
Convert ADC counts to temperature .
[in] | dev | Sensor device descriptor. |
[in] | raw_values | Raw values read from the sensor. |