EEPROM write more than 256 bytes

Hello,

Does anyone had troubles writing more than 256 byte to EEPROM?
If i write less than 256 bytes everything is ok, but when i try to write more
it stops at 13.
I'm using an ATMega 328P with Optiboot as an Arduino UNO, but the same behavior
i get on a Duemilanove

void RomWrite(unsigned int Idx,unsigned int Val)
{
  Idx *= 2;//int is 2 bytes
  EEPROM.write(Idx + 1,Val & 0xFF);
  Val/=256;
  EEPROM.write(Idx + 0,Val & 0xFF);
}
void ResetEEPROM(int idx)
{
  RomWrite(idx + ROM_Sequence, 0);//Sequence Off=0/On=1
  RomWrite(idx + ROM_SDelay, 10);//Sequence Delay 0-9999[ms] between Shutter1 and Shutter2 if ROM_Sequence=1
  RomWrite(idx + ROM_Bulb, 60);//Exposure in Bulb Mode[s] 0-3599
  RomWrite(idx + ROM_BulbProc, 120);//Processing time in Bulb Mode[s] 0-7199
  RomWrite(idx + ROM_TLH, 0);//Timelapse Hours interval [h] 0-23
  RomWrite(idx + ROM_TLM, 0);//Timelapse Minutes interval [min] 0-59
  RomWrite(idx + ROM_TLS, 30);//Timelapse Seconds interval [s] 0-59
  RomWrite(idx + ROM_TLW, 1);//Timelapse WakeUp interval - activate camera focus to get it out from standBy [s] 0-59
  RomWrite(idx + ROM_TLB, 0);//Timelapse UseBulb 0=No/1=Yes (setting from bulb menu)
  RomWrite(idx + ROM_TLN, 5);//Timelapse Number of Frames 0-999
  RomWrite(idx + ROM_S1_TrigAt, 0);//Sensor1 trigger at 0=Low/1=High Value
  RomWrite(idx + ROM_S1_Threshold, 512);//Sensor1 trigger value 0-1023
  RomWrite(idx + ROM_S2_TrigAt, 0);//Sensor2 trigger at 0=Low/1=High Value
  RomWrite(idx + ROM_S2_Threshold, 512);//Sensor2 trigger value 0-1023
  RomWrite(idx + ROM_D1_TrigBy, 0);//Device1 is triggered by 0=None/1=Sensor1/2=Sensor2
  RomWrite(idx + ROM_D1_Delay, 10);//Delay between Device1 and his trigger [ms] 0-9999
  RomWrite(idx + ROM_D1_Cycle, 100);//Device1 Period to wait until next picture[ms]0-9999
  RomWrite(idx + ROM_D2_Mode, 0);//Device2 type 0=None,1=Camera,2=Flash,3=Split
  RomWrite(idx + ROM_D2_TrigBy, 0);//Device2istriggeredby0=None/1=Sensor1/2=Sensor2
  RomWrite(idx + ROM_D2_Delay, 10);//Delay between Device2 and his trigger [ms] 0-9999
  RomWrite(idx + ROM_D2_Cycle, 100);//Device2 Period to wait until next picture[ms] 0-9999
  RomWrite(idx + ROM_D2_SpitTime, 10);//Delay between Device2 Shutter and Device2 Focus
  RomWrite(idx + ROM_HDR_Exp, 45);//This is the index of Exposure time in HDR mode [ms] from the array
  RomWrite(idx + ROM_HDR_Inc, 11);//0-11 Size of EV
  RomWrite(idx + ROM_HDR_Img, 3);//3-17No of frames in HDR Mode
  RomWrite(idx + ROM_Target_Dist, 100);//0-9999 [cm]
  RomWrite(idx + ROM_Gravity, 0);//0-Off 1-On
  RomWrite(idx + ROM_Drop1_Size, 80);//0-999 [ms]
  RomWrite(idx + ROM_Drops_Delay, 0);//0-999 [ms]
  RomWrite(idx + ROM_Drop2_Size, 0);//0-999 [ms]
  RomWrite(idx + ROM_Photo_Delay, 200);//0-999 [ms]
  RomWrite(idx + ROM_Contrast, 50);
  RomWrite(idx + ROM_BtnDelay, 5);
  RomWrite(idx + ROM_ClipLen, 60);//0-999 [s]
  RomWrite(idx + ROM_FrameRate, 25);//0-60 [frames/sec]
  RomWrite(idx + ROM_FrameInterval, 5);//0-999 [s]
  RomWrite(idx + ROM_ClipHDR, 0);//0=Off; 1=On
  RomWrite(idx + ROM_HDRBtnDelay, 1000);//0-5000 [ms] how long a button will be kept pressed
  RomWrite(idx + ROM_DelH, 0);//Time to wait before shooting[h]0-23
  RomWrite(idx + ROM_DelM, 0);//Time to wait before shooting[min]0-59
  RomWrite(idx + ROM_DelS, 0);//Time to wait before shooting[s]0-59
  RomWrite(idx + ROM_MLU, 0);//Mirror LookUp
  RomWrite(idx + ROM_MLU_Delay, 100);//Wait time for vibrations to end 0-999[ms]
}

where idx is 0, 1 or 2

gvi70000,
what are the values of ROM_Sequence , ROM_Delay ... etc?
also, what is the purpose of idx = 0, 1, 2 ... ?

Why bother with all the variables - why not just group them into a structure?

gvi70000:
...when i try to write more
it stops at 13....

What the heck does that mean?

Suggestion: Write a complete small sketch that tries to write to various addresses in the range 0-1023. Read the values back and see what happens.

#include <EEPROM.h>


void setup()
{
    Serial.begin(9600);
    
    EEPROM.write(0, 111);
    EEPROM.write(128, 222);
    EEPROM.write(256, 123);
    EEPROM.write(384, 234);
    EEPROM.write(1023, 42);

    printEEPROMData(0);
    printEEPROMData(128);
    printEEPROMData(256);
    printEEPROMData(384);
    printEEPROMData(1023);
}

void loop() {}
  
  
void printEEPROMData(unsigned int addr)
{
    unsigned char val = EEPROM.read(addr);
    Serial.print("EEPROM(");Serial.print(addr);Serial.print(") = ");
    Serial.println(val,DEC);
}

Output:


[color=blue]EPROM(0) = 111
EEPROM(128) = 222
EEPROM(256) = 123
EEPROM(384) = 234
EEPROM(1023) = 42[/color]

Modify this to use your integer write function and give it specific values of Idx and val. Put print statements to see the actual addresses being used. See if you can read them back.

Then go back to your sketch and see what it is trying to do and when.

You can use print statements at strategic points in the program to tell you the address and data that it is trying to write.

Stuff like that.

Regards,

Dave

#define ROM_Sequence 0//Sequence Off=0/On=1
#define ROM_SDelay 1//Sequence Delay 0-9999[ms] between Shutter1 and Shutter2 if ROM_Sequence=1
#define ROM_Bulb 2//Exposure in Bulb Mode 0-3599
#define ROM_TLH 3//Time lapse Hours interval 0-23
#define ROM_TLM 4//Timelapse Minutes interval[min]0-59
#define ROM_TLS 5//Timelapse Seconds interval0-59
#define ROM_TLW 6//Timelapse WakeUp interval activate camera focus to get it out from StandBy 0-59
....
#define ROM_MLU 42//Mirror LookUp 0-Off/1-On
#define ROM_MLU_Delay 43//Wait time for vibrations to end 0-999[ms]
0,1 and 2 are profiles. For each profile there is a set of parameters (integers) defined by an index 0 to 43(41) so there is a total
of 4223 =258 bytes +1(the current profile is stored at 0)
If i stop to 41 it works, if i add more parameters then the write to eeprom stops at 13 :~
I did try a sketch to write values from 0 to 512 and it works
Seems to be a bug in optiboot because when the sketch exceeds 28800 bytes i get this behavior even if maximum is 32256 bytes
Anyway, i remove some parameters from definitions to keep the number at 41
~~PS: for a better understanding see this link http://www.grozeaion.com/Electronics/RCV3/GVI_DSLR_RC_V3R2.zip~~

... the 28K limit given 32K of flash memory had me going sideways as well ...
It turns out the 'other' 4K is consumed by the bootloader. It has to go somewhere - and flash memory is where it resides.

So ... for most of us, the Uno really provides 28K usable flash memory space.

Really nifty/advanced users could over-write or replace the bootloader, but you'd have to have a really compelling reason to drive through that zone of complexity.