sometimes error occour when read eeprom

for example at one address on eeprom,i store a value of 20 in decimal,but sometimes read out a value -236,and 60 read out as -196,i noticed 20 - 256 = -236, 60 - 256 = -196,but i still not know what's the really reason why this happend.

for example at one address on eeprom,i store a value of 20 in decimal

What does that mean? EEPROM stores data in binary.

but i still not know what's the really reason why this happend.

The "really" reason is that there is something wrong with your code.

Please post an example program that shows the problem so that we can all try it and give advice.

waysleehh:
i still not know what's the really reason why this happend.

And I don't know
1.) Why are you using wrong code?
2.) Why don't you show the wrong code?

If it is a "huge sketch" with "a lot of code", you probably simply run out of RAM and fully working functions provide weird results due to lack of enough free RAM.

waysleehh:
i noticed 20 - 256 = -236, 60 - 256 = -196

Possibly you are just doing wrong by mixing "unsigned" and "signed" variable types.

i just use the library functions to write and read the EEPROM.

 //write to EEPROM
 addr = (int)index * size;
 for(u8 i=0;i<size;i++)
 {
 EEPROM.write(addr, *ptr);
 addr++;
 *ptr++;
 }
    for (u8 k=0;k<sizeof(ptimer_t);k++) //ptimer has 9 members,totol 10 bytes
   {
     *p++ = EEPROM.read(addr++);
// PrintHexByte(*p);
   }
typedef struct              // struct for power timing control
{
  u8 index;
  u8 flag;
  date_time_t datetime;
  u16 interval;
}power_timer_t;

error is occour in interval.

below code is to get the interval:

	timer_string.interval = (u16)strtol(interval, &endptr, 10);

	if(timer_string.interval > 1440)
	{
		Serial.print("\r\nInterval should not exceed 1440 (24*60min)");
		return 0;
	}

jurs:
And I don't know
1.) Why are you using wrong code?
2.) Why don't you show the wrong code?

If it is a "huge sketch" with "a lot of code", you probably simply run out of RAM and fully working functions provide weird results due to lack of enough free RAM.

Possibly you are just doing wrong by mixing "unsigned" and "signed" variable types.

no! i defined clearly!

typedef unsigned char	u8;
typedef unsigned int	u16;
typedef unsigned long int	u32;

this error happened not very offen, the board produced 200pcs+ in two hardware version,the first version haven't seen such error.in the second hardware version,it happened. the different between two hardware is adding two switches and a boost power chip to the second board,is never influent the EEPROM read/write,i think.

waysleehh:
this error happened not very offen, the board produced 200pcs+ in two hardware version,the first version haven't seen such error.in the second hardware version,it happened. the different between two hardware is adding two switches and a boost power chip to the second board,is never influent the EEPROM read/write,i think.

have you tried moving the EEPROM storage location to another area in the EEPROM? maybe you have a dodgy section in EEPROM...

BulldogLowell:
have you tried moving the EEPROM storage location to another area in the EEPROM? maybe you have a dodgy section in EEPROM...

no! this error is hapenned in several boards, it's impossible that these board all have a dodgy section at the same address.

You must be casting the result of EEPROM.read() to a signed type.

MarkT:
You must be casting the result of EEPROM.read() to a signed type.

what do you mean? the prototype of EEPROM read is assigned to uint_8

uint8_t EEPROMClass::read(int address)
{
	return eeprom_read_byte((unsigned char *) address);
}

what do you mean? the prototype of EEPROM read is assigned to uint_8

We know that. If you are certain that the hardware is good, then the fault MUST be in the damned code you won't share.

Quit wasting our time. Either post ALL of the code or live with the problem.