Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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

Code:

; WRITE INTERNAL EEPROM
; Data to Write: R30
; Adress Hi Byte: R29
; Adress Lo Byte: R28
;
WRITE_EEPROM: PUSH R30 ; Store write value to stack
RCALL READ_EEPROM ; Check if value to write is same as content of EEPROM cell
MOV R31, R30 ; Move the current content of the EEPROM cell to R31
POP R30 ; Restore write value from stack
CP R30, R31 ; Compare current EEPROM content with new value
BRNE WAIT_EEWE ; If it is not equal, then write it
RET ; Don't stress EEPROM if the value is already there ...
WAIT_EEWE: SBIC EECR, EEWE ;
RJMP WAIT_EEWE ; wait until bit EEWE in EEPROM Control Register is clear
WAIT_SPMEN: IN R31, SPMCR ;
sbrc R31, SPMEN ;
RJMP WAIT_SPMEN ; wait until bit SPMEN in SPMCR is clear
OUT EEARH,R29 ; output address high
OUT EEARL,R28 ; output address low
OUT EEDR,R30 ; output data
SBI EECR,EEMWE ; set master write enable
SBI EECR,EEWE ; set EEPROM Write strobe
RET ;

;
; READ INTERNAL EEPROM
; Adress Hi Byte: R29
; Adress Lo Byte: R28
; Read Data : R30
;
READ_EEPROM: SBIC EECR,EEWE ; if EEWE not clear
RJMP READ_EEPROM ; wait more
OUT EEARH,R29 ; EEPROM address high
OUT EEARL,R28 ; EEPROM address low
SBI EECR,EERE ; set EEPROM Read strobe
IN R30,EEDR ; get data
RET ;
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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top