1
0
This repository has been archived on 2025-11-01. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
2025-10-10 02:20:31 +02:00

25 lines
466 B
C
Executable File

#include "stm32l4xx_hal.h"
extern I2C_HandleTypeDef hi2c2;
void LPS22_Init() {
uint8_t buffer[1];
buffer[0] = 0x42;
HAL_I2C_Mem_Write(&hi2c2, 0xBA, 0x10, I2C_MEMADD_SIZE_8BIT, buffer, 1 , 1000);
}
float LPS22_ReadPress() {
float press;
uint8_t buffer[3];
HAL_I2C_Mem_Read(&hi2c2, 0xBA, 0x28, I2C_MEMADD_SIZE_8BIT, buffer, 3, 1000);
uint32_t press_raw = (buffer[2] << 16) | (buffer[1] << 8) | buffer[0];
press = press_raw / 4096.0f;
return press;
}