cancellare 24lc512

Assicurati che il monitor sia configurato alla stessa velocità del tuo Serial.begin

#include <Wire.h>
#define disk1 0x50 

unsigned int address = 0,nLocazione;

void setup(void)
{
  Serial.begin(9600);
  Wire.begin();  

  Serial.println("hello !");
  
  
 
  writeEEPROM(disk1, address, 123);
  Serial.print(readEEPROM(disk1, address), DEC);
}
 
void loop(){
 while (Serial.available())
    {
      char cmd = (char)Serial.read();
       
      if (cmd == 'f')
      { 
          while (address++ < nLocazione )  writeEEPROM(disk1, address, 255);  // cancella tutto
          Serial.print("EEPROM cancellata");
      } 
   } 
  }
 
void writeEEPROM( byte deviceaddress, unsigned int eeaddress, byte data ) 
{
  Wire.beginTransmission(deviceaddress);
   Wire.write((int)(eeaddress >> 8));   // MSB
   Wire.write((int)(eeaddress & 0xFF)); // LSB
   Wire.write(data);
   Wire.endTransmission();
 
  delay(10);
}
 
byte readEEPROM(byte deviceaddress, unsigned int eeaddress ) 
{
  byte rdata = 0xFF;
 
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8));   // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.endTransmission();
 
  Wire.requestFrom(deviceaddress,1);
 
  if (Wire.available()) rdata = Wire.read();

  return rdata;
}