avr and eeprom problema and how to halt cycles in programming

Status
Not open for further replies.

deepakgupta.rf

Member level 4
Joined
Jul 21, 2010
Messages
77
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Location
jaipur
Activity points
1,820
hello everyone
some time what i feel ,my atmega8535 do not read eeprom value.
it process all the work properly but sometime it not read values from eeprom.again when i do reset ,then it works proper and show numbers exactly.


for(k=0;k<=29;k++)
{
numb[k]= eeprom_read_byte(k);
delay_ms(200);
}


///// eeprom write////////////
/


void write_eeprom_byte(char address, char data)
{
// EEARH=0x00;
// EEARL = address ;

while(EECR & 0x02 == 1) ; // CHECK EEWE BIT

while( SPMCR & 0x01 == 1); // CHECK SPMEN BIT

// EEARH=0x00; // SET ADDRESS MSB BYTE
EEARL = address ; // SET LSB BYTE OF ADDRESS
EEDR = data ; // WRITE data to be written to EEPROM
EECR = 0x04 ; // SET EEMWE BIT
#asm
// nop;
// nop;

#endasm
EECR = 0x06; // SET EEMWE & EEWE BITS

while(EECR & 0x04 == 1); // CHECK EEMWE IS CLRED


// delay_ms(10); // general delay

return;


}


////// eeprom read/////////////////////////////

char eeprom_read_byte(char address)
{
char data=0;

while(EECR & 0x02 == 1) ; // check EEWE BIT IS CLRed

// EEARH=0x00; // SET MSB BYTE OF ADDRESS
EEARL = address ; // SET LSB BYTE OF ADDRESS

EECR = 0x01 ; // SET EERE BIT

#asm
// nop;
// nop;

#endasm

data = EEDR; // read data from the EEPROM

return(data); // RETURN EEPROM data value


}


so sir plz what is the basic problem
 

reading function is ok u write
if problem not solved u can write asm code in c function and also c code is given in its data sheet
anyhow

And don't forget to set these fuses:
Brown-out detection level at VCC=2.7 V
Brown-out detection enabled
or your eeprom may get corrupted during power on/off
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…