Skip to content

Commit d776259

Browse files
committed
fixed wire issues and some other smal things
version++
1 parent 8168458 commit d776259

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=INA226Lib
2-
version=1.1.1
2+
version=1.1.2
33
author=Peter Buchegger <[email protected]>, Korneliusz Jarzebski <[email protected]>
44
maintainer=Peter Buchegger <[email protected]>
55
sentence=Enables reading from INA226 current sensors to measure current and power.

src/INA226.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/*
22
INA226.cpp - Class file for the INA226 Bi-directional Current/Power Monitor Arduino Library.
33
4-
Version: 1.0.0
5-
(c) 2014 Korneliusz Jarzebski
4+
(c) 2014 Korneliusz Jarzebski, modified 2020 by Peter Buchegger
65
www.jarzebski.pl
76
87
This program is free software: you can redistribute it and/or modify
@@ -49,7 +48,7 @@ bool INA226::configure(ina226_averages_t avg, ina226_busConvTime_t busConvTime,
4948
return true;
5049
}
5150

52-
bool INA226::calibrate(float rShuntValue, float iMaxExpected)
51+
bool INA226::calibrate(float rShuntValue, float iMaxCurrentExcepted)
5352
{
5453
uint16_t calibrationValue;
5554
rShunt = rShuntValue;
@@ -58,7 +57,7 @@ bool INA226::calibrate(float rShuntValue, float iMaxExpected)
5857

5958
iMaxPossible = vShuntMax / rShunt;
6059

61-
minimumLSB = iMaxExpected / 32767;
60+
minimumLSB = iMaxCurrentExcepted / 32767;
6261

6362
currentLSB = (uint32_t)(minimumLSB * 100000000);
6463
currentLSB /= 100000000;
@@ -285,7 +284,10 @@ int16_t INA226::readRegister16(uint8_t reg)
285284
{
286285
int16_t value;
287286

287+
Wire.beginTransmission(inaAddress);
288288
Wire.write(reg);
289+
Wire.endTransmission();
290+
289291
Wire.requestFrom(inaAddress, 2);
290292
uint8_t vha = Wire.read();
291293
uint8_t vla = Wire.read();
@@ -300,7 +302,9 @@ void INA226::writeRegister16(uint8_t reg, uint16_t val)
300302
vla = (uint8_t)val;
301303
val >>= 8;
302304

305+
Wire.beginTransmission(inaAddress);
303306
Wire.write(reg);
304307
Wire.write((uint8_t)val);
305308
Wire.write(vla);
309+
Wire.endTransmission();
306310
}

src/INA226.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/*
22
INA226.h - Header file for the Bi-directional Current/Power Monitor Arduino Library.
33
4-
Version: 1.0.0
5-
(c) 2014 Korneliusz Jarzebski
4+
(c) 2014 Korneliusz Jarzebski, modified 2020 by Peter Buchegger
65
www.jarzebski.pl
76
87
This program is free software: you can redistribute it and/or modify
@@ -104,7 +103,7 @@ class INA226
104103

105104
bool begin(uint8_t address = INA226_ADDRESS);
106105
bool configure(ina226_averages_t avg = INA226_AVERAGES_1, ina226_busConvTime_t busConvTime = INA226_BUS_CONV_TIME_1100US, ina226_shuntConvTime_t shuntConvTime = INA226_SHUNT_CONV_TIME_1100US, ina226_mode_t mode = INA226_MODE_SHUNT_BUS_CONT);
107-
bool calibrate(float rShuntValue = 0.1, float iMaxExcepted = 2);
106+
bool calibrate(float rShuntValue = 0.1, float iMaxCurrentExcepted = 2);
108107

109108
ina226_averages_t getAverages(void);
110109
ina226_busConvTime_t getBusConversionTime(void);
@@ -138,7 +137,7 @@ class INA226
138137
float getMaxShuntVoltage(void);
139138
float getMaxPower(void);
140139

141-
private:
140+
private:
142141

143142
int8_t inaAddress;
144143
float currentLSB, powerLSB;

0 commit comments

Comments
 (0)