Internal Arduino EEPROM resetting on address 1 when saving to address 0


hello everyone! had curious problem piece of code.

code: [select]
#include <eeprom.h>

char command = 'a';
int num = 0;
int highaddress = 1;
int highlimit;
int lowaddress = 0;
int lowlimit;

void setup()
{
  serial.begin(9600);
  serial.println("ready work");

  serial.print("highlimit = ");
  serial.println(eeprom.read(highaddress));

  serial.print("lowlimit = ");
  serial.println(eeprom.read(lowaddress));
}

void userinterface()
{
    while (serial.available() > 0)
    {
      if (serial.available() > 0)
      {
        command = serial.read();
        //serial.println(command);
     
         num = serial.parseint();
         //serial.println(num);
     
         switch (toupper(command))
         {
          case 'l':
            serial.println("inside l");
            lowlimit = num;
            setlowlimit();
            break;
          case 'h':
            serial.println("inside h");
            highlimit = num;
            sethighlimit();
            break;
          default:
            serial.print("sorry \"");
            serial.print(command);
            serial.println("\" not valid command, try again.");
            break;
         }
      }
    }
}

void setlowlimit()
{
  if (lowlimit < 0)
  {
    serial.println("your low limit must number between 0 , 100");
   
    return;
  }
 
  if (lowlimit > 100)
  {
    serial.println("your low limit must number between 0 , 100");
   
    return;
  }
 
  if (eeprom.read(highaddress) < lowlimit)
  {
    serial.print("your desired low limit of ");
    serial.println(lowlimit);
    serial.print("is set higher high limit of ");
    serial.print(eeprom.read(highaddress));
    serial.println(".");
    serial.println("please input different limit setting.");

    return;
  }
 
  eeprom.put(lowaddress, lowlimit);
  lowlimit = eeprom.read(lowaddress);
  serial.print("the value of ");
  serial.print(eeprom.read(lowaddress));
  serial.println(" has been stored in eeprom memory at");
  serial.print("the address ");
  serial.print(lowaddress);
  serial.println(".");

  return;
}

void sethighlimit()
{
  if (highlimit < 0)
  {
    serial.println("your high limit must number between 0 , 100");
   
    return;
  }
 
  if (highlimit > 100)
  {
    serial.println("your high limit must number between 0 , 100");
   
    return;
  }
 
  if (eeprom.read(lowaddress) > highlimit)
  {
    serial.print("your desired high limit of ");
    serial.println(highlimit);
    serial.print("is set lower low limit of ");
    serial.print(eeprom.read(lowaddress));
    serial.println(".");
    serial.println("please input different limit setting.");

    return;
  }
 
  eeprom.put(highaddress, highlimit);
  highlimit = eeprom.read(highaddress);
  serial.print("the value of ");
  serial.print(eeprom.read(highaddress));
  serial.println(" has been stored in eeprom memory at");
  serial.print("the address ");
  serial.print(highaddress);
  serial.println(".");

  return;
}

void loop()
{
  lowlimit = eeprom.read(lowaddress);
  highlimit = eeprom.read(highaddress);

  userinterface();

  return;
}


when type in highlimit, things go swimmingly , serial port tells me command has been saved. when set lowlimit, every time resets highlimit 0. (this can evident when 1 shuts down serial port right after setting lowlimit , opening program see both address limits set 0). changed address of lowlimit saved 2 , program worked expected.

even though solved problem got me curious. why did saving "0" address of eeprom storage reset "1" address of eerom storage 0. thought must have been eeprom using either address 0 or address 1 write memory. looked datasheet @ address:

http://www.atmel.com/images/atmel-8271-8-bit-avr-microcontroller-atmega48a-48pa-88a-88pa-168a-168pa-328-328p_datasheet_complete.pdf

but have not found validate thoughts. although datasheet long have missed something. have looked @ several other places on internet, including site , other forums see if specs on arduino explain have found nothing relating topic. in fact many of examples of eeprom storage on website use address 0 of eeprom store things , not mention caveats it.

does have ideas might have caused this?


how many bytes needed store int?



Arduino Forum > Using Arduino > Programming Questions > Internal Arduino EEPROM resetting on address 1 when saving to address 0


arduino

Comments

Popular posts from this blog

Valutazione Template - Joomla! Forum - community, help and support

SD Datastring Convention

First use of Arduino Uno : avrdude error on Blink uploading