Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/Continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ jobs:
id: compile
uses: stm32duino/actions/compile-examples@main
with:
board-pattern: "NUCLEO_L476RG"

custom-config: "./extras/build_config.json"
board-pattern: "NUCLEO_L476RG|NUCLEO_H503RB"
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
# Use the output from the `Compilation` step
- name: Compilation Errors
if: failure()
Expand Down
31 changes: 31 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# v3.21 implemented semantic changes regarding $<TARGET_OBJECTS:...>
# See https://cmake.org/cmake/help/v3.21/command/target_link_libraries.html#linking-object-libraries-via-target-objects
cmake_minimum_required(VERSION 3.21)

add_library(LPS22DF INTERFACE)
add_library(LPS22DF_usage INTERFACE)

target_include_directories(LPS22DF_usage INTERFACE
src
)


target_link_libraries(LPS22DF_usage INTERFACE
base_config
)

target_link_libraries(LPS22DF INTERFACE LPS22DF_usage)



add_library(LPS22DF_bin OBJECT EXCLUDE_FROM_ALL
src/lps22df_reg.c
src/LPS22DFSensor.cpp
)
target_link_libraries(LPS22DF_bin PUBLIC LPS22DF_usage)

target_link_libraries(LPS22DF INTERFACE
LPS22DF_bin
$<TARGET_OBJECTS:LPS22DF_bin>
)

22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Arduino library to support the LPS22DF 260-1260 hPa absolute digital output baro

## API

This sensor uses I2C or SPI to communicate.
This sensor uses I2C, SPI or I3C to communicate.
For I2C it is then required to create a TwoWire interface before accessing to the sensors:

TwoWire dev_i2c(I2C_SDA, I2C_SCL);
Expand All @@ -27,6 +27,26 @@ An instance can be created and enabled when the SPI bus is used following the pr
PressTemp.begin();
PressTemp.Enable();

An instance can be created and enabled when the I3C bus is used with SETDASA (static-to-dynamic address assignment):

LPS22DFSensor PressTemp(&I3C, LPS22DF_I3C_ADD_H);
I3C.begin(I3C_SDA, I3C_SCL, 1000000U);
I3C.resetDynamicAddresses();
I3C.assignDynamicAddress(PressTemp.getStaticAddress(), LPS22DF_DYNAMIC_ADDRESS);
PressTemp.begin(LPS22DF_DYNAMIC_ADDRESS);
I3C.setClock(12500000);
PressTemp.Enable();

An instance can be created and enabled when the I3C bus is used with ENTDAA (dynamic address discovery):

LPS22DFSensor PressTemp(&I3C);
I3C.begin(I3C_SDA, I3C_SCL, 1000000U);
I3C.discover(devices, 8, &found);
// find dynAddr by matching LPS22DF_I3C_PID_H in discovered devices
PressTemp.begin(dynAddr);
I3C.setClock(12500000);
PressTemp.Enable();

The access to the sensor values is done as explained below:

Read pressure and temperature.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
@file LPS22DF_DataLog_Terminal.ino
@file LPS22DF_DataLog_Terminal_I2C.ino
@author Giuseppe Roberti <giuseppe.roberti@ieee.org>
@brief Example to use the LPS22DF 260-1260 hPa absolute digital
output barometer
output barometer with I2C bus
*******************************************************************************
Copyright (c) 2022, STMicroelectronics
All rights reserved.
Expand All @@ -15,18 +15,21 @@

#include <LPS22DFSensor.h>

LPS22DFSensor sensor (&Wire);
LPS22DFSensor sensor(&Wire);
float pressure, temperature;

void setup() {
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
Wire.begin();
sensor.begin();
sensor.Enable();
Serial.println("LPS22DF ready");
}

void loop() {
void loop()
{
sensor.GetPressure(&pressure);
sensor.GetTemperature(&temperature);

Expand All @@ -38,7 +41,8 @@ void loop() {
blink(LED_BUILTIN);
}

inline void blink(int pin) {
inline void blink(int pin)
{
digitalWrite(pin, HIGH);
delay(25);
digitalWrite(pin, LOW);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
@file LPS22DF_DataLog_Terminal_I3C.ino
@author STMicroelectronics
@brief Example to use the LPS22DF pressure sensor with I3C and SETDASA command
*******************************************************************************
Copyright (c) 2026, STMicroelectronics
All rights reserved.

This software component is licensed by ST under BSD 3-Clause license,
the "License"; You may not use this file except in compliance with the
License. You may obtain a copy of the License at:
opensource.org/licenses/BSD-3-Clause

*******************************************************************************
*/
#include "LPS22DFSensor.h"

#define LPS22DF_DYNAMIC_ADDRESS 0x30

LPS22DFSensor sensor(&I3C, LPS22DF_I3C_ADD_H);

void setup()
{
Serial.begin(115200);
while (!Serial) {}
delay(1000);

Serial.println("=== LPS22DF SETDASA ===");

if (!I3C.begin(I3C_SDA, I3C_SCL, 1000000U)) {
Serial.println("begin() failed");
while (1) {}
}

if (!I3C.resetDynamicAddresses()) {
Serial.println("resetDynamicAddresses() failed");
while (1) {}
}

if (!I3C.assignDynamicAddress(sensor.getStaticAddress(), LPS22DF_DYNAMIC_ADDRESS)) {
Serial.println("assignDynamicAddress() failed");
while (1) {}
}

if (sensor.begin(LPS22DF_DYNAMIC_ADDRESS) != LPS22DF_OK) {
Serial.println("sensor.begin() failed");
while (1) {}
}

if (!I3C.setClock(12500000)) {
Serial.println("setClock() failed");
while (1) {}
}

if (sensor.Enable() != LPS22DF_OK) {
Serial.println("sensor.Enable() failed");
while (1) {}
}

Serial.println("LPS22DF ready");
}

void loop()
{
float pressure = 0.0f;
float temperature = 0.0f;

if (sensor.GetPressure(&pressure) == LPS22DF_OK && sensor.GetTemperature(&temperature) == LPS22DF_OK) {
Serial.print("Pressure[hPa]:");
Serial.print(pressure, 2);
Serial.print(", Temperature[C]:");
Serial.println(temperature, 2);
} else {
Serial.println("Read failed");
}

delay(500);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
@file LPS22DF_DataLog_Terminal_I3C_ENTDAA.ino
@author STMicroelectronics
@brief Example to use the LPS22DF pressure sensor with I3C dynamic address assignment
*******************************************************************************
Copyright (c) 2026, STMicroelectronics
All rights reserved.

This software component is licensed by ST under BSD 3-Clause license,
the "License"; You may not use this file except in compliance with the
License. You may obtain a copy of the License at:
opensource.org/licenses/BSD-3-Clause

*******************************************************************************
*/

#include "LPS22DFSensor.h"

LPS22DFSensor sensor(&I3C);

void setup()
{
Serial.begin(115200);
while (!Serial) {}
delay(1000);

Serial.println("=== LPS22DF DAA ===");

if (!I3C.begin(I3C_SDA, I3C_SCL, 1000000U)) {
Serial.println("begin() failed");
while (1) {}
}

if (!I3C.resetDynamicAddresses()) {
Serial.println("resetDynamicAddresses() failed");
while (1) {}
}

I3CDiscoveredDevice devices[8] {};
size_t found = 0;

if (I3C.discover(devices, 8, &found)) {
Serial.println("discover() failed");
while (1) {}
}

uint8_t lpsDynAddr = 0U;

for (size_t i = 0; i < found; ++i) {
Serial.println(devices[i].pid, HEX);
if (devices[i].pid == LPS22DF_I3C_PID_H) {
lpsDynAddr = devices[i].dynAddr;
Serial.print("lpsDynAddr=");
Serial.println(lpsDynAddr, HEX);
break;
}
}

if (lpsDynAddr == 0U) {
Serial.println("Sensor not found");
while (1) {}
}

if (sensor.begin(lpsDynAddr) != LPS22DF_OK) {
Serial.println("sensor.begin() failed");
while (1) {}
}

if (!I3C.setClock(12500000)) {
Serial.println("setClock() failed");
while (1) {}
}

if (sensor.Enable() != LPS22DF_OK) {
Serial.println("sensor.Enable() failed");
while (1) {}
}

Serial.println("LPS22DF ready");
}

void loop()
{
float pressure = 0.0f;
float temperature = 0.0f;

if (sensor.GetPressure(&pressure) == LPS22DF_OK && sensor.GetTemperature(&temperature) == LPS22DF_OK) {
Serial.print("Pressure[hPa]:");
Serial.print(pressure, 2);
Serial.print(", Temperature[C]:");
Serial.println(temperature, 2);
} else {
Serial.println("Read failed");
}

delay(500);
}
25 changes: 25 additions & 0 deletions extras/build_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"cores": [
{
"maintainer": "STMicroelectronics",
"architecture": "stm32",
"boards": [
],
"sketches": [
{
"pattern": "[^I][^3][^C]",
"applicable": true,
"boards": [
"NUCLEO_L476RG",
"NUCLEO_H503RB"
]
},
{
"pattern": "I3C",
"applicable": true,
"boards": [ "NUCLEO_H503RB"]
}
]
}
]
}
1 change: 1 addition & 0 deletions extras/codespell-ignore-words-list.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
daa
ths
10 changes: 10 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,20 @@ Read_Reg KEYWORD2
Write_Reg KEYWORD2
Set_One_Shot KEYWORD2
Get_One_Shot_Status KEYWORD2
getStaticAddress KEYWORD2
getDynAddress KEYWORD2

#######################################
# Constants (LITERAL1)
#######################################

LPS22DF_OK LITERAL1
LPS22DF_ERROR LITERAL1
LPS22DF_I2C_BUS LITERAL1
LPS22DF_SPI_4WIRES_BUS LITERAL1
LPS22DF_SPI_3WIRES_BUS LITERAL1
LPS22DF_I3C_BUS LITERAL1
LPS22DF_I3C_ADD_L LITERAL1
LPS22DF_I3C_ADD_H LITERAL1
LPS22DF_I3C_PID_L LITERAL1
LPS22DF_I3C_PID_H LITERAL1
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=STM32duino LPS22DF
version=1.0.4
version=1.1.0
author=SRA
maintainer=stm32duino
sentence=Nano pressure sensor.
Expand Down
Loading