@@ -66,6 +66,24 @@ bool ExternalEEPROM::begin(uint8_t deviceAddress, TwoWire &wirePort)
66
66
67
67
return true ;
68
68
}
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
+ }
69
87
70
88
// Erase entire EEPROM
71
89
void ExternalEEPROM::erase (uint8_t toWrite)
@@ -871,6 +889,9 @@ int ExternalEEPROM::write(uint32_t eepromLocation, const uint8_t *dataToWrite, u
871
889
while (isBusy (settings.deviceAddress ) == true ) // Poll device's original address, not the modified one
872
890
delayMicroseconds (100 ); // This shortens the amount of time waiting between writes but hammers the I2C bus
873
891
892
+ // Check if we are using Write Protection then disable WP for write access
893
+ if (settings.wpPin != 255 ) digitalWrite (settings.wpPin , LOW);
894
+
874
895
settings.i2cPort ->beginTransmission (i2cAddress);
875
896
if (settings.addressSize_bytes > 1 ) // Device larger than 16,384 bits have two byte addresses
876
897
settings.i2cPort ->write ((uint8_t )((eepromLocation + recorded) >> 8 )); // MSB
@@ -888,6 +909,9 @@ int ExternalEEPROM::write(uint32_t eepromLocation, const uint8_t *dataToWrite, u
888
909
889
910
if (settings.pollForWriteComplete == false )
890
911
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);
891
915
}
892
916
893
917
return (result);
0 commit comments