Skip to content

Commit 9ec04dd

Browse files
SV-ZanshinSV-Zanshin
authored andcommitted
Issue #30 fixed
Support TEENSY and removed overflow error when using devices with large EEPROM
1 parent 2333d78 commit 9ec04dd

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/INA.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ uint8_t INA_Class::begin(const uint8_t maxBusAmps, const uint32_t microOhmR, con
176176
uint16_t originalRegister,tempRegister; // Stores 16-bit register contents //
177177
if (_DeviceCount==0) // Enumerate devices in first call //
178178
{ // //
179-
uint8_t maxDevices = 0; // declare variable //
179+
uint16_t maxDevices = 0; // declare variable //
180180
#if defined(ESP32) || defined(ESP2866) // //
181181
EEPROM.begin(512); // If ESP32 then allocate 512 Bytes //
182182
maxDevices = 512 / sizeof(inaEE); // and compute number of devices //
@@ -185,12 +185,12 @@ uint8_t INA_Class::begin(const uint8_t maxBusAmps, const uint32_t microOhmR, con
185185
#endif // //
186186
#if defined(__STM32F1__) // Emulated EEPROM for STM32F1 //
187187
maxDevices = EEPROM.maxcount() / sizeof(inaEE); // Compute number devices possible //
188-
#elif defined(CORE_TEENSY) || defined(MK20DX128) || defined(MK20DX256) || \
189-
defined(MKL26Z64) || defined(MK64FX512) || defined(MK66FX1M0) // TEENSY doesn't have EEPROM.length//
188+
#elif defined(CORE_TEENSY) // TEENSY doesn't have EEPROM.length//
190189
maxDevices = 2048 / sizeof(inaEE); // defined, so use 2Kb as value //
191190
#else // EEPROM Library V2.0 for Arduino //
192191
maxDevices = EEPROM.length() / sizeof(inaEE); // Compute number devices possible //
193192
#endif // //
193+
if (maxDevices > 255) { maxDevices = 255; } // Limit to a 8-bit number //
194194
for(uint8_t deviceAddress = 0x40;deviceAddress<0x80;deviceAddress++) // Loop for each possible address //
195195
{ // //
196196
Wire.beginTransmission(deviceAddress); // See if something is at address //
@@ -201,7 +201,7 @@ uint8_t INA_Class::begin(const uint8_t maxBusAmps, const uint32_t microOhmR, con
201201
tempRegister = readWord(INA_CONFIGURATION_REGISTER,deviceAddress);// Read the newly reset register //
202202
if (tempRegister==INA_RESET_DEVICE ) // If the register isn't reset then //
203203
{ // //
204-
writeWord(INA_CONFIGURATION_REGISTER,originalRegister,deviceAddress);// Not an an INA, write back value//
204+
writeWord(INA_CONFIGURATION_REGISTER,originalRegister,deviceAddress);// Not an an INA, write back value //
205205
} // //
206206
else // otherwise we know it is an INA //
207207
{ // //

src/INA.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
** **
3232
** Vers. Date Developer Comments **
3333
** ====== ========== ============================= ============================================================== **
34-
** 1.0.6 2018-10-16 https://github.com/Sv-Zanshin Issue #30. Added support for TEENSY in EEPROM calls **
34+
** 1.0.6 2018-10-19 https://github.com/Sv-Zanshin Issue #30. Added TEENSY suuport & support large EEPROM **
3535
** 1.0.6 2018-10-14 https://github.com/Sv-Zanshin Added correct wire handling for ESP8266 and ESP32 **
3636
** 1.0.6 2018-10-07 https://github.com/Sv-Zanshin Optimized getBusRaw() and getShuntRaw() functions **
3737
** 1.0.5 2018-10-04 https://github.com/Sv-Zanshin Added getBusRaw() and getShuntRaw() functions **

0 commit comments

Comments
 (0)