How to read/write in the EEPROM?

Hi:

Tried to follow some guidelines, I even copied and pasted a portion of code but when the values are read, they are not the same as should have been saved.

I need to save 6 values from around 1000 and 2000 (yes RC pulse values). I understand that values are saved as bytes, so I must divide by 256 for the highbyte and store the remain for the lowbyte.

This is the code I use to write:

void writeChannelSetting(uint8_t nIndex,uint16_t unSetting)
{
    EEPROM.write(nIndex*sizeof(uint16_t),lowByte(unSetting));
    EEPROM.write((nIndex*sizeof(uint16_t))+1,highByte(unSetting));
}

But the code that reads the values does this:

void readSettingsFromEEPROM()
{
  minPulseWidthThr = readChannelSetting(EEPROM_INDEX_minPulseWidthThr); (etc.)

It seems to be reading just one byte. Is it enough to have one index per value? If the value takes two bytes, shouldn't I read two indexed positions?

is there any working example storing and reading values greater than one byte?

(etc.)

I can't believe that compiles.

it seems to be reading just one byte.

yes it does that is how it works for both read and write.
http://arduino.cc/en/Reference/EEPROM
If you want it to read or write more than one byte then you have to code it to do so using multiple EEPROM calls.

You have not posted the code for readChannelSetting(). We can only guess at what it is doing.

Yes, anyway I saw the error: he was reading just the first byte, though both (high andd low bytes were saved).

Now it works:

//  SAVE pulse width as two bytes
void writeChannelSetting(uint8_t nIndex,uint16_t unSetting)
{
    EEPROM.write(nIndex,highByte(unSetting));
    EEPROM.write(nIndex+1,lowByte(unSetting));
 }

//  READ BOTH BYTES AT INDEX nStart and nStart+1
uint16_t readChannelSetting(uint8_t nStart)
{
  uint16_t unSetting = (EEPROM.read(nStart))*256;
  unSetting += EEPROM.read(nStart+1);
  return unSetting;
}