@@ -66,6 +66,24 @@ bool ExternalEEPROM::begin(uint8_t deviceAddress, TwoWire &wirePort)
6666
6767 return true ;
6868}
69+ bool ExternalEEPROM::begin (uint8_t deviceAddress, TwoWire &wirePort, uint8_t WP)
70+ {
71+ if (WP != 255 )
72+ {
73+ pinMode (WP, OUTPUT);
74+ digitalWrite (WP, HIGH);
75+ settings.wpPin = WP;
76+ }
77+ settings.i2cPort = &wirePort; // Grab which port the user wants us to use
78+ settings.deviceAddress = deviceAddress;
79+
80+ if (isConnected () == false )
81+ {
82+ return false ;
83+ }
84+
85+ return true ;
86+ }
6987
7088// Erase entire EEPROM
7189void ExternalEEPROM::erase (uint8_t toWrite)
@@ -871,6 +889,9 @@ int ExternalEEPROM::write(uint32_t eepromLocation, const uint8_t *dataToWrite, u
871889 while (isBusy (settings.deviceAddress ) == true ) // Poll device's original address, not the modified one
872890 delayMicroseconds (100 ); // This shortens the amount of time waiting between writes but hammers the I2C bus
873891
892+ // Check if we are using Write Protection then disable WP for write access
893+ if (settings.wpPin != 255 ) digitalWrite (settings.wpPin , LOW);
894+
874895 settings.i2cPort ->beginTransmission (i2cAddress);
875896 if (settings.addressSize_bytes > 1 ) // Device larger than 16,384 bits have two byte addresses
876897 settings.i2cPort ->write ((uint8_t )((eepromLocation + recorded) >> 8 )); // MSB
@@ -888,6 +909,9 @@ int ExternalEEPROM::write(uint32_t eepromLocation, const uint8_t *dataToWrite, u
888909
889910 if (settings.pollForWriteComplete == false )
890911 delay (settings.writeTime_ms ); // Delay the amount of time to record a page
912+
913+ // Enable Write Protection if we are using WP
914+ if (settings.wpPin != 255 ) digitalWrite (settings.wpPin , HIGH);
891915 }
892916
893917 return (result);
0 commit comments