|
F439_CPP_BMP390_Barometric_Pressure_and_Altimeter_01 1.0
STM32F439 BMP390 barometric pressure and altimeter tutorial
|
: Main program body More...
#include "main.h"#include <math.h>#include <stdio.h>#include "bmp3.h"#include "common.h"#include "i2c_spi_interface.h"Go to the source code of this file.
Macros | |
| #define | LOCAL_QNH_CALIBRATION |
| Define to reference altitude against today's actual local sea-level pressure instead of the standard atmosphere. | |
| #define | SEA_LEVEL_PRESSURE_PA 102057.7 |
| Sea-level pressure (Pa) used as the altitude reference. | |
Functions | |
| void | SystemClock_Config (void) |
| System Clock Configuration. | |
| static void | MX_GPIO_Init (void) |
| GPIO Initialization Function. | |
| static void | MX_USART1_UART_Init (void) |
| USART1 Initialization Function. | |
| static void | MX_I2C1_Init (void) |
| I2C1 Initialization Function. | |
| static void | MX_TIM1_Init (void) |
| TIM1 Initialization Function. | |
| void | delayUS (uint16_t us) |
| Busy-waits for the given number of microseconds using TIM1 (1 MHz counter – see MX_TIM1_Init()'s prescaler). | |
| static double | calculateAltitudeFt (double pressurePa) |
| Converts pressure to altitude using the barometric formula (International Standard Atmosphere model), referenced against SEA_LEVEL_PRESSURE_PA. | |
| int | main (void) |
| The application entry point. | |
| void | _Error_Handler (const char *file, int line) |
| Reports a fatal error and halts. See _Error_Handler() in main.c. | |
Variables | |
| I2C_HandleTypeDef | hi2c1 |
| I2C1 handle, used by the BMP390 driver's read/write callbacks. | |
| TIM_HandleTypeDef | htim1 |
| TIM1 handle, used as delayUS()'s free-running microsecond counter. | |
| UART_HandleTypeDef | huart1 |
| USART1 handle, used for printf() output via REDIRECT_PRINTF. | |
| static I2C_SPI_Interface | bmp390Intf |
| I2C bus/address binding passed to the BMP390 driver as intf_ptr. | |
| static struct bmp3_dev | bmp390 |
| BMP390 driver device handle (Bosch bmp3_dev). | |
: Main program body
Copyright (c) 2026 STMicroelectronics. All rights reserved.
This software is licensed under terms that can be found in the LICENSE file in the root directory of this software component. If no LICENSE file comes with this software, it is provided AS-IS.
Definition in file main.c.
| #define LOCAL_QNH_CALIBRATION |
Define to reference altitude against today's actual local sea-level pressure instead of the standard atmosphere.
This value was derived from a known 600 ft reference elevation and this sensor's readings on 2026-07-09 – it drifts with the weather, so it will need re-deriving the same way to stay accurate later.
| #define SEA_LEVEL_PRESSURE_PA 102057.7 |
Sea-level pressure (Pa) used as the altitude reference.
Definition at line 53 of file main.c.
Referenced by calculateAltitudeFt().
| void _Error_Handler | ( | const char * | file, |
| int | line ) |
Reports a fatal error and halts. See _Error_Handler() in main.c.
| file | Source file name where the error occurred. |
| line | Source line number where the error occurred. |
|
static |
Converts pressure to altitude using the barometric formula (International Standard Atmosphere model), referenced against SEA_LEVEL_PRESSURE_PA.
| pressurePa | Measured pressure in Pa. |
Definition at line 122 of file main.c.
References SEA_LEVEL_PRESSURE_PA.
Referenced by main().
| void delayUS | ( | uint16_t | us | ) |
Busy-waits for the given number of microseconds using TIM1 (1 MHz counter – see MX_TIM1_Init()'s prescaler).
| us | Number of microseconds to wait (0-65535). |
Definition at line 109 of file main.c.
References htim1.
| int main | ( | void | ) |
The application entry point.
| int |
Definition at line 134 of file main.c.
References bmp390, bmp390Intf, calculateAltitudeFt(), hi2c1, htim1, MX_GPIO_Init(), MX_I2C1_Init(), MX_TIM1_Init(), MX_USART1_UART_Init(), and SystemClock_Config().
|
static |
|
static |
I2C1 Initialization Function.
Configure Analogue filter
Configure Digital filter
Definition at line 302 of file main.c.
References Error_Handler, and hi2c1.
Referenced by main().
|
static |
TIM1 Initialization Function.
Definition at line 348 of file main.c.
References Error_Handler, and htim1.
Referenced by main().
|
static |
USART1 Initialization Function.
Definition at line 392 of file main.c.
References Error_Handler, and huart1.
Referenced by main().
| void SystemClock_Config | ( | void | ) |
System Clock Configuration.
Configure the main internal regulator output voltage
Initializes the RCC Oscillators according to the specified parameters in the RCC_OscInitTypeDef structure.
Activate the Over-Drive mode
Initializes the CPU, AHB and APB buses clocks
Definition at line 250 of file main.c.
References Error_Handler.
Referenced by main().
|
static |
|
static |
| I2C_HandleTypeDef hi2c1 |
I2C1 handle, used by the BMP390 driver's read/write callbacks.
Definition at line 68 of file main.c.
Referenced by main(), and MX_I2C1_Init().
| TIM_HandleTypeDef htim1 |
| UART_HandleTypeDef huart1 |
USART1 handle, used for printf() output via REDIRECT_PRINTF.
Definition at line 74 of file main.c.
Referenced by MX_USART1_UART_Init().