-
Notifications
You must be signed in to change notification settings - Fork 4
/
EEPROM.h
42 lines (36 loc) · 1.15 KB
/
EEPROM.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef EEPROM_h
#define EEPROM_h
#include <Wire.h>
byte readMemory(int index) {//Example for 24AA02E64 eeprom chip
// when using external storage, implement READ command here
// return EEPROM.read(index);
byte rdata = 0xFF;
Wire.beginTransmission(0x50);
Wire.write((int)(index >> 8)); // MSB
Wire.write((int)(index & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(0x50,1);
if (Wire.available()) rdata = Wire.read();
return rdata;
}
void writeMemory(int index, byte val) {//Example for 24AA02E64 eeprom chip
// when using external storage, implement WRITE command here
// return EEPROM.write(index, val);
Wire.beginTransmission(0x50);
Wire.write((int)(index >> 8)); // MSB
Wire.write((int)(index & 0xFF)); // LSB
Wire.write(val);
Wire.endTransmission();
delay(5);//is it needed?!
}
void updateMemory(int index, byte val) {
// when using external storage, implement UPDATE command here
//return EEPROM.update(index, val);
if (readMemory(index) != val) {
writeMemory(index, val);
}
}
void commitMemory() {
// EEPROM needs no commit, so this function is intentionally left blank
}
#endif