mirror of
https://github.com/RobTillaart/I2C_EEPROM.git
synced 2026-07-27 20:06:07 +00:00
@@ -1,8 +1,7 @@
|
||||
//
|
||||
// FILE: I2C_eeprom_determineSize.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: test determinsize function
|
||||
// PURPOSE: test determinSize() function
|
||||
//
|
||||
|
||||
|
||||
@@ -10,9 +9,7 @@
|
||||
#include "I2C_eeprom.h"
|
||||
|
||||
|
||||
#define MEMORY_SIZE 0x2000 //total bytes can be accessed 24LC64 = 0x2000 (maximum address = 0x1FFF)
|
||||
|
||||
I2C_eeprom ee(0x50, MEMORY_SIZE);
|
||||
I2C_eeprom ee(0x50, I2C_DEVICESIZE_24LC256);
|
||||
|
||||
uint32_t start, diff;
|
||||
|
||||
@@ -21,6 +18,8 @@ void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("I2C_EEPROM_VERSION: ");
|
||||
Serial.println(I2C_EEPROM_VERSION);
|
||||
|
||||
ee.begin();
|
||||
if (! ee.isConnected())
|
||||
@@ -29,28 +28,32 @@ void setup()
|
||||
while (1);
|
||||
}
|
||||
|
||||
Serial.print("I2C_EEPROM_VERSION: ");
|
||||
Serial.println(I2C_EEPROM_VERSION);
|
||||
|
||||
Serial.println("\nDetermine size");
|
||||
delay(10);
|
||||
|
||||
start = micros();
|
||||
int size = ee.determineSize(true); // debug param
|
||||
uint32_t size = ee.determineSize(false); // debug param
|
||||
diff = micros() - start;
|
||||
Serial.print("TIME: ");
|
||||
Serial.print(diff);
|
||||
Serial.println(" us.");
|
||||
if (size > 0)
|
||||
if (size == 0)
|
||||
{
|
||||
Serial.println("SIZE: could not determine size");
|
||||
}
|
||||
else if (size > 1024)
|
||||
{
|
||||
Serial.print("SIZE: ");
|
||||
Serial.print(size / 1024);
|
||||
Serial.println(" KB.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print("SIZE: ");
|
||||
Serial.print(size);
|
||||
Serial.println(" KB.");
|
||||
}
|
||||
if (size == 0)
|
||||
{
|
||||
Serial.println("WARNING: Can't determine eeprom size");
|
||||
Serial.println(" bytes.");
|
||||
}
|
||||
|
||||
Serial.println("Done...");
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
//
|
||||
// FILE: I2C_eeprom_format.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo format EEPROM
|
||||
//
|
||||
|
||||
|
||||
#include "Wire.h"
|
||||
#include "I2C_eeprom.h"
|
||||
|
||||
|
||||
I2C_eeprom ee(0x50, I2C_DEVICESIZE_24LC256);
|
||||
|
||||
uint32_t start, diff;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("I2C_EEPROM_VERSION: ");
|
||||
Serial.println(I2C_EEPROM_VERSION);
|
||||
|
||||
ee.begin();
|
||||
if (! ee.isConnected())
|
||||
{
|
||||
Serial.println("ERROR: Can't find eeprom\nstopped...");
|
||||
while (1);
|
||||
}
|
||||
|
||||
|
||||
Serial.println();
|
||||
uint32_t size = ee.determineSize(false); // debug param
|
||||
if (size == 0)
|
||||
{
|
||||
Serial.println("SIZE: could not determine size");
|
||||
}
|
||||
else if (size > 1024)
|
||||
{
|
||||
Serial.print("SIZE: ");
|
||||
Serial.print(size / 1024);
|
||||
Serial.println(" KB.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print("SIZE: ");
|
||||
Serial.print(size);
|
||||
Serial.println(" bytes.");
|
||||
}
|
||||
|
||||
|
||||
// flush input
|
||||
while (Serial.available()) Serial.read();
|
||||
|
||||
Serial.println("Sure to format EEPROM? [Y | N]");
|
||||
while (!Serial.available());
|
||||
int ans = Serial.read();
|
||||
|
||||
if ( ans == 'Y')
|
||||
{
|
||||
start = millis();
|
||||
for (uint32_t i = 0; i < size; i += 128)
|
||||
{
|
||||
if (i % 1024 == 0) Serial.print('.');
|
||||
ee.setBlock(0, 0xFF, 128);
|
||||
}
|
||||
diff = millis() - start;
|
||||
Serial.print("\nTIME: ");
|
||||
Serial.print(diff);
|
||||
Serial.println(" ms.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("not formatted");
|
||||
}
|
||||
|
||||
Serial.println("Done...");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
||||
@@ -1,46 +1,46 @@
|
||||
//
|
||||
// FILE: I2C_eeprom_test.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.09
|
||||
// PURPOSE: show/test I2C_EEPROM library
|
||||
//
|
||||
|
||||
#include <Wire.h> //I2C library
|
||||
#include <I2C_eeprom.h>
|
||||
// uses a 24LC256 (32KB) EEPROM
|
||||
|
||||
#include "Wire.h"
|
||||
#include "I2C_eeprom.h"
|
||||
|
||||
|
||||
// UNO
|
||||
#define SERIAL_OUT Serial
|
||||
// Due
|
||||
// #define SERIAL_OUT SerialUSB
|
||||
|
||||
//for decimal display uncomment below two lines
|
||||
#define DISPLAY_DECIMAL
|
||||
#define BLOCK_TO_LENGTH 10
|
||||
|
||||
//for hex display uncomment below two lines
|
||||
//#define DISPLAY_HEX
|
||||
//#define BLOCK_TO_LENGTH 16
|
||||
|
||||
#define MEMORY_SIZE 0x2000 //total bytes can be accessed 24LC64 = 0x2000 (maximum address = 0x1FFF)
|
||||
|
||||
I2C_eeprom ee(0x50, MEMORY_SIZE);
|
||||
I2C_eeprom ee(0x50, I2C_DEVICESIZE_24LC256);
|
||||
|
||||
uint32_t start, diff, totals = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
ee.begin();
|
||||
|
||||
SERIAL_OUT.begin(57600);
|
||||
void setup()
|
||||
{
|
||||
SERIAL_OUT.begin(115200);
|
||||
while (!SERIAL_OUT); // wait for SERIAL_OUT port to connect. Needed for Leonardo only
|
||||
|
||||
SERIAL_OUT.print("Demo I2C eeprom library ");
|
||||
SERIAL_OUT.println(__FILE__);
|
||||
|
||||
ee.begin();
|
||||
if (! ee.isConnected())
|
||||
{
|
||||
SERIAL_OUT.println("ERROR: Can't find eeprom\nstopped...");
|
||||
while (1);
|
||||
}
|
||||
|
||||
SERIAL_OUT.print("I2C eeprom library: ");
|
||||
SERIAL_OUT.print(I2C_EEPROM_VERSION);
|
||||
SERIAL_OUT.println("\n");
|
||||
|
||||
SERIAL_OUT.println("\nTEST: determine size");
|
||||
start = micros();
|
||||
int size = ee.determineSize();
|
||||
uint32_t size = ee.determineSize();
|
||||
diff = micros() - start;
|
||||
SERIAL_OUT.print("TIME: ");
|
||||
SERIAL_OUT.println(diff);
|
||||
@@ -56,7 +56,7 @@ void setup()
|
||||
else
|
||||
{
|
||||
SERIAL_OUT.println("ERROR: Can't find eeprom\nstopped...");
|
||||
while(1);
|
||||
while (1);
|
||||
}
|
||||
|
||||
SERIAL_OUT.println("\nTEST: 64 byte page boundary writeBlock");
|
||||
@@ -86,21 +86,21 @@ void setup()
|
||||
|
||||
SERIAL_OUT.println("\nTEST: write large string readback in small steps");
|
||||
ee.setBlock(0, 0, 128);
|
||||
char data2[] = "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999A";
|
||||
char data2[] = "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999A";
|
||||
ee.writeBlock(10, (uint8_t *) &data2, sizeof(data2));
|
||||
dumpEEPROM(0, 128);
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
if (i % 10 == 0 ) SERIAL_OUT.println();
|
||||
SERIAL_OUT.print(' ');
|
||||
SERIAL_OUT.print(ee.readByte(10+i));
|
||||
SERIAL_OUT.print(ee.readByte(10 + i));
|
||||
}
|
||||
SERIAL_OUT.println();
|
||||
|
||||
|
||||
SERIAL_OUT.println("\nTEST: check almost endofPage writeBlock");
|
||||
ee.setBlock(0, 0, 128);
|
||||
char data3[] = "6666";
|
||||
char data3[] = "6666";
|
||||
ee.writeBlock(60, (uint8_t *) &data3, sizeof(data3));
|
||||
dumpEEPROM(0, 128);
|
||||
|
||||
@@ -115,7 +115,7 @@ void setup()
|
||||
SERIAL_OUT.print("\nTEST: timing writeByte()\t");
|
||||
uint32_t start = micros();
|
||||
ee.writeByte(10, 1);
|
||||
uint32_t diff = micros() - start;
|
||||
uint32_t diff = micros() - start;
|
||||
SERIAL_OUT.print("TIME: ");
|
||||
SERIAL_OUT.println(diff);
|
||||
totals += diff;
|
||||
@@ -123,7 +123,7 @@ void setup()
|
||||
SERIAL_OUT.print("TEST: timing writeBlock(50)\t");
|
||||
start = micros();
|
||||
ee.writeBlock(10, (uint8_t *) &data2, 50);
|
||||
diff = micros() - start;
|
||||
diff = micros() - start;
|
||||
SERIAL_OUT.print("TIME: ");
|
||||
SERIAL_OUT.println(diff);
|
||||
totals += diff;
|
||||
@@ -131,7 +131,7 @@ void setup()
|
||||
SERIAL_OUT.print("TEST: timing readByte()\t\t");
|
||||
start = micros();
|
||||
ee.readByte(10);
|
||||
diff = micros() - start;
|
||||
diff = micros() - start;
|
||||
SERIAL_OUT.print("TIME: ");
|
||||
SERIAL_OUT.println(diff);
|
||||
totals += diff;
|
||||
@@ -139,7 +139,7 @@ void setup()
|
||||
SERIAL_OUT.print("TEST: timing readBlock(50)\t");
|
||||
start = micros();
|
||||
ee.readBlock(10, (uint8_t *) &data2, 50);
|
||||
diff = micros() - start;
|
||||
diff = micros() - start;
|
||||
SERIAL_OUT.print("TIME: ");
|
||||
SERIAL_OUT.println(diff);
|
||||
totals += diff;
|
||||
@@ -154,7 +154,7 @@ void setup()
|
||||
SERIAL_OUT.print("\nTEST: timing writeByte()\t");
|
||||
start = micros();
|
||||
ee.writeByte(10, 1);
|
||||
diff = micros() - start;
|
||||
diff = micros() - start;
|
||||
SERIAL_OUT.print("TIME: ");
|
||||
SERIAL_OUT.println(diff);
|
||||
totals += diff;
|
||||
@@ -164,7 +164,7 @@ void setup()
|
||||
SERIAL_OUT.print("TEST: timing writeBlock(50)\t");
|
||||
start = micros();
|
||||
ee.writeBlock(10, (uint8_t *) &data2, 50);
|
||||
diff = micros() - start;
|
||||
diff = micros() - start;
|
||||
SERIAL_OUT.print("TIME: ");
|
||||
SERIAL_OUT.println(diff);
|
||||
totals += diff;
|
||||
@@ -174,7 +174,7 @@ void setup()
|
||||
SERIAL_OUT.print("TEST: timing readByte()\t\t");
|
||||
start = micros();
|
||||
ee.readByte(10);
|
||||
diff = micros() - start;
|
||||
diff = micros() - start;
|
||||
SERIAL_OUT.print("TIME: ");
|
||||
SERIAL_OUT.println(diff);
|
||||
totals += diff;
|
||||
@@ -184,7 +184,7 @@ void setup()
|
||||
SERIAL_OUT.print("TEST: timing readBlock(50)\t");
|
||||
start = micros();
|
||||
int xx = ee.readBlock(10, (uint8_t *) &data2, 50);
|
||||
diff = micros() - start;
|
||||
diff = micros() - start;
|
||||
SERIAL_OUT.print("TIME: ");
|
||||
SERIAL_OUT.println(diff);
|
||||
totals += diff;
|
||||
@@ -199,33 +199,21 @@ void setup()
|
||||
SERIAL_OUT.println("\tDone...");
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void dumpEEPROM(uint16_t memoryAddress, uint16_t length)
|
||||
{
|
||||
#ifdef DISPLAY_DECIMAL
|
||||
const int BLOCK_TO_LENGTH = 10;
|
||||
|
||||
SERIAL_OUT.print("\t ");
|
||||
#endif
|
||||
#ifdef DISPLAY_HEX
|
||||
SERIAL_OUT.print("\t ");
|
||||
#endif
|
||||
for(int x = 0; x < BLOCK_TO_LENGTH; x++) {
|
||||
if(x != 0) {
|
||||
#ifdef DISPLAY_DECIMAL
|
||||
SERIAL_OUT.print(" ");
|
||||
#endif
|
||||
#ifdef DISPLAY_HEX
|
||||
SERIAL_OUT.print(" ");
|
||||
#endif
|
||||
}
|
||||
#ifdef DISPLAY_DECIMAL
|
||||
for (int x = 0; x < 10; x++)
|
||||
{
|
||||
if (x != 0) SERIAL_OUT.print(" ");
|
||||
SERIAL_OUT.print(x);
|
||||
#endif
|
||||
#ifdef DISPLAY_HEX
|
||||
SERIAL_OUT.print(x,HEX);
|
||||
#endif
|
||||
}
|
||||
SERIAL_OUT.println();
|
||||
|
||||
@@ -233,34 +221,23 @@ void dumpEEPROM(uint16_t memoryAddress, uint16_t length)
|
||||
memoryAddress = memoryAddress / BLOCK_TO_LENGTH * BLOCK_TO_LENGTH;
|
||||
length = (length + BLOCK_TO_LENGTH - 1) / BLOCK_TO_LENGTH * BLOCK_TO_LENGTH;
|
||||
|
||||
byte b = ee.readByte(memoryAddress);
|
||||
byte b = ee.readByte(memoryAddress);
|
||||
for (unsigned int i = 0; i < length; i++)
|
||||
{
|
||||
char buf[6];
|
||||
if (memoryAddress % BLOCK_TO_LENGTH == 0)
|
||||
{
|
||||
if(i != 0) {
|
||||
SERIAL_OUT.println();
|
||||
}
|
||||
#ifdef DISPLAY_DECIMAL
|
||||
if (i != 0) SERIAL_OUT.println();
|
||||
sprintf(buf, "%05d", memoryAddress);
|
||||
#endif
|
||||
#ifdef DISPLAY_HEX
|
||||
sprintf(buf, "%04X", memoryAddress);
|
||||
#endif
|
||||
SERIAL_OUT.print(buf);
|
||||
SERIAL_OUT.print(":\t");
|
||||
}
|
||||
#ifdef DISPLAY_DECIMAL
|
||||
sprintf(buf, "%03d", b);
|
||||
#endif
|
||||
#ifdef DISPLAY_HEX
|
||||
sprintf(buf, "%02X", b);
|
||||
#endif
|
||||
SERIAL_OUT.print(buf);
|
||||
b = ee.readByte(++memoryAddress);
|
||||
b = ee.readByte(++memoryAddress);
|
||||
SERIAL_OUT.print(" ");
|
||||
}
|
||||
SERIAL_OUT.println();
|
||||
}
|
||||
|
||||
// END OF FILE
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
//
|
||||
// FILE: I2C_eeprom_test_performance.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: show/test I2C_EEPROM library
|
||||
// PURPOSE: test I2C_EEPROM library
|
||||
//
|
||||
|
||||
|
||||
@@ -10,30 +9,28 @@
|
||||
#include "I2C_eeprom.h"
|
||||
|
||||
|
||||
//for decimal display uncomment below two lines
|
||||
#define DISPLAY_DECIMAL
|
||||
#define BLOCK_TO_LENGTH 10
|
||||
|
||||
//for hex display uncomment below two lines
|
||||
//#define DISPLAY_HEX
|
||||
//#define BLOCK_TO_LENGTH 16
|
||||
|
||||
|
||||
#define MEMORY_SIZE 0x2000 // total bytes can be accessed 24LC64 = 0x2000 (maximum address = 0x1FFF)
|
||||
|
||||
|
||||
I2C_eeprom ee(0x50, MEMORY_SIZE);
|
||||
I2C_eeprom ee(0x50, I2C_DEVICESIZE_24LC256);
|
||||
|
||||
uint32_t start, diff, totals = 0;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
|
||||
while (!Serial); // wait for Serial port to connect. Needed for Leonardo only
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("VERSION: ");
|
||||
Serial.println(I2C_EEPROM_VERSION);
|
||||
|
||||
ee.begin();
|
||||
if (! ee.isConnected())
|
||||
{
|
||||
Serial.println("ERROR: Can't find eeprom\nstopped...");
|
||||
while (1);
|
||||
}
|
||||
|
||||
Serial.print("I2C_EEPROM_VERSION: ");
|
||||
Serial.println(I2C_EEPROM_VERSION);
|
||||
|
||||
for (uint32_t speed = 100000; speed <= 1000000; speed += 100000)
|
||||
{
|
||||
@@ -43,14 +40,15 @@ void setup()
|
||||
delay(10);
|
||||
test();
|
||||
}
|
||||
|
||||
Serial.println("\ndone...");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
void test()
|
||||
@@ -146,27 +144,13 @@ void test()
|
||||
|
||||
void dumpEEPROM(uint16_t memoryAddress, uint16_t length)
|
||||
{
|
||||
#ifdef DISPLAY_DECIMAL
|
||||
const int BLOCK_TO_LENGTH = 10;
|
||||
|
||||
Serial.print("\t ");
|
||||
#endif
|
||||
#ifdef DISPLAY_HEX
|
||||
Serial.print("\t ");
|
||||
#endif
|
||||
for (int x = 0; x < BLOCK_TO_LENGTH; x++) {
|
||||
if (x != 0) {
|
||||
#ifdef DISPLAY_DECIMAL
|
||||
Serial.print(" ");
|
||||
#endif
|
||||
#ifdef DISPLAY_HEX
|
||||
Serial.print(" ");
|
||||
#endif
|
||||
}
|
||||
#ifdef DISPLAY_DECIMAL
|
||||
for (int x = 0; x < 10; x++)
|
||||
{
|
||||
if (x != 0) Serial.print(" ");
|
||||
Serial.print(x);
|
||||
#endif
|
||||
#ifdef DISPLAY_HEX
|
||||
Serial.print(x, HEX);
|
||||
#endif
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
@@ -180,28 +164,17 @@ void dumpEEPROM(uint16_t memoryAddress, uint16_t length)
|
||||
char buf[6];
|
||||
if (memoryAddress % BLOCK_TO_LENGTH == 0)
|
||||
{
|
||||
if (i != 0) {
|
||||
Serial.println();
|
||||
}
|
||||
#ifdef DISPLAY_DECIMAL
|
||||
if (i != 0) Serial.println();
|
||||
sprintf(buf, "%05d", memoryAddress);
|
||||
#endif
|
||||
#ifdef DISPLAY_HEX
|
||||
sprintf(buf, "%04X", memoryAddress);
|
||||
#endif
|
||||
Serial.print(buf);
|
||||
Serial.print(":\t");
|
||||
}
|
||||
#ifdef DISPLAY_DECIMAL
|
||||
sprintf(buf, "%03d", b);
|
||||
#endif
|
||||
#ifdef DISPLAY_HEX
|
||||
sprintf(buf, "%02X", b);
|
||||
#endif
|
||||
Serial.print(buf);
|
||||
b = ee.readByte(++memoryAddress);
|
||||
Serial.print(" ");
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
// END OF FILE
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
//
|
||||
// FILE: I2C_eeprom_update.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo I2C_EEPROM library - updateByte
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <I2C_eeprom.h>
|
||||
// uses a 24LC256 (32KB) EEPROM
|
||||
|
||||
#define MEMORY_SIZE 0x2000 // total bytes can be accessed 24LC64 = 0x2000 (maximum address = 0x1FFF)
|
||||
#include "Wire.h"
|
||||
#include "I2C_eeprom.h"
|
||||
|
||||
I2C_eeprom ee(0x50, MEMORY_SIZE);
|
||||
|
||||
I2C_eeprom ee(0x50, I2C_DEVICESIZE_24LC256);
|
||||
|
||||
uint32_t start, dur1, dur2;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
ee.begin();
|
||||
Serial.begin(115200);
|
||||
while (!Serial); // wait for SERIAL_OUT port to connect. Needed for Leonardo only
|
||||
|
||||
@@ -24,8 +24,15 @@ void setup()
|
||||
Serial.print("VERSION: ");
|
||||
Serial.println(I2C_EEPROM_VERSION);
|
||||
|
||||
ee.begin();
|
||||
if (! ee.isConnected())
|
||||
{
|
||||
Serial.println("ERROR: Can't find eeprom\nstopped...");
|
||||
while (1);
|
||||
}
|
||||
|
||||
Serial.println("\nTEST: determine size");
|
||||
int size = ee.determineSize();
|
||||
uint32_t size = ee.determineSize();
|
||||
if (size > 0)
|
||||
{
|
||||
Serial.print("SIZE: ");
|
||||
|
||||
Reference in New Issue
Block a user