Hi guys,
I'm stumped here on this one. Let me give you some information of what I'm working with and what problem I'm having. Later in this post I'll post the code I'm using.
First off I've been working with FRAM from www.Ramtron.com and from what I've read in the specs document its a direct drop in replacement for EEPROM memory. I've been using the Wire library with the code samples for writing to EEPROM memory from the playground area on the main arduino site. The memory chip I'm using is the FM24C16A-G. Everything I've read in the specs file seems to fall right in line with the sample code I've got.
So here is the best way I can describe what I think is happening. First I can write to the chip without any problems. I have a function that writes an integer to two bytes of memory and then a function to read an integer from a specified location. The write function works or so it seems but the read function partially works.
In my tests I write an integer to the first two bytes in memory and then I write another integer to the next two bytes in memory. When I read it always returns the last write even when I tell it what block to go to. It's latching the last address I wrote to and all subsequent reads start there. Here is an example of my code and the results I'm getting.
#include <Wire.h>
#define _DeviceAddress B1010000 //int 80 hex 0x50
void setup() {
Serial.begin(9600);
Wire.begin();
i2c_eeprom_write_int(_DeviceAddress, 0, 1023);
i2c_eeprom_write_int(_DeviceAddress, 2, 1022);
Serial.println("Printing Result");
int read = i2c_eeprom_read_int(_DeviceAddress, 0);
Serial.println(read);
read = i2c_eeprom_read_int(_DeviceAddress, 2);
Serial.println(read);
}
void loop()
{
}
void i2c_eeprom_write_int( int deviceaddress, unsigned int eeaddress, int data ) {
Wire.beginTransmission(deviceaddress);
Wire.send((byte)highByte(eeaddress)); // MSB
Wire.send((byte)lowByte(eeaddress)); // LSB
Wire.send((byte)highByte(data));
Wire.send((byte)lowByte(data));
Wire.endTransmission();
}
int i2c_eeprom_read_int( int deviceaddress, unsigned int eeaddress ) {
byte theByteArray[2];
Wire.beginTransmission(deviceaddress);
Wire.send((int)highByte(eeaddress)); // MSB
Wire.send((int)lowByte(eeaddress)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,2);
if (Wire.available())
{
theByteArray[0] = Wire.receive();
theByteArray[1] = Wire.receive();
}
return (int)word(theByteArray[0], theByteArray[1]);
}
here is the result I get:
Printing Result
1022
1022
If I write the first integer to memory and then read what I just wrote and then write the second number to memory and then read that one I get the two individual values back.
like this...
Serial.println("Printing Result");
i2c_eeprom_write_int(_DeviceAddress, 0, 1023);
int read = i2c_eeprom_read_int(_DeviceAddress, 0);
Serial.println(read);
i2c_eeprom_write_int(_DeviceAddress, 2, 1022);
read = i2c_eeprom_read_int(_DeviceAddress, 2);
Serial.println(read);
I get this...
Printing Result
1023
1022
If I remark out the write lines and push that to the arduino and then disconnect the arduino from the usb (disconnecting it's power source) and then plug back in the usb cable and run the read only code I get the last value that was written to memory for any and all read requests. I'm going to assume by this that it is infact writing to the memory and that my issue is somewhere in the read process.
Any ideas anyone?
Thanks
John