XENSIV DPS3xx Pressure Sensor (sensor-xensiv-dps3xx)
Pressure Sensor

General Description

Basic set of APIs for interacting with the XENSIV™ DPS3xx pressure sensors.

This provides basic initialization and access to to the pressure & temperature data. It also provides access to the configuration settings for the sensor for full control. More information about the motion sensor is available at: https://www.infineon.com/cms/en/product/sensor/pressure-sensors/pressure-sensors-for-iot/

Note
This library uses delays while waiting for the sensor. If the RTOS_AWARE component is set or CY_RTOS_AWARE is defined, the driver will defer to the RTOS for delays. Because of this, it is not safe to call any functions other than xensiv_dps3xx_init_i2c until after the RTOS scheduler has started.

Code snippets

Snippet 1: Simple initialization with I2C.

The following snippet initializes an I2C instance and the DPS3xx.

/* Initialize i2c for pressure sensor */
result = cyhal_i2c_init(&i2c, CYBSP_I2C_SDA, CYBSP_I2C_SCL, NULL);
CY_ASSERT(result == CY_RSLT_SUCCESS);
result = cyhal_i2c_configure(&i2c, &i2c_cfg);
CY_ASSERT(result == CY_RSLT_SUCCESS);
/* Initialize pressure sensor */
result = xensiv_dps3xx_mtb_init_i2c(&pressure_sensor, &i2c, XENSIV_DPS3XX_I2C_ADDR_DEFAULT);
CY_ASSERT(result == CY_RSLT_SUCCESS);
@ XENSIV_DPS3XX_I2C_ADDR_DEFAULT
Default I2C address (0x77)
Definition: xensiv_dps3xx.h:84

Snippet 2: Sensor configuration.

The following snippet demonstrates how to configure the sensor.

{
.dev_mode = XENSIV_DPS3XX_MODE_BACKGROUND_ALL, // Set device to read temp &
// pressure
.pressure_rate = XENSIV_DPS3XX_RATE_1, // 1x sample rate for pressure
.temperature_rate = XENSIV_DPS3XX_RATE_1, // 1x sample rate for data
.pressure_oversample = XENSIV_DPS3XX_OVERSAMPLE_1, // 1x oversample for pressure
.temperature_oversample = XENSIV_DPS3XX_OVERSAMPLE_1, // 1x oversample for temp
.data_timeout = 500, // Wait up to 500ms for measurement data
.i2c_timeout = 10, // Wait up to 10ms for i2c operations
};
result = xensiv_dps3xx_set_config(&pressure_sensor, &config);
CY_ASSERT(result == CY_RSLT_SUCCESS);
xensiv_dps3xx_mode_t dev_mode
Operating mode of device.
Definition: xensiv_dps3xx.h:188
cy_rslt_t xensiv_dps3xx_set_config(xensiv_dps3xx_t *obj, xensiv_dps3xx_config_t *config)
Sets the current configuration parameters for the sensor.
Definition: xensiv_dps3xx.c:670
@ XENSIV_DPS3XX_RATE_1
Normal sample rate.
Definition: xensiv_dps3xx.h:136
@ XENSIV_DPS3XX_OVERSAMPLE_1
1x oversample rate
Definition: xensiv_dps3xx.h:122
@ XENSIV_DPS3XX_MODE_BACKGROUND_ALL
Ongoing background pressure and temp.
Definition: xensiv_dps3xx.h:105
Structure of configuration parameters for the pressure sensor.
Definition: xensiv_dps3xx.h:187

Snippet 3: Reading from the sensor.

The following snippet demonstrates how to read data from the sensor.

while (measure_data)
{
/* Get the pressure and temperature data and print the results to the UART */
float pressure, temperature;
xensiv_dps3xx_read(&pressure_sensor, &pressure, &temperature);
printf("Pressure : %8f\r\n", (double)pressure);
printf("Temperature: :%8f\r\n\r\n", (double)temperature);
cyhal_system_delay_ms(1000);
}
cy_rslt_t xensiv_dps3xx_read(xensiv_dps3xx_t *obj, float *pressure, float *temperature)
Gets the current pressure and temperature values from the sensor.
Definition: xensiv_dps3xx.c:739

Data Structures

struct  xensiv_dps3xx_config_t
 Structure of configuration parameters for the pressure sensor. More...
 
struct  xensiv_dps3xx_i2c_comm_t
 Structure providing function pointers to I2C communication routines. More...
 
struct  xensiv_dps3xx_t
 Structure of pressure sensor context. More...
 

Macros

#define XENSIV_DPS3XX_RSLT_ERR_WRITE_TOO_LARGE    (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_BOARD_HARDWARE_DPS3XX, 0x00))
 Result code indicating an unexpectedly large I2C write was requested that is not supported.
 
#define XENSIV_DPS3XX_RSLT_ERR_DATA_NOT_READY    (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_BOARD_HARDWARE_DPS3XX, 0x01))
 Result code indicating a timeout occurred waiting for the pressure sensor data to be ready.
 

Typedefs

typedef cy_rslt_t(* xensiv_dps3xx_i2c_read_t) (void *context, uint16_t timeout, uint8_t i2c_addr, uint8_t reg_adr, uint8_t *data, uint8_t length)
 Function pointer for reading sensor registers via I2C.
 
typedef cy_rslt_t(* xensiv_dps3xx_i2c_write_t) (void *context, uint16_t timeout, uint8_t i2c_addr, uint8_t reg_adr, uint8_t *data, uint8_t length)
 Function pointer for writing sensor registers via I2C.
 
typedef cy_rslt_t(* xensiv_dps3xx_delay_t) (uint32_t ms)
 Function pointer for delay operations.
 

Enumerations

enum  xensiv_dps3xx_i2c_addr_t {
  XENSIV_DPS3XX_I2C_ADDR_DEFAULT = 0x77 ,
  XENSIV_DPS3XX_I2C_ADDR_ALT = 0x76
}
 Possible I2C addresses to communicate with the device. More...
 
enum  xensiv_dps3xx_mode_t {
  XENSIV_DPS3XX_MODE_IDLE = 0x00 ,
  XENSIV_DPS3XX_MODE_COMMAND_PRESSURE = 0x01 ,
  XENSIV_DPS3XX_MODE_COMMAND_TEMPERATURE = 0x02 ,
  XENSIV_DPS3XX_MODE_BACKGROUND_PRESSURE = 0x05 ,
  XENSIV_DPS3XX_MODE_BACKGROUND_TEMPERATURE = 0x06 ,
  XENSIV_DPS3XX_MODE_BACKGROUND_ALL = 0x07
}
 enum defining the different device operating modes More...
 
enum  xensiv_dps3xx_interrupt_t {
  XENSIV_DPS3XX_INT_NONE = 0x00 ,
  XENSIV_DPS3XX_INT_HL = 0x80 ,
  XENSIV_DPS3XX_INT_FIFO = 0x40 ,
  XENSIV_DPS3XX_INT_TMP = 0x20 ,
  XENSIV_DPS3XX_INT_PRS = 0x10
}
 Enum to enable/disable/report interrupt cause flags. More...
 
enum  xensiv_dps3xx_oversample_t {
  XENSIV_DPS3XX_OVERSAMPLE_1 = 0x00 ,
  XENSIV_DPS3XX_OVERSAMPLE_2 = 0x01 ,
  XENSIV_DPS3XX_OVERSAMPLE_4 = 0x02 ,
  XENSIV_DPS3XX_OVERSAMPLE_8 = 0x03 ,
  XENSIV_DPS3XX_OVERSAMPLE_16 = 0x04 ,
  XENSIV_DPS3XX_OVERSAMPLE_32 = 0x05 ,
  XENSIV_DPS3XX_OVERSAMPLE_64 = 0x06 ,
  XENSIV_DPS3XX_OVERSAMPLE_128 = 0x07
}
 Oversampling rates for both pressure and temperature measurements. More...
 
enum  xensiv_dps3xx_rate_t {
  XENSIV_DPS3XX_RATE_1 = 0x00 ,
  XENSIV_DPS3XX_RATE_2 = 0x10 ,
  XENSIV_DPS3XX_RATE_4 = 0x20 ,
  XENSIV_DPS3XX_RATE_8 = 0x30 ,
  XENSIV_DPS3XX_RATE_16 = 0x40 ,
  XENSIV_DPS3XX_RATE_32 = 0x50 ,
  XENSIV_DPS3XX_RATE_64 = 0x60 ,
  XENSIV_DPS3XX_RATE_128 = 0x70
}
 Measurement rates for both pressure and temperature measurements. More...
 

Functions

cy_rslt_t xensiv_dps3xx_init_i2c (xensiv_dps3xx_t *obj, const xensiv_dps3xx_i2c_comm_t *functions, xensiv_dps3xx_i2c_addr_t i2c_addr)
 Initialize the DPS sensor, and configures it to use the specified I2C peripheral. More...
 
cy_rslt_t xensiv_dps3xx_get_config (xensiv_dps3xx_t *obj, xensiv_dps3xx_config_t *config)
 Gets the current configuration parameters. More...
 
cy_rslt_t xensiv_dps3xx_set_config (xensiv_dps3xx_t *obj, xensiv_dps3xx_config_t *config)
 Sets the current configuration parameters for the sensor. More...
 
cy_rslt_t xensiv_dps3xx_get_revision_id (xensiv_dps3xx_t *obj, uint8_t *revision_id)
 Gets the sensor revision number. More...
 
cy_rslt_t xensiv_dps3xx_read (xensiv_dps3xx_t *obj, float *pressure, float *temperature)
 Gets the current pressure and temperature values from the sensor. More...
 
cy_rslt_t xensiv_dps3xx_check_ready (xensiv_dps3xx_t *obj, bool *pressure_ready, bool *temperature_ready)
 Gets whether the pressure sensor has new pressure/temperature data ready to be read. More...
 
void xensiv_dps3xx_free (xensiv_dps3xx_t *obj)
 Frees up any resources allocated by the motion_sensor as part of xensiv_dps3xx_init_i2c(). More...
 

Data Structure Documentation

◆ xensiv_dps3xx_config_t

struct xensiv_dps3xx_config_t
Data Fields
xensiv_dps3xx_mode_t dev_mode Operating mode of device.
xensiv_dps3xx_rate_t pressure_rate Pressure sensor measurement mode.
xensiv_dps3xx_rate_t temperature_rate Temperature sensor measurement mode.
xensiv_dps3xx_oversample_t pressure_oversample Pressure sensor oversample rate.
xensiv_dps3xx_oversample_t temperature_oversample Temperature sensor oversample rate.
xensiv_dps3xx_interrupt_t interrupt_triggers Signals that trigger an interrupt.
bool fifo_enable Should the FIFO buffer be enabled.
uint16_t data_timeout Millisecond timeout for measurements.
uint16_t i2c_timeout Millisecond timeout for I2C commands.

◆ xensiv_dps3xx_i2c_comm_t

struct xensiv_dps3xx_i2c_comm_t
Data Fields
xensiv_dps3xx_i2c_read_t read Function to read sensor registers over I2C.
xensiv_dps3xx_i2c_write_t write Function to write sensor registers over I2C.
xensiv_dps3xx_delay_t delay Function to delay while waiting for the sensor.
void * context Contextual data to provide to the read/write funcs.

◆ xensiv_dps3xx_t

struct xensiv_dps3xx_t
Data Fields
xensiv_dps3xx_i2c_comm_t comm sensor
xensiv_dps3xx_config_t user_config User configuration settings.
xensiv_dps3xx_i2c_addr_t i2c_address Sensor slave address.
float temp_scaled sensor
uint8_t meas_cfg sensor
_xensiv_dps3xx_scaling_coeffs_t tmp_osr_scale_coeff Temperature scaling coefficient.
_xensiv_dps3xx_scaling_coeffs_t prs_osr_scale_coeff Pressure scaling coefficient.
_xensiv_dps3xx_cal_coeff_regs_t calib_coeffs Calibration coefficients index.
_xensiv_dps3xx_temp_src_t tmp_ext Should always be set MEMS.

Enumeration Type Documentation

◆ xensiv_dps3xx_i2c_addr_t

Possible I2C addresses to communicate with the device.

Enumerator
XENSIV_DPS3XX_I2C_ADDR_DEFAULT 

Default I2C address (0x77)

XENSIV_DPS3XX_I2C_ADDR_ALT 

I2C address (0x76); if SDO pin is pulled to GND.

◆ xensiv_dps3xx_mode_t

enum defining the different device operating modes

Enumerator
XENSIV_DPS3XX_MODE_IDLE 

Idle mode value.

XENSIV_DPS3XX_MODE_COMMAND_PRESSURE 

Single shot pressure only.

After a single measurement the device will return to IDLE. Subsequent measurements must call xensiv_dps3xx_set_config to set the mode again.

XENSIV_DPS3XX_MODE_COMMAND_TEMPERATURE 

Single shot temperature only.

After a single measurement the device will return to IDLE. Subsequent measurements must call xensiv_dps3xx_set_config to set the mode again.

XENSIV_DPS3XX_MODE_BACKGROUND_PRESSURE 

Ongoing background pressure only.

XENSIV_DPS3XX_MODE_BACKGROUND_TEMPERATURE 

Ongoing background temperature only.

XENSIV_DPS3XX_MODE_BACKGROUND_ALL 

Ongoing background pressure and temp.

◆ xensiv_dps3xx_interrupt_t

Enum to enable/disable/report interrupt cause flags.

Enumerator
XENSIV_DPS3XX_INT_NONE 

No interrupt enabled.

XENSIV_DPS3XX_INT_HL 

Interrupt (on SDO pin) active level.

XENSIV_DPS3XX_INT_FIFO 

Interrupt when the FIFO is full.

XENSIV_DPS3XX_INT_TMP 

Interrupt when a temperature measurement is ready.

XENSIV_DPS3XX_INT_PRS 

Interrupt when a pressure measurement is ready.

◆ xensiv_dps3xx_oversample_t

Oversampling rates for both pressure and temperature measurements.

Enumerator
XENSIV_DPS3XX_OVERSAMPLE_1 

1x oversample rate

XENSIV_DPS3XX_OVERSAMPLE_2 

2x oversample rate

XENSIV_DPS3XX_OVERSAMPLE_4 

4x oversample rate

XENSIV_DPS3XX_OVERSAMPLE_8 

8x oversample rate

XENSIV_DPS3XX_OVERSAMPLE_16 

16x oversample rate

XENSIV_DPS3XX_OVERSAMPLE_32 

32x oversample rate

XENSIV_DPS3XX_OVERSAMPLE_64 

64x oversample rate

XENSIV_DPS3XX_OVERSAMPLE_128 

128x oversample rate

◆ xensiv_dps3xx_rate_t

Measurement rates for both pressure and temperature measurements.

Enumerator
XENSIV_DPS3XX_RATE_1 

Normal sample rate.

XENSIV_DPS3XX_RATE_2 

2x sample rate

XENSIV_DPS3XX_RATE_4 

4x sample rate

XENSIV_DPS3XX_RATE_8 

8x sample rate

XENSIV_DPS3XX_RATE_16 

16x sample rate

XENSIV_DPS3XX_RATE_32 

32x sample rate

XENSIV_DPS3XX_RATE_64 

64x sample rate

XENSIV_DPS3XX_RATE_128 

128x sample rate

Function Documentation

◆ xensiv_dps3xx_init_i2c()

cy_rslt_t xensiv_dps3xx_init_i2c ( xensiv_dps3xx_t obj,
const xensiv_dps3xx_i2c_comm_t functions,
xensiv_dps3xx_i2c_addr_t  i2c_addr 
)

Initialize the DPS sensor, and configures it to use the specified I2C peripheral.

By default it is configured in command mode.

Note
A ModusToolbox™ HAL based equivalent, xensiv_dps3xx_mtb_init_i2c(), is also available
Parameters
[out]objPointer to an pressure sensor object. The caller must allocate the memory for this object but the init function will initialize its contents.
[in]functionsStructure containing pointers to the I2C communication functions.
[in]i2c_addrI2C address to use when communicating with the sensor.
Returns
CY_RSLT_SUCCESS if properly initialized, else an error indicating what went wrong.

◆ xensiv_dps3xx_get_config()

cy_rslt_t xensiv_dps3xx_get_config ( xensiv_dps3xx_t obj,
xensiv_dps3xx_config_t config 
)

Gets the current configuration parameters.

Parameters
[in]objPointer to a pressure sensor object.
[out]configThe current configuration parameters from the device
Returns
CY_RSLT_SUCCESS if the config was obtained, else an error indicating what went wrong.

◆ xensiv_dps3xx_set_config()

cy_rslt_t xensiv_dps3xx_set_config ( xensiv_dps3xx_t obj,
xensiv_dps3xx_config_t config 
)

Sets the current configuration parameters for the sensor.

Note
If switching to a pressure only mode, at least one measurement should be done with temperature data enabled to setup calibration parameters.
Parameters
[in]objPointer to a pressure sensor object.
[out]configThe new configuration parameters to apply
Returns
CY_RSLT_SUCCESS if the config was set, else an error indicating what went wrong.

◆ xensiv_dps3xx_get_revision_id()

cy_rslt_t xensiv_dps3xx_get_revision_id ( xensiv_dps3xx_t obj,
uint8_t *  revision_id 
)

Gets the sensor revision number.

Parameters
[in]objPointer to a pressure sensor object.
[out]revision_idPointer to populate with the revision id
Returns
CY_RSLT_SUCCESS if the revision was obtained, else an error indicating what went wrong.

◆ xensiv_dps3xx_read()

cy_rslt_t xensiv_dps3xx_read ( xensiv_dps3xx_t obj,
float *  pressure,
float *  temperature 
)

Gets the current pressure and temperature values from the sensor.

Parameters
[in]objPointer to a pressure sensor object.
[out]pressurePointer to populate with the pressure data, may be NULL
[out]temperaturePointer to populate with the temperature data, may be NULL
Returns
CY_RSLT_SUCCESS if the data was obtained, else an error indicating what went wrong.

◆ xensiv_dps3xx_check_ready()

cy_rslt_t xensiv_dps3xx_check_ready ( xensiv_dps3xx_t obj,
bool *  pressure_ready,
bool *  temperature_ready 
)

Gets whether the pressure sensor has new pressure/temperature data ready to be read.

Parameters
[in]objPointer to a pressure sensor object.
[out]pressure_readyIndication whether the pressure data is ready to be read
[out]temperature_readyIndication whether the temperature data is ready to be read
Returns
CY_RSLT_SUCCESS if the check succeeded, else an error indicating what went wrong.

◆ xensiv_dps3xx_free()

void xensiv_dps3xx_free ( xensiv_dps3xx_t obj)

Frees up any resources allocated by the motion_sensor as part of xensiv_dps3xx_init_i2c().

Parameters
[in]objPointer to the pressure sensor object to free.