Create a gist now

Instantly share code, notes, and snippets.

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