Created
September 12, 2016 05:31
-
-
Save trdenton/d55579156486a7e9a4342040e846c0e4 to your computer and use it in GitHub Desktop.
re-writing an EEPROM to control the bluetooth name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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