EEPROM doesn't respond

This is a discussion on EEPROM doesn't respond within the C Programming forums, part of the General Programming Boards category; Hello friends, this is a test program I'm writing to get eeprom to read back a couple of long integers. ...

  1. #1
    Registered User
    Join Date
    May 2011
    Location
    Toronto
    Posts
    20

    EEPROM doesn't respond

    Hello friends, this is a test program I'm writing to get eeprom to read back a couple of long integers. So far, I incremented up a few hundred clicks, (because I could not load 45,000 on startup) then started the chip again, I had in memory say "235" and "188" i.e. When I restart, the numbers comes back for a few loops then it goes to 61 and 120, then sits there. Restarting only reloads these two values, no matter if I change them. Can't get anything to write.

    I have to store a 5 or 6 digit in memory and retrieve it, change it, put it back, etc. So this is not working. The print lines are for debugging.


    Code:
    #include <EEPROM.h>
    
    const int buttonPin3 = 3;   
    const int buttonPin4 = 4;    
    const int buttonPin5 = 5;
      
    int button3 = 0; 
    int button4 = 0;
    int button5 = 0;
    
    
    long y2 = 45000;
    long y1 = 15000;
    long oldy2;
    long oldy1;
    
    
    void setup() {
    
       
      pinMode(buttonPin3, INPUT); 
      pinMode(buttonPin4, INPUT); 
      pinMode(buttonPin5, INPUT);
    
      Serial.begin(9600); 
       byte addr1;
       byte addr2;
      y2 = EEPROM.read(20);   
      y1 = EEPROM.read(10);
     
     
      Serial.println(y2, DEC);
      Serial.println(y1, DEC); 
      
    }
     void loop()
     {
    
      Serial.println(y2, DEC);
      Serial.println(y1, DEC);
      delay(10);
      button3 = digitalRead(buttonPin3); // reading the buttons.
      button4 = digitalRead(buttonPin4);
      button5 = digitalRead(buttonPin5);
      
            if(button3 == HIGH)
               {
               y2 = y2 + 1;                       // incrementing
               byte addr2;
               oldy2 = EEPROM.read(addr2);    //compare old and new value
               if(y2 != oldy2)
                  {
                   byte addr2;                       
                   EEPROM.write(addr2, y2);     // write in eeprom
                   Serial.println(y2, DEC);
                   delay(100);
                  }
               }
               
             if(button4 == HIGH) 
               {
                y1 = y1 + 1;
                byte addr1;
                oldy1 = EEPROM.read(addr1);
                if(y1 != oldy1)
                  {
                   byte addr1;    
                   EEPROM.write(addr1, y1);
                   Serial.println(y1, DEC);
                   delay(100);
                  }
               }  
       }
    Last edited by RobertD; 05-26-2011 at 02:58 PM.

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,676
    Care to give us anything useful, like what microcontroller you're using, what eeprom, a wiring schematic and the rest of your code, or at least a main function?

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Quote Originally Posted by anduril462 View Post
    Care to give us anything useful, like what microcontroller you're using, what eeprom, a wiring schematic and the rest of your code, or at least a main function?
    Looks like its for the arduino so there wont be a main function unless he/she's compiling directly with the gcc cross compiler.

    >>byte addr2;
    >>oldy2 = EEPROM.read(addr2);

    You are declaring a stack variable and not initialising it. That means whatever value is in it is pretty much garbage when you pass it to read as the address variable. It might be 20, it might be 328, if you dont initialise, then you cant complain that you get garbage out the other end

  4. #4
    Registered User
    Join Date
    May 2011
    Location
    Toronto
    Posts
    20
    It's atmega 328.

    This is all the code I wrote to familiarize myself with eeprom operation.

    Seems I definitely have to initialize .

    How do I initialize the EEPROM...?

    Would it be something like:

    Code:
      byte addr2; 
     *addr2 = 20;
    OK seems to be working now...

    byte addr2 = 30;

    Thanks a million...
    Last edited by RobertD; 05-26-2011 at 04:40 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sturcture to memory eeprom
    By RocketMan in forum C Programming
    Replies: 3
    Last Post: 11-16-2009, 02:10 PM
  2. respond to button
    By algi in forum Windows Programming
    Replies: 2
    Last Post: 03-19-2005, 10:28 PM
  3. Dialog doesn't respond to tab key
    By dhaupt in forum Windows Programming
    Replies: 8
    Last Post: 08-11-2004, 01:41 PM
  4. server won't respond...
    By Sebastiani in forum C++ Programming
    Replies: 11
    Last Post: 10-19-2002, 10:09 PM
  5. Respond
    By whistlenm1 in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 02-02-2002, 02:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21