Skip to content

Instantly share code, notes, and snippets.

@trdenton
Created September 12, 2016 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trdenton/acc9340e49eae71e031d914bfa869bb1 to your computer and use it in GitHub Desktop.
Save trdenton/acc9340e49eae71e031d914bfa869bb1 to your computer and use it in GitHub Desktop.
looking through an eeprom for a known sequence, "AB"
#include <Wire.h>
#define disk1 0x50 //Address of 24LC256 eeprom chip
void setup(void)
{
Serial.begin(9600);
Wire.begin();
unsigned int address = 0x3571;
//Serial.print(readEEPROM(disk1, address), DEC);
long int i;
byte last=0x00;
byte in =0x00;
for(i = 0x3500; i<0x6000; i++)
{
last=in;
in = readEEPROM(disk1,i);
if ((char)in == 'B' && (char)last =='A')
{
Serial.print("AB @ ");
Serial.println(i-1,HEX);
}
}
}
void loop(){}
void writeEEPROM(int 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(5);
}
byte readEEPROM(int 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment