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

Public interface for the MPL3115A2 pressure and temperature sensor driver. More...

#include <main.h>

Go to the source code of this file.

Macros

#define MPL3115A2_ADDRESS   (0x60 << 1)
 Default 7-bit MPL3115A2 I2C address shifted for STM32 HAL use.
 

Enumerations

MPL3115A2 output and configuration registers
enum  {
  MPL3115A2_REGISTER_STATUS = (0x00) , MPL3115A2_REGISTER_PRESSURE_MSB = (0x01) , MPL3115A2_REGISTER_PRESSURE_CSB = (0x02) , MPL3115A2_REGISTER_PRESSURE_LSB = (0x03) ,
  MPL3115A2_REGISTER_TEMP_MSB = (0x04) , MPL3115A2_REGISTER_TEMP_LSB = (0x05) , MPL3115A2_WHOAMI = (0x0C)
}
 
MPL3115A2 status register bits
enum  { MPL3115A2_REGISTER_STATUS_TDR = 0x02 , MPL3115A2_REGISTER_STATUS_PTDR = 0x08 }
 
MPL3115A2 PT_DATA_CFG register values
enum  { MPL3115A2_PT_DATA_CFG = 0x13 , MPL3115A2_PT_DATA_CFG_TDEFE = 0x01 , MPL3115A2_PT_DATA_CFG_PDEFE = 0x02 , MPL3115A2_PT_DATA_CFG_DREM = 0x04 }
 
MPL3115A2 control registers
enum  { MPL3115A2_CTRL_REG1 = (0x26) }
 
MPL3115A2 CTRL_REG1 bit masks
enum  { MPL3115A2_CTRL_REG1_SBYB = 0x01 }
 
MPL3115A2 oversampling values for CTRL_REG1
enum  { MPL3115A2_CTRL_REG1_OS128 = 0x38 }
 

Functions

HAL_StatusTypeDef MPL31152A_Init (I2C_HandleTypeDef *hi2c, uint16_t devAddr)
 Initialize the MPL3115A2 sensor for barometer and temperature reads.
 
HAL_StatusTypeDef MPL31152A_getStatus (uint8_t *data)
 Read the MPL3115A2 STATUS register.
 
HAL_StatusTypeDef MPL3115A2_ReadPressure (float *pressure_inHg)
 Read pressure from the MPL3115A2.
 
HAL_StatusTypeDef MPL3115A2_ReadTemperature (float *celsius)
 Read temperature from the MPL3115A2.
 

Detailed Description

Public interface for the MPL3115A2 pressure and temperature sensor driver.

This driver uses STM32 HAL I2C calls to initialize the MPL3115A2 sensor, read the sensor status register, and return pressure and temperature measurements in application-friendly floating-point units.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
MPL3115A2_REGISTER_STATUS_TDR 

Temperature data ready.

MPL3115A2_REGISTER_STATUS_PTDR 

Pressure/altitude and temperature data ready.

◆ anonymous enum

anonymous enum
Enumerator
MPL3115A2_PT_DATA_CFG_TDEFE 

Enable temperature data-ready event flag.

MPL3115A2_PT_DATA_CFG_PDEFE 

Enable pressure/altitude data-ready event flag.

MPL3115A2_PT_DATA_CFG_DREM 

Data-ready event flag latch enable.

◆ anonymous enum

anonymous enum
Enumerator
MPL3115A2_CTRL_REG1_SBYB 

Active mode when set, standby mode when clear.

◆ anonymous enum

anonymous enum
Enumerator
MPL3115A2_CTRL_REG1_OS128 

Oversampling ratio used by this tutorial.

Function Documentation

◆ MPL31152A_getStatus()

HAL_StatusTypeDef MPL31152A_getStatus ( uint8_t * retVal)

Read the MPL3115A2 STATUS register.

Parameters
dataPointer that receives the raw status register value.
Returns
HAL_OK when the register read succeeds, otherwise the HAL error status.
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 the MPL3115A2 sensor for barometer and temperature reads.

The function stores the HAL I2C handle for later driver calls, waits until the sensor responds on the I2C bus, validates the WHO_AM_I value, enables data-ready event flags, and activates the sensor with OSR=128.

Parameters
hi2cPointer to the STM32 HAL I2C handle used by the sensor.
devAddrSTM32 HAL-formatted I2C device address.
Returns
HAL_OK when initialization succeeds, otherwise the HAL error status.

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 pressure from the MPL3115A2.

Parameters
pressure_inHgPointer that receives pressure in inches of mercury.
Returns
HAL_OK when the pressure read succeeds, otherwise the HAL error status.

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 temperature from the MPL3115A2.

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

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.