CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

at24c1024 eeprom

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
brahme.girish



Joined: 20 Jun 2010
Posts: 7

View user's profile Send private message

at24c1024 eeprom
PostPosted: Mon Dec 27, 2010 3:52 am     Reply with quote

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 27, 2010 12:42 pm     Reply with quote

You driver has a few problems. I think it would be easier if you modify
an existing CCS driver so it will work with the at24c1024 eeprom.

Make a copy of this CCS driver file:
Quote:

c:\program files\picc\drivers\241025.c

Give the copy a new name: at24c1024.c

Then edit the at24c1024.c file. There are two places in the file that
have "0xa8". You need to change both of them to 0xA2. Then I think
it will work with the at24c1024.

Apparently you are interested in reading and writing more than one byte.
If you want to read/write a 16-bit or 32-bit value, you can call the routines
in this CCS driver file:
Quote:

c:\program files\picc\drivers\external_eeprom.c

This file above will call the routines in the at24c1024.c file.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group