-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAT24C1024.cpp
More file actions
executable file
·46 lines (39 loc) · 1.07 KB
/
Copy pathAT24C1024.cpp
File metadata and controls
executable file
·46 lines (39 loc) · 1.07 KB
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
43
44
45
46
/*
AT24C1024.cpp
AT24C1024 EEPROM Library for Arduino
http://www.arduino.cc/playground/Code/I2CEEPROM24C1024
*/
#include <Wire.h>
#if ARDUINO >= 100
#include "Arduino.h"
#else
extern "C" {
#include "WConstants.h"
}
#endif
#include "AT24C1024.h"
AT24C1024::AT24C1024(void)
{
Wire.begin();
}
void AT24C1024::write(unsigned long dataAddress, uint8_t data)
{
Wire.beginTransmission((uint8_t)((0x500000 | dataAddress) >> 16)); // B1010xxx
Wire.write((uint8_t)((dataAddress & WORD_MASK) >> 8)); // MSB
Wire.write((uint8_t)(dataAddress & 0xFF)); // LSB
Wire.write(data);
Wire.endTransmission();
delay(5);
}
uint8_t AT24C1024::read(unsigned long dataAddress)
{
uint8_t data = 0x00;
Wire.beginTransmission((uint8_t)((0x500000 | dataAddress) >> 16)); // B1010xxx
Wire.write((uint8_t)((dataAddress & WORD_MASK) >> 8)); // MSB
Wire.write((uint8_t)(dataAddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom((uint8_t)((0x500000 | dataAddress) >> 16),(uint8_t)1);
if (Wire.available()) data = Wire.peek();
return data;
}
AT24C1024 EEPROM1024;