|
| 1 | +#include "I3C.h" |
| 2 | +#include "LPS22DFSensor.h" |
| 3 | + |
| 4 | +#define I3C_BUS I3C1Bus |
| 5 | + |
| 6 | +LPS22DFSensor sensor(&I3C_BUS, 0x00); |
| 7 | + |
| 8 | +void setup() { |
| 9 | + Serial.begin(115200); |
| 10 | + while (!Serial) {} |
| 11 | + delay(1000); |
| 12 | + |
| 13 | + Serial.println("=== LPS22DF DAA ==="); |
| 14 | + |
| 15 | + if (!I3C_BUS.begin(I3C_SDA, I3C_SCL, 1000000U)) { |
| 16 | + Serial.println("begin() failed"); |
| 17 | + while (1) {} |
| 18 | + } |
| 19 | + |
| 20 | + I3CDiscoveredDevice devices[8]{}; |
| 21 | + size_t found = 0; |
| 22 | + |
| 23 | + if (I3C_BUS.discover(devices, 8, &found)) { |
| 24 | + Serial.println("discover() failed"); |
| 25 | + while (1) {} |
| 26 | + } |
| 27 | + |
| 28 | + uint8_t lpsDynAddr = 0U; |
| 29 | + |
| 30 | + for (size_t i = 0; i < found; ++i) { |
| 31 | + Serial.println(devices[i].pid,HEX); |
| 32 | + if (devices[i].pid == LPS22DF_I3C_PID_H) { |
| 33 | + lpsDynAddr = devices[i].dynAddr; |
| 34 | + break; |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + sensor.set_address(lpsDynAddr); |
| 39 | + |
| 40 | + if (lpsDynAddr == 0U) { |
| 41 | + Serial.println("Sensor not found failed"); |
| 42 | + while (1) {} |
| 43 | + } |
| 44 | + |
| 45 | + if (sensor.begin() != LPS22DF_OK) { |
| 46 | + Serial.println("sensor.begin() failed"); |
| 47 | + while (1) {} |
| 48 | + } |
| 49 | + |
| 50 | + if (sensor.Enable() != LPS22DF_OK) { |
| 51 | + Serial.println("sensor.Enable() failed"); |
| 52 | + while (1) {} |
| 53 | + } |
| 54 | + |
| 55 | + Serial.println("LPS22DF ready"); |
| 56 | +} |
| 57 | + |
| 58 | +void loop() { |
| 59 | + float p = 0.0f; |
| 60 | + float t = 0.0f; |
| 61 | + |
| 62 | + if (sensor.GetPressure(&p) == LPS22DF_OK && sensor.GetTemperature(&t) == LPS22DF_OK) { |
| 63 | + Serial.print("P = "); |
| 64 | + Serial.print(p, 2); |
| 65 | + Serial.print(" hPa T = "); |
| 66 | + Serial.print(t, 1); |
| 67 | + Serial.println(" C"); |
| 68 | + } else { |
| 69 | + Serial.println("Read failed"); |
| 70 | + } |
| 71 | + |
| 72 | + delay(500); |
| 73 | +} |
0 commit comments