First attempt

This commit is contained in:
2025-05-02 23:40:54 +03:00
parent 795c9e0a90
commit e2fe8396ca
2 changed files with 196 additions and 12 deletions

View File

@@ -18,22 +18,82 @@
typedef struct DS_INA226
{
// SPI_HandleTypeDef* SPI;
// char DisplayData[8];
// uint8_t Dots;
// uint8_t DecodeMode, Intensivity, ScanLimit;
// bool EnableDecodeMode;
// GPIO_TypeDef* Port_CS;
// uint16_t Pin_CS;
uint8_t DevAddr;
I2C_HandleTypeDef *hi2c;
uint16_t SensorData[9];
float Current_LSB;
uint8_t ShuntResistance; //mOhm
}DS_INA226;
void DS_INA226_Init(void);
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