|
F439_CPP_MPL3115A2_Project_01 1.0
STM32F439 MPL3115A2 pressure and temperature tutorial
|
MPL3115A2 pressure and temperature sensor driver implementation. More...
#include "mpl3115a2.h"Go to the source code of this file.
Functions | |
| HAL_StatusTypeDef | MPL3115A2_Init (I2C_HandleTypeDef *hi2c, uint16_t devAddress) |
| Initialize and configure the MPL3115A2 sensor. | |
| HAL_StatusTypeDef | MPL3115A2_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. | |
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.
Definition in file mpl3115a2.c.
| HAL_StatusTypeDef MPL3115A2_GetStatus | ( | uint8_t * | retVal | ) |
Read the MPL3115A2 STATUS register.
| retVal | Pointer that receives the raw STATUS register value. |
Definition at line 99 of file mpl3115a2.c.
Referenced by main().
| HAL_StatusTypeDef MPL3115A2_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, then blocks until the sensor acknowledges on the bus, retrying through reset_I2C() on each failed probe. Once the device responds, verifies WHO_AM_I, places the sensor in standby, enables the pressure and temperature data-ready event flags, and returns it to active barometer mode with OSR=128.
The bus-probe phase does not return on failure; it retries indefinitely until the sensor answers. A WHO_AM_I mismatch is treated as a fatal hardware fault and invokes Error_Handler() (which does not return). After the identity check, the first failing configuration transaction stops setup and is reported through the return value.
| hi2c | Pointer to the STM32 HAL I2C handle connected to the sensor. |
| devAddress | STM32 HAL-formatted (left-shifted) I2C device address. |
Definition at line 40 of file mpl3115a2.c.
References devAddr, Error_Handler(), i2c, and reset_I2C().
Referenced by main().
| 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 to pascals, and returns the result in inches of mercury.
| pressure_inHg | Pointer that receives the converted pressure in inHg. On an I2C read failure it is set to the sentinel value -99.99f. |
Definition at line 156 of file mpl3115a2.c.
Referenced by main().
| HAL_StatusTypeDef MPL3115A2_ReadTemperature | ( | float * | celsius | ) |
Read and convert the MPL3115A2 temperature measurement.
Read temperature from the MPL3115A2.
Reads OUT_T_MSB and OUT_T_LSB, which together form a signed Q8.4 fixed-point value (1/256 C per LSB of the register pair), and converts it to degrees Celsius. The signed cast preserves the full measurement range, including sub-zero temperatures.
| celsius | Pointer that receives the converted temperature in degrees Celsius. On an I2C read failure it is set to the sentinel value -99.99f. |
Definition at line 125 of file mpl3115a2.c.
Referenced by main().
|
static |
STM32 HAL-formatted MPL3115A2 I2C address.
Definition at line 17 of file mpl3115a2.c.
Referenced by MPL3115A2_GetStatus(), MPL3115A2_Init(), MPL3115A2_ReadPressure(), and MPL3115A2_ReadTemperature().
|
static |
HAL I2C handle used for all MPL3115A2 transactions.
Definition at line 14 of file mpl3115a2.c.
Referenced by MPL3115A2_GetStatus(), MPL3115A2_Init(), MPL3115A2_ReadPressure(), and MPL3115A2_ReadTemperature().