brahme.girish
Joined: 20 Jun 2010 Posts: 7
|
at24c1024 eeprom |
Posted: Mon Dec 27, 2010 3:52 am |
|
|
Dear all,
I working on at24c1024 1024k eeprom. I am using ccs function written
for at24c64 eeprom, with somewhat modification for 1024k. As it has 17bit addressing format.
I write data say ' 10' on 0X0000 address.
And if I read it back from 0X0000 I get exact same data.
The problem is if I write '11' on next location 0x00001, the previous data get deleted. And also when I read it from same location say 0X0001, I get 0Xff (255).
The code I written work only for 1 address location.
I connected 4.7k pullup on SDA, SCL and 1,2,3,4 (NC,A0,A1,WP) all are grounded.
Function for read write eeprom is,
Code: |
void write_ext_eeprom(unsigned long int address, Byte data)
{
short int status;
i2c_start();
i2c_write(0xa0);
i2c_write((address>>8)&0x1f);
i2c_write(address);
i2c_write(address);
i2c_write(data);
i2c_write(data); //here i send two byte of data and address
i2c_stop();
i2c_start();
status=i2c_write(0xa0);
while(status==1)
{
i2c_start();
status=i2c_write(0xa0);
}
i2c_stop();
delay_ms(20);
}
Byte read_ext_eeprom2(unsigned long address) {
Byte data1,data2;
while(!ext_eeprom_ready());
i2c_start();
i2c_write((0xa0|(BYTE)(address>>8))&0xfe);//fe
i2c_write(address);
i2c_write(address);
i2c_stop();
i2c_start();
i2c_write((0xa1|(BYTE)(address>>8))|1);
data1=i2c_read(1); //read first msb with ack
data2=i2c_read(0);
i2c_stop();
return(data2);
}
void init_ext_eeprom() {
output_float(EEPROM_SCL);
output_float(EEPROM_SDA);
}
BOOLEAN ext_eeprom_ready() {
int1 ack;
i2c_start(); // If the write command is acknowledged,
ack = i2c_write(0xa0); // then the device is ready.
i2c_stop();
return !ack;
} |
Here is the code for main routine.
Code: |
void main()
{
Byte x=0;
Byte adr=40;
unsigned long f =0;
f =0;
write_ext_eeprom(f,adr);
delay_ms(100);
f = 0; // here also i am verifying
whether write operation is ok then i go
for next write. only for checking
x =read_ext_eeprom2(f);
if(x==adr){
f =1;
adr++;
write_ext_eeprom(f,adr);
}
while(true)
{
f = 1;
x =read_ext_eeprom2(f);
delay_ms(100);
}
} |
Crystal is 4mhz, ic PIC 16f883.
Anyone have idea why the code is behaving like this ? As it read/writes, first memory location 0X0000 ok, then afterward what happens that it does not write any new data and clear previously written also. Why?
Please help me
Thanx in advance,
with best wishes,
Girish |
|