mirror of
https://github.com/RobTillaart/I2C_EEPROM.git
synced 2026-07-27 20:06:07 +00:00
Test cases for I2C_eeprom initialization (#15)
Added test cases for I2C_eeprom initialization to verify that the page size is chosen correctly and that it sets the address size properly. Fixed a bug with the larger eeprom sizes having incorrect intervals.
This commit is contained in:
+7
-10
@@ -46,30 +46,27 @@ I2C_eeprom::I2C_eeprom(const uint8_t deviceAddress, const unsigned int deviceSiz
|
||||
_deviceAddress = deviceAddress;
|
||||
|
||||
// Chips 16Kbit (2048 Bytes) or smaller only have one-word addresses.
|
||||
// Also try to guess page size from device size (going by Microchip 24LCXX datasheets here).
|
||||
if (deviceSize <= 256)
|
||||
this->_isAddressSizeTwoWords = deviceSize <= 2048 ? false : true;
|
||||
|
||||
// Try to guess page size from device size (going by Microchip 24LCXX datasheets here).
|
||||
if (deviceSize <= 256) // 2Kbit
|
||||
{
|
||||
this->_isAddressSizeTwoWords = false;
|
||||
this->_pageSize = 8;
|
||||
}
|
||||
else if (deviceSize <= 256 * 8)
|
||||
else if (deviceSize <= 2048) // 16Kbit
|
||||
{
|
||||
this->_isAddressSizeTwoWords = false;
|
||||
this->_pageSize = 16;
|
||||
}
|
||||
else if(deviceSize <= 8192 * 8)
|
||||
else if(deviceSize <= 8192) // 64Kbit
|
||||
{
|
||||
this->_isAddressSizeTwoWords = true;
|
||||
this->_pageSize = 32;
|
||||
}
|
||||
else if(deviceSize <= 65536 * 8)
|
||||
else if(deviceSize <= 32768) // 256Kbit
|
||||
{
|
||||
this->_isAddressSizeTwoWords = true;
|
||||
this->_pageSize = 64;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->_isAddressSizeTwoWords = true;
|
||||
this->_pageSize = 128;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user