ATMEGA16-EEPROM PROBLEM
Discussion in "Project Doubts" started by kathirdot Mar 18, 2013.
Mon Mar 18 2013, 05:34 pm
In my project i want to write some values to eeprom.Problem is when reading the eeprom the value comes 255 or 0xFF.The code is,
#define F_CPU 16000000UL
#include<avr/io.h>
#include<util/delay.h>
#include<avr/eeprom.h>
#include<util/interrupt.h>
void EEPROM_write(unsigned int Address, unsigned int Data);
unsigned int EEPROM_read(unsigned int Address);
unsigned int c=0;
int main(void)
{
EEPROM_write(0x01,0x07);
_delay_ms(50);
c=EEPROM_read(0x01);
_delay_ms(50);
while(1)
{
To_7seg(c);
}
}
void EEPROM_write(unsigned int Address,unsigned int Data)
{
while(EECR & (1<<EEWE));
EEAR = Address;
EEDR = Data;
EECR |= (1<<EEMWE);
EECR |= (1<<EEWE);
}
unsigned int EEPROM_read(unsigned int Address)
{
while(EECR & (1<<EEWE));
EEAR = Address;
EECR |= (1<<EERE);
return(EEDR);
}
kindly give the solution for this problem....
#define F_CPU 16000000UL
#include<avr/io.h>
#include<util/delay.h>
#include<avr/eeprom.h>
#include<util/interrupt.h>
void EEPROM_write(unsigned int Address, unsigned int Data);
unsigned int EEPROM_read(unsigned int Address);
unsigned int c=0;
int main(void)
{
EEPROM_write(0x01,0x07);
_delay_ms(50);
c=EEPROM_read(0x01);
_delay_ms(50);
while(1)
{
To_7seg(c);
}
}
void EEPROM_write(unsigned int Address,unsigned int Data)
{
while(EECR & (1<<EEWE));
EEAR = Address;
EEDR = Data;
EECR |= (1<<EEMWE);
EECR |= (1<<EEWE);
}
unsigned int EEPROM_read(unsigned int Address)
{
while(EECR & (1<<EEWE));
EEAR = Address;
EECR |= (1<<EERE);
return(EEDR);
}
kindly give the solution for this problem....
Mon Mar 18 2013, 11:40 pm
Which compiler are you using ?
Does it have any built in EEPROM functions ?
Does it have any built in EEPROM functions ?
Tue Mar 19 2013, 12:49 pm
i am able to read the data when eeprom write and eeprom read functions are executing.but if i am comment the write eeprom function after once write, not able to read the correct data.the value comes 255.kindly give me the solution for this problem.
Wed Mar 20 2013, 10:19 am
Please check datasheet (page 21)for help. It has got sample code for read/write. If you are still not able to solve. Post back here
Powered by e107 Forum System