Envorimental Monitoring
Loading...
Searching...
No Matches
i2c_core.c File Reference

Sensor-agnostic I2C read abstraction implementation. More...

#include "i2c_core.h"

Functions

float i2c_sensor_read (uint8_t device_address, sensor_t sensor_type, void *p_handle)
 Reads a single measurement from the specified I2C sensor.
uint8_t I2C_ScanDeviceAddress (I2C_HandleTypeDef *hi2c)
 Scans the I2C bus for the first responding device.

Detailed Description

Sensor-agnostic I2C read abstraction implementation.

Author
Şule Nur Demirdaş
Date
April 2026

Function Documentation

◆ I2C_ScanDeviceAddress()

uint8_t I2C_ScanDeviceAddress ( I2C_HandleTypeDef * hi2c)

Scans the I2C bus for the first responding device.

Iterates through all 128 possible 7-bit addresses and returns the first one that acknowledges HAL_I2C_IsDeviceReady(). Intended as a diagnostic helper during hardware bring-up.

Parameters
[in]hi2cPointer to the initialised I2C peripheral handle.
Returns
7-bit address (0x00–0x7F) of the first responding device, or 0xFF if no device is found.

◆ i2c_sensor_read()

float i2c_sensor_read ( uint8_t device_address,
sensor_t sensor_type,
void * p_handle )

Reads a single measurement from the specified I2C sensor.

The function triggers a sensor read via the appropriate driver, then returns the requested physical quantity as a float. On error -1.0f is returned.

Parameters
[in]device_address8-bit I2C address of the target device (left-shifted by 1 as required by HAL).
[in]sensor_typeThe physical quantity to retrieve; must match the sensor pointed to by p_handle.
[in]p_handleVoid pointer to the sensor driver handle (AHT20_HandleTypeDef*, BMP180_HandleTypeDef*, or BH1750_HandleTypeDef*).
Returns
Measured value as a float, or -1.0f on failure.