I am having trouble accessing the EEPROM. The following testcode code works fine for TESTLEN of up to 256 but does strange things in the first byte of each pair for TESTLEN 512 an up.
The first byte seems to get some bits stuck at '1'. This doesn't make much sense on a serial device.
I have the RTC module connected to an Arduino mini and the RTC functions work fine (although the RTC does seem to run slowly when on battery, loosing several seconds per minute!)
Help would be appreciated
Code: Select all
/* Include the wire library */
#include "Wire.h"
/* Include the Hobby Components RTC library */
#include <HCRTC.h>
/* Define the I2C addresses for the RTC and EEPROM */
#define I2CDS1307Add 0x68
#define I2C24C32Add 0x50
#define TESTLEN (256)
unsigned int index,i,j;
byte h,l;
/* Create an instance of HCRTC library */
HCRTC HCRTC;
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println("");
/************* Example write to EEPROM ***************/
j=0;
for (index = 0; index < TESTLEN; index++)
{
HCRTC.EEStartWrite(I2C24C32Add, index*16);
// Sequentially write example data to the EEPROM
for (i=0;i<8;i++) {
h = (byte)(j>>8);
l = (byte)(j & 0xff);
HCRTC.EEWriteByte(h);
HCRTC.EEWriteByte(l);
Serial.print(h);
Serial.print(":");
Serial.println(l);
j++;
}
// End the write sequence
HCRTC.EEEndWrite();
// Wait for cached data to finish writing
delay(10);
}
Serial.println("done writing");
/************* Example read from EEPROM ***************/
j=0;
for (index = 0; index < TESTLEN; index++)
{
HCRTC.EEStartRead(I2C24C32Add, index*16);
// Sequentially write example data to the EEPROM
for (i=0;i<8;i++) {
Serial.print(HCRTC.EEReadByte(I2C24C32Add));
Serial.print(",");
Serial.println(HCRTC.EEReadByte(I2C24C32Add));
}
}
Serial.println("done reading!");
while(1);
}