BayEOSArduino Library
I2C_eeprom.h
1 #ifndef I2C_EEPROM_H
2 #define I2C_EEPROM_H
3 //
4 // FILE: I2C_eeprom.h
5 // AUTHOR: Rob Tillaart
6 // PURPOSE: Simple I2C_eeprom library for Arduino with EEPROM 24LC256 et al.
7 // VERSION: 1.0.05
8 // HISTORY: See I2C_eeprom.cpp
9 // URL: http://arduino.cc/playground/Main/LibraryForI2CEEPROM
10 //
11 // Released to the public domain
12 //
13 
14 #include <Wire.h>
15 #include "Arduino.h"
16 
17 #define I2C_EEPROM_VERSION "1.0.05"
18 
19 // I2C_EEPROM_PAGESIZE must be multiple of 2 e.g. 16, 32 or 64
20 // 24LC256 -> 64 bytes
21 #define I2C_EEPROM_PAGESIZE 64
22 
23 // TWI buffer needs max 2 bytes for address
24 #define I2C_TWIBUFFERSIZE 30
25 
26 // to break blocking read/write
27 #define I2C_EEPROM_TIMEOUT 1000
28 
29 // comment next line to keep lib small
30 #define I2C_EEPROM_EXTENDED
31 
33 {
34 public:
35  I2C_eeprom(){};
36  I2C_eeprom(uint8_t deviceAddress);
37 
38  int writeByte(uint16_t address, const uint8_t value);
39  int writeBlock(uint16_t address, const uint8_t* buffer, uint16_t length);
40  int setBlock(uint16_t address, uint8_t value, uint16_t length);
41  void setDeviceAddress(uint8_t deviceAddress){
42  _deviceAddress=deviceAddress;
43  }
44 
45  uint8_t readByte(uint16_t address);
46  uint16_t readBlock(uint16_t address, uint8_t* buffer, uint16_t length);
47 
48 #ifdef I2C_EEPROM_EXTENDED
49  uint8_t determineSize();
50 #endif
51 
52 private:
53  uint8_t _deviceAddress;
54  uint32_t _lastWrite; // for waitEEReady
55 
56  int _pageBlock(uint16_t address, const uint8_t* buffer, uint16_t length, bool incrBuffer);
57  int _WriteBlock(uint16_t address, const uint8_t* buffer, uint8_t length);
58  uint8_t _ReadBlock(uint16_t address, uint8_t* buffer, uint8_t length);
59 
60  void waitEEReady();
61 };
62 
63 #endif
64 // END OF FILE
65 
Definition: I2C_eeprom.h:33