F439_CPP_MPL3115A2_Project_01
STM32F439 MPL3115A2 pressure and temperature tutorial
Loading...
Searching...
No Matches
Functions | Variables

MPL3115A2 pressure and temperature sensor driver implementation. More...

#include "mpl31152a.h"

Functions

HAL_StatusTypeDef MPL31152A_Init (I2C_HandleTypeDef *hi2c, uint16_t devAddress)
 Initialize and configure the MPL3115A2 sensor.
 
HAL_StatusTypeDef MPL31152A_getStatus (uint8_t *retVal)
 Read the MPL3115A2 STATUS register.
 
HAL_StatusTypeDef MPL3115A2_ReadTemperature (float *celsius)
 Read and convert the MPL3115A2 temperature measurement.
 
HAL_StatusTypeDef MPL3115A2_ReadPressure (float *pressure_inHg)
 Read and convert the MPL3115A2 pressure measurement.
 

Variables

static I2C_HandleTypeDef * i2c
 HAL I2C handle used for all MPL3115A2 transactions.
 
static uint16_t devAddr
 STM32 HAL-formatted MPL3115A2 I2C address.
 

Detailed Description

MPL3115A2 pressure and temperature sensor driver implementation.

The driver is intentionally small for tutorial use. It stores one global I2C handle and device address, initializes the sensor for barometer operation, and exposes blocking read helpers for temperature and pressure.

Function Documentation

◆ MPL31152A_getStatus()

HAL_StatusTypeDef MPL31152A_getStatus ( uint8_t * retVal)

Read the MPL3115A2 STATUS register.

Parameters
retValPointer that receives the raw STATUS register value.
Returns
HAL_OK when the I2C register read succeeds, otherwise the HAL error status.

◆ MPL31152A_Init()

HAL_StatusTypeDef MPL31152A_Init ( I2C_HandleTypeDef * hi2c,
uint16_t devAddress )

Initialize and configure the MPL3115A2 sensor.

Initialize the MPL3115A2 sensor for barometer and temperature reads.

Stores the I2C handle and device address, waits for the sensor to answer, verifies WHO_AM_I, enables pressure and temperature data-ready flags, and places the device into active barometer mode with OSR=128.

Parameters
hi2cPointer to the STM32 HAL I2C handle connected to the sensor.
devAddressSTM32 HAL-formatted I2C device address.
Returns
HAL_OK when initialization completes. Initialization errors call Error_Handler() in this tutorial application.

◆ MPL3115A2_ReadPressure()

HAL_StatusTypeDef MPL3115A2_ReadPressure ( float * pressure_inHg)

Read and convert the MPL3115A2 pressure measurement.

Read pressure from the MPL3115A2.

Reads the three pressure output registers, converts the Q18.2 pressure value from pascals, and returns the result in inches of mercury.

Parameters
pressure_inHgPointer that receives the converted pressure in inHg.
Returns
HAL_OK when the I2C register read succeeds, otherwise the HAL error status.

◆ MPL3115A2_ReadTemperature()

HAL_StatusTypeDef MPL3115A2_ReadTemperature ( float * celsius)

Read and convert the MPL3115A2 temperature measurement.

Read temperature from the MPL3115A2.

Reads the two temperature output registers and converts the signed 12-bit fixed-point value into degrees Celsius.

Parameters
celsiusPointer that receives the converted temperature in degrees Celsius.
Returns
HAL_OK when the I2C register read succeeds, otherwise the HAL error status.