system
July 13, 2010, 8:19pm
1
Hi,
I'm using the external EEPROM to store readings from my accelerometer, gyroscope and magnetometer.. The details of the EEPROM are:
This is an I2C, 256Kbit, Serial Electrically Erasable PROM (EEPROM), capable of operation across a 2.5V to 5.5V range.
I'm writing the values as double to the EEPROM.. The problem is it takes about 390ms for 1 cycle while I need it to be done in a much lesser time.. Is there a way to reduce this time??
Any inputs will be much helpful..
system
July 13, 2010, 8:22pm
2
Additional Data:
I'm using 3.3V from the Arduino to drive the EEPROM as all the sensors I'm using have a max rating of 3.3V.. The EEPROM works fine with 3.3V..
I've used 10k pull up resistors on the I2C lines..
system
July 14, 2010, 9:36am
3
You only need to write data to EEPROM so that it persists when the Arduino is powered down. What data from the accelerometer, gyroscope, or magnetometer needs to be persisted? Are you writing the data only when it changes, or are you writing every time through loop? Why do you need to write so often? What does the code look like?
We need more details in order to be able to help.
system
July 22, 2010, 9:48pm
4
I have to get the data for each cycle for further analysis.. So I'm writing the values of the sensors each cycle..
I have resorted to check the timing with a simple program.. The code is given below:
#include <EEPROM.h>
#include <Wire.h>
#define disk1 0x50
double testInt[12] = {
-12.5, -10.00, -5.7, 0, 2.45, 2.90, 3.10, 4 , 5.6, 7.9, 5.5, 4};
byte noElem = 12;
unsigned int baseAddr = 0;
long currentTime = 0, lastTime = 0;
void setup() {
Serial.begin(9600);
Wire.begin();
}
void loop() {
// write float array to eeprom
// float value takes 4 bytes
// addresses are baseAddr + address every 4 bytes
for (int i=0; i < noElem-1; i++){
EEPROM_writeDouble( (i*4)+baseAddr, testInt[i]);
}
//read data back
for (int i=0; i < noElem-1; i++){
int addr = (i*4)+baseAddr;
double val = EEPROM_readDouble( addr);
Serial.println((double)val);
}
currentTime = millis();
if(currentTime - lastTime > 200)
{
warning = 1;
delay(1);
}
lastTime = currentTime;
}
void EEPROM_writeDouble(int ee, double value)
{
byte* p = (byte*)(void*)&value;
for (int i = 0; i < sizeof(value); i++)
writeEEPROM(disk1, ee++, *p++);
}
float EEPROM_readDouble(int ee)
{
double value = 0.0;
byte* p = (byte*)(void*)&value;
for (int i = 0; i < sizeof(value); i++)
*p++ = readEEPROM(disk1, ee++);
return value;
}
void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data )
{
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddress >> 8)); // MSB
Wire.send((int)(eeaddress & 0xFF)); // LSB
Wire.send(data);
Wire.endTransmission();
delay(5);
}
byte readEEPROM(int deviceaddress, unsigned int eeaddress )
{
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddress >> 8)); // MSB
Wire.send((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,1);
if (Wire.available()) rdata = Wire.receive();
return rdata;
}
Even this takes more than 350ms.. Kindly let me know wat can be done..