Initial Commit from upstream - v1.4

This commit is contained in:
2019-07-04 09:23:44 -07:00
commit 833823dbeb
30 changed files with 5391 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
/*
E24C1024.cpp
AT24C1024 Library for Arduino
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 US
This library is based on several projects:
The Arduino EEPROM library found here:
http://arduino.cc/en/Reference/EEPROM
The 24C256 library found here:
http://www.arduino.cc/playground/Code/I2CEEPROM
The 24C512 library found here:
http://www.arduino.cc/playground/Code/I2CEEPROM24LC512
Our project page is here:
http://www.arduino.cc/playground/Code/I2CEEPROM24C1024
From the datasheet:
The AT24C1024B provides 1,048,576 bits of serial electrically
erasable and programmable read only memory (EEPROM) organized
as 131,072 words of 8 bits each. The device<63>s cascadable
feature allows up to four devices to share a common two-wire
bus.
http://www.atmel.com/dyn/resources/prod_documents/doc5194.pdf
*/
#include <Wire.h>
#include <Arduino.h>
#include "E24C1024.h"
E24C1024::E24C1024(void)
{
Wire.begin();
}
void E24C1024::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 E24C1024::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(0x50,1);
if (Wire.available()) data = Wire.read();
return data;
}
E24C1024 EEPROM1024;

View File

@@ -0,0 +1,62 @@
#ifndef E24C1024_h
#define E24C1024_h
/*
E24C1024.h
AT24C1024 Library for Arduino
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 US
This library is based on several projects:
The Arduino EEPROM library found here:
http://arduino.cc/en/Reference/EEPROM
The 24C256 library found here:
http://www.arduino.cc/playground/Code/I2CEEPROM
The 24C512 library found here:
http://www.arduino.cc/playground/Code/I2CEEPROM24LC512
Our project page is here:
http://www.arduino.cc/playground/Code/I2CEEPROM24C1024
From the datasheet:
The AT24C1024B provides 1,048,576 bits of serial electrically
erasable and programmable read only memory (EEPROM) organized
as 131,072 words of 8 bits each. The device<63>s cascadable
feature allows up to four devices to share a common two-wire
bus.
http://www.atmel.com/dyn/resources/prod_documents/doc5194.pdf
*/
//#include <WConstants.h>
#include <Wire.h>
#define FULL_MASK 0x7FFFF
#define DEVICE_MASK 0x7F0000
#define WORD_MASK 0xFFFF
class E24C1024
{
public:
E24C1024();
static void write(unsigned long, uint8_t);
static uint8_t read(unsigned long);
};
extern E24C1024 EEPROM1024;
#endif

View File

@@ -0,0 +1,115 @@
/*
EEPROM1024.pde
AT24C1024 EEPROM Benchmark Sketch
Our project page is here:
http://www.arduino.cc/playground/Code/I2CEEPROM24C1024
From the datasheet:
The AT24C1024B provides 1,048,576 bits of serial electrically
erasable and programmable read only memory (EEPROM) organized
as 131,072 words of 8 bits each. The devices cascadable
feature allows up to four devices to share a common two-wire
bus.
http://www.atmel.com/dyn/resources/prod_documents/doc5194.pdf
*/
#include <WProgram.h>
#include <Wire.h>
#include <E24C1024.h>
unsigned long time;
unsigned long finishTime;
unsigned long errors = 0;
unsigned long address = 0;
byte loop_size;
// Set to a higher number if you want to start at a higher address.
#define MIN_ADDRESS 0
// Upper boundary of the address space. Choose one.
#define MAX_ADDRESS 131072 // 1 device
//#define MAX_ADDRESS 262144 // 2 devices
//#define MAX_ADDRESS 393216 // 3 devices
//#define MAX_ADDRESS 524288 // 4 devices
void setup()
{
// Make sure we aren't reading old data
randomSeed(analogRead(0));
loop_size = random(1, 100);
Serial.begin(9600);
Serial.println();
Serial.println("E24C1024 Library Benchmark Sketch");
Serial.println();
writeByByteTest();
readByByteTest();
}
void loop()
{
}
void writeByByteTest()
{
time = millis();
errors = 0;
Serial.println("--------------------------------");
Serial.println("Write By Byte Test:");
Serial.println();
Serial.print("Writing data:");
for (address = MIN_ADDRESS; address < MAX_ADDRESS; address++)
{
EEPROM1024.write(address, (uint8_t)(address % loop_size));
if (!(address % 5000)) Serial.print(".");
}
finishTime = millis() - time;
Serial.println("DONE");
Serial.print("Total Time (seconds): ");
Serial.println((unsigned long)(finishTime / 1000));
Serial.print("Write operations per second: ");
Serial.println((unsigned long)(MAX_ADDRESS / (finishTime / 1000)));
Serial.println("--------------------------------");
Serial.println();
}
void readByByteTest()
{
time = millis();
errors = 0;
Serial.println("--------------------------------");
Serial.println("Read By Byte Test:");
Serial.println();
Serial.print("Reading data:");
for (address = MIN_ADDRESS; address < MAX_ADDRESS; address++)
{
uint8_t data;
data = EEPROM1024.read(address);
if (data != (uint8_t)(address % loop_size))
{
Serial.println();
Serial.print("Address: ");
Serial.print(address);
Serial.print(" Should be: ");
Serial.print((uint8_t)(address % loop_size), DEC);
Serial.print(" Read val: ");
Serial.println(data, DEC);
errors++;
}
if (!(address % 5000)) Serial.print(".");
}
finishTime = millis() - time;
Serial.println("DONE");
Serial.println();
Serial.print("Total Test Time (secs): ");
Serial.println((unsigned long)(finishTime / 1000));
Serial.print("Read operations per second: ");
Serial.println((unsigned long)(MAX_ADDRESS / (finishTime / 1000)));
Serial.print("Total errors: ");
Serial.println(errors);
Serial.println("--------------------------------");
Serial.println();
}