Files
DS_INA226/Inc/DS_INA226.h
2025-05-02 23:40:54 +03:00

99 lines
2.3 KiB
C

#ifndef DS_INA226_H
#define DS_INA226_H
#include <stdbool.h>
#ifdef STM32G030xx
#include "stm32g0xx_hal.h"
#endif
#ifdef STM32F030xx
#include "stm32f0xx_hal.h"
#endif
#ifdef STM32F103xB
#include "stm32f1xx_hal.h"
#endif
typedef struct DS_INA226
{
uint8_t DevAddr;
I2C_HandleTypeDef *hi2c;
uint16_t SensorData[9];
float Current_LSB;
uint8_t ShuntResistance; //mOhm
}DS_INA226;
void DS_INA226_Init(DS_INA226 *DS_INA226, I2C_HandleTypeDef *hi2c, uint8_t DevAddr);
/// @brief Sets the number of samples that will be collected and averaged together
/// 0 - 1
/// 1 - 4
/// 2 - 16
/// 3 - 64
/// 4 - 128
/// 5 - 256
/// 6 - 512
/// 7 - 1024
/// @param DS_INA226 struct DS_INA226
/// @param AveragingMode 0-7
void _DS_INA226_SetAveragingMode(DS_INA226 *DS_INA226, uint8_t AveragingMode);
/// @brief Sets the conversion time for the bus voltage measurement
/// 0 - 140μs
/// 1 - 204μs
/// 2 - 332μs
/// 3 - 588μs
/// 4 - 1.1ms
/// 5 - 2.116ms
/// 6 - 4.156ms
/// 7 - 8.244ms
///
/// @param DS_INA226 struct DS_INA226
/// @param ConversionTime 0-7
void _DS_INA226_SetBusVoltageConversionTime(DS_INA226 *DS_INA226, uint8_t ConversionTime);
/// @brief Sets the conversion time for the shunt voltage measurement
/// 0 - 140μs
/// 1 - 204μs
/// 2 - 332μs
/// 3 - 588μs
/// 4 - 1.1ms
/// 5 - 2.116ms
/// 6 - 4.156ms
/// 7 - 8.244ms
///
/// @param DS_INA226 struct DS_INA226
/// @param ConversionTime 0-7
void _DS_INA226_SetShuntVoltageConversionTime(DS_INA226 *DS_INA226, uint8_t ConversionTime);
/// @brief Selects continuous, triggered, or power-down mode of operation
/// 0 - Power-Down
/// 1 - Shunt Voltage, Triggered
/// 2 - Bus Voltage, Triggered
/// 3 - Shunt and Bus, Triggered
/// 4 - Power-Down
/// 5 - Shunt Voltage, Continuous
/// 6 - Bus Voltage, Continuous
/// 7 - Shunt and Bus, Continuous
///
/// @param DS_INA226 struct DS_INA226
/// @param OperatingMode 0-7
void _DS_INA226_SetOperatingMode(DS_INA226 *DS_INA226, uint8_t OperatingMode);
/// @brief Update DS_INA226 structure
/// @param DS_INA226 struct DS_INA226
void _DS_INA226_GetAllMemory(DS_INA226 *DS_INA226);
uint16_t DS_INA226_GetShuntVoltage(DS_INA226 *DS_INA226);
uint16_t DS_INA226_GetBusVoltage(DS_INA226 *DS_INA226);
float DS_INA226_GetPower(DS_INA226 *DS_INA226);
float DS_INA226_GetCurrent(DS_INA226 *DS_INA226);
#endif //DS_INA226_H