Go Down

Topic: Arduino EEPROM read (Read 512 times) previous topic - next topic

jwidz

Hello,
Is there a limit to the number of consecutive EEPROM reads which an Arduino Uno R3 can perform?
My code executes normally when performing roughly 500 consecutive reads; although, when I try to increase this number, my code uploads normally but does not function beyond that. 

Erdin

Reading is no problem. Only writing is a problem after writing the same EEPROM location 100000 times.
I think it is more likely that the limit is in your code.

retrolefty


Hello,
Is there a limit to the number of consecutive EEPROM reads which an Arduino Uno R3 can perform?
My code executes normally when performing roughly 500 consecutive reads; although, when I try to increase this number, my code uploads normally but does not function beyond that.  


Then there is some problem with your sketch code. If your storing the EEPROM read data into SRAM memory perhaps your running out of SRAM after 500 EEPROM reads. Post you code if you want help with it.

There is no physical limit on reading EEPROM memory.

Lefty

jwidz

#3
Mar 28, 2013, 04:58 pm Last Edit: Mar 29, 2013, 12:52 am by Coding Badly Reason: 1
Okay, here is the code up until the 'void loop()'. The EEPROM reading is done at the beginning of the 'void setup()'. The code works fine when the 'PHONO' variable reading is commented out.


Code: [Select]
#include <XBee.h>
#include <EEPROM.h>

XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
Rx16Response rx16 = Rx16Response();
Rx64Response rx64 = Rx64Response();

int c=0;
int pin;
int n = 0;
int k = 0;
byte x;
int data = 1;

byte ECG[170];
byte BP[170];
byte PAP[170];
byte PHONO[170];
byte PHONO_mod[170];
byte BP_mod[170];
byte ECG_mod[170];
byte PAP_mod[170];
int maxIndex = 0;
int minIndex = 0;

int CS = 10;
int WR = 11;
int LDAC = 12;
int RESET = 13;

int LE = A5;
int E1 = A4;
int E2 = A3;
int S0 = A2;
int S1 = A1;
int S2 = A0;

int D;
int Spike;
double option;
double HR;
double ArPr_SYS;
double ArPr_DYS;
double ArPr_change;
double Plum;
double Air_max;
double Air_min;
double Vent_rate;
double Air_pr;
double Phn_time;
double Phn_inten;





void setup() {
 
 pinMode(2, OUTPUT);
 pinMode(3, OUTPUT);
 pinMode(4, OUTPUT);
 pinMode(5, OUTPUT);
 pinMode(6, OUTPUT);
 pinMode(7, OUTPUT);
 pinMode(8, OUTPUT);
 pinMode(9, OUTPUT);
 pinMode(RESET, OUTPUT);
 pinMode(LDAC, OUTPUT);
 pinMode(WR, OUTPUT);
 pinMode(CS, OUTPUT);
 
 pinMode(LE, OUTPUT);
 pinMode(E1, OUTPUT);
 pinMode(E2, OUTPUT);
 pinMode(S0, OUTPUT);
 pinMode(S1, OUTPUT);
 pinMode(S2, OUTPUT);
 

 for(int address = 50;address < 220; address++){
   ECG[n] = ECG_mod[n] = EEPROM.read(address);
   //Serial.print(ECG[n]);
   //Serial.println();
   n = n+1;
   
 }
       
   for(int address = 221;address < 391; address++){
   BP[k] = BP_mod[k] = EEPROM.read(address) - 35;
   //Serial.print(BP[k]);
   //Serial.println();
   k = k+1;
   
 }
 
 k = 0;
 for(int address = 392;address < 563; address++){
   PAP[k] = PAP_mod[k] = EEPROM.read(address);
   //Serial.print(PAP[k]);
   Serial.print(data);
   //Serial.println();
   k = k+1;
   
 }
k = 0;
 for(int address = 565;address < 735; address++){
   PHONO[k] = PHONO_mod[k] = EEPROM.read(address);
   //Serial.print(PHONO[k]);
   //Serial.println();
   k = k+1;
   
 }*/

 
 
 int maxi = BP[maxIndex];
 for (int c=1; c<171; c++){
   if (maxi<BP[c]){
     maxi = BP[c];
     maxIndex = c;
   }
 }
   //Serial.println(BP[maxIndex]);
   //Serial.println(maxIndex);

 
 int mini = BP[minIndex];
 for (int c=1; c<171; c++){
   if (mini>BP[c]){
     mini = BP[c];
     minIndex = c;
   }
 }
   //Serial.println(BP[minIndex]);
   //Serial.println(minIndex);

digitalWrite(RESET, HIGH);
digitalWrite(CS, HIGH);
digitalWrite(LDAC, HIGH);
digitalWrite(WR, HIGH);

digitalWrite(S0, LOW);
digitalWrite(S1, LOW);
digitalWrite(S2, LOW);
digitalWrite(E1, LOW);
digitalWrite(E2, HIGH);
digitalWrite(LE, HIGH);


 Serial.begin(57600);
 xbee.setSerial(Serial);
 
 
}



Moderator edit: [code] [/code] tags added.

jwidz

#4
Mar 28, 2013, 04:59 pm Last Edit: Mar 29, 2013, 12:52 am by Coding Badly Reason: 1
And here is the other section of the code beginning at the 'void loop()'.

Code: [Select]
void loop() {
   

   
   
   
     while(data == 1){
      for (int i=0; i<170; i++){
   
   
   // Arterial Blood Pressure; Channel # 0
   digitalWrite(CS, LOW);
   digitalWrite(WR, LOW);
   output_DATA(BP_mod, i);
   digitalWrite(WR, HIGH);
   digitalWrite(CS, HIGH);
   digitalWrite(LDAC, LOW);
   digitalWrite(LE, HIGH);
   digitalWrite(S0, LOW);
   digitalWrite(WR, LOW);
   digitalWrite(LE, LOW);
   digitalWrite(WR, HIGH);
   digitalWrite(LDAC, HIGH);
   
//GONEEEEEEEEEEEEEEEE

    // ECG; Channel # 2  
   digitalWrite(CS, LOW);
   digitalWrite(WR, LOW);
   output_DATA(ECG_mod, i);
   digitalWrite(WR, HIGH);
   digitalWrite(CS, HIGH);
   digitalWrite(LDAC, LOW);
   digitalWrite(LE, HIGH);
   digitalWrite(S1, HIGH);
   digitalWrite(WR, LOW);
   digitalWrite(WR, HIGH);
   digitalWrite(LE, LOW);
   digitalWrite(LDAC, HIGH);
 
    // Pulnomary Artery Pressure; Channel # 3
   digitalWrite(CS, LOW);
   digitalWrite(WR, LOW);
   output_DATA(PAP_mod, i);
   digitalWrite(WR, HIGH);
   digitalWrite(CS, HIGH);
   digitalWrite(LDAC, LOW);
   digitalWrite(LE, HIGH);
   digitalWrite(S0, HIGH);
   digitalWrite(WR, LOW);
   digitalWrite(LE, LOW);
   digitalWrite(WR, HIGH);
   digitalWrite(LDAC, HIGH);
   
    // Phonocardiogram ; Channel # 7
   digitalWrite(CS, LOW);
   digitalWrite(WR, LOW);
   output_DATA(ECG_mod, i);
   digitalWrite(WR, HIGH);
   digitalWrite(CS, HIGH);
   digitalWrite(LDAC, LOW);
   digitalWrite(LE, HIGH);
   digitalWrite(S2, HIGH);
   digitalWrite(WR, LOW);
   digitalWrite(LE, LOW);
   digitalWrite(WR, HIGH);
   digitalWrite(LDAC, HIGH);
   
   // Airway Pressure ; Channel # 1
   digitalWrite(CS, LOW);
   digitalWrite(WR, LOW);
   output_DATA(PAP_mod, i);
   digitalWrite(WR, HIGH);
   digitalWrite(CS, HIGH);
   digitalWrite(LDAC, LOW);
   digitalWrite(LE, HIGH);
   digitalWrite(S1, LOW);
   digitalWrite(S2, LOW);
   digitalWrite(WR, LOW);
   digitalWrite(LE, LOW);
   digitalWrite(WR, HIGH);
   digitalWrite(LDAC, HIGH);
   
   
  xbee.readPacket();
  if(xbee.getResponse().isAvailable()){data = 0; break;}
   

     }
   }  
   
   
   if (xbee.getResponse().getApiId() == RX_16_RESPONSE) {
               xbee.getResponse().getRx16Response(rx16);
        option = rx16.getOption();
        D = rx16.getData(0);
               
                if (D == 1){
               //option = rx16.getOption();
       
                     HR = rx16.getData(1);
                     ArPr_SYS = rx16.getData(2) - 35;
                     ArPr_DYS = rx16.getData(3) - 35;
                     ArPr_change = rx16.getData(4) * 10;
                     Plum = rx16.getData(5);
                     Air_max = rx16.getData(6);
                     Air_min = rx16.getData(7);
                     Vent_rate = rx16.getData(8);
                     Air_pr = rx16.getData(9);
                     Phn_time = rx16.getData(10);
                     Phn_inten = rx16.getData(11);
                     
                     Serial.print("heart rate is  ");
                     Serial.println(HR);
                     Serial.print("Arterial Pressure Systole  " );
                     Serial.println(ArPr_SYS);
                     Serial.print("Arterial Pressure Dystole  ");
                     Serial.println(ArPr_DYS);
                     Serial.print("Arterial Pressure rate of change  ");
                     Serial.println(ArPr_change);
                     Serial.print("Pulmonary  ");
                     Serial.println(Plum);
                     Serial.print("Airway pressure MAX  ");
                     Serial.println(Air_max);
                     Serial.print("Airway Pressure MIN  ");
                     Serial.println(Air_min);
                     Serial.print("Ventalation rate  ");
                     Serial.println(Vent_rate);
                     Serial.print("Airway Presure  ");
                     Serial.println(Air_pr);
                     Serial.print("Phonocardiogram timing  ");
                     Serial.println(Phn_time);
                     Serial.print("Phonocardiogram intense  ");
                     Serial.println(Phn_inten);
                     
                     
               }
               else if (D == 2){
                   for (int h = 0; h<85; h++){
                     
                     ECG_mod[h] = rx16.getData(h+1);
                     Serial.println(rx16.getData(h+1));
                   }
               }
               else if (D == 3){
                   for (int h = 85; h<170; h++){
                     
                     ECG_mod[h] = rx16.getData(h-84);
                     Serial.println(rx16.getData(h-84));
                   }
               }
               else if (D == 4){Serial.println("ERROR 4");}
               else if (D == 5){Serial.println("ERROR 5");}
               else if (D == 6){Serial.println("ERROR 6");}
               else if (D == 7){Serial.println("ERROR 7");}
               else if (D == 8){Serial.println("ERROR 8");}
               else if (D == 9){Serial.println("ERROR 9");}
               else if (D == 10){Serial.println("ERROR 10");}
               else if (D == 11){Serial.println("ERROR 11");}
               else if (D == 12){Serial.println("ERROR 12");}
               else if (D == 13){
                   
                   Spike = rx16.getData(1);
                     HR = rx16.getData(2);
                     ArPr_SYS = rx16.getData(3) - 35;
                     ArPr_DYS = rx16.getData(4) - 35;
                     ArPr_change = rx16.getData(5) * 10;
                     Plum = rx16.getData(6);
                     Air_max = rx16.getData(7);
                     Air_min = rx16.getData(8);
                     Vent_rate = rx16.getData(9);
                     Air_pr = rx16.getData(10);
                     Phn_time = rx16.getData(11);
                     Phn_inten = rx16.getData(12);
                     
                     ECG_mod[Spike] = 255;
                     BP_mod[Spike] = 255;
                     ECG_mod[Spike+1] = 0;
                     BP_mod[Spike+1] = 0;
               }
       
               
       
       data = 1;        
               
       }
               
       
    else if (xbee.getResponse().isError()) {
     
      data = 1;
     Serial.println("NO RESPONSE");
     //nss.print("Error reading packet.  Error code: ");  
     //nss.println(xbee.getResponse().getErrorCode());
     // or flash error led
   }
 
 

}
void output_DATA (byte signal[], int point){

    pin = 2;
    for(int n=0;n<8;n++){

       if(bitRead(signal[point],n)==1){ digitalWrite(pin, HIGH);}
       else {digitalWrite(pin, LOW);}
    pin = pin +1;
   }
   
}



Moderator edit: [code] [/code] tags added.

retrolefty

Posted code should be pasted into # window.

Your simply using too much SRAM, the Uno has only 2KB avalible in total and you are using up 1,360 just on your byte arrays alone:

Code: [Select]

byte ECG[170];
byte BP[170];
byte PAP[170];
byte PHONO[170];
byte PHONO_mod[170];
byte BP_mod[170];
byte ECG_mod[170];
byte PAP_mod[170];


Quote

SRAM   2 KB (ATmega328)

You need to be aware of the resources available on your micro-controller.

Lefty

Go Up