Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
re-writing an EEPROM to control the bluetooth name
#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;
writeEEPROM(disk1,0x3B44,'S');
writeEEPROM(disk1,0x3B45,'k');
writeEEPROM(disk1,0x3B46,'u');
writeEEPROM(disk1,0x3B47,'l');
writeEEPROM(disk1,0x3B48,'l');
writeEEPROM(disk1,0x3B49,'S');
writeEEPROM(disk1,0x3B4a,'p');
writeEEPROM(disk1,0x3B4b,'a');
writeEEPROM(disk1,0x3B4c,'c');
writeEEPROM(disk1,0x3B4d,'e');
Serial.println("Done writing, read back...");
for(i = 0; i<12; i++)
{
Serial.print((char)readEEPROM(disk1,0x3B44+i));
}
}
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