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 support@ccsinfo.com

I2C EEPROM page Write & RS232

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



Joined: 07 Mar 2006
Posts: 19

View user's profile Send private message

I2C EEPROM page Write & RS232
PostPosted: Mon Mar 13, 2006 4:24 pm     Reply with quote

I'm trying to download a database from the PC to I2C. I'm using the hyber tirminal to test first.

I add the following function to CCS 24256.c driver to make page copy

Code:
void page_write_ext_eeprom(long int address, char *data)
{
   short int status;
   int i;
   i2c_start();
   i2c_write(0xa0);
   i2c_write(address>>8);
   i2c_write(address);

   for (i=0 ; i<64 ; i++)
      i2c_write(*data++);

   i2c_stop();
   i2c_start();
   status=i2c_write(0xa0);
   while(status==1)
   {
   i2c_start();
   status=i2c_write(0xa0);
  }
}


In the main, i'm trying to copy the 64 byte in an array first then copy it to eeprom as shown in the code by the end. (if anybody had better idea please, advice)

The Problem:

when i wrote page to I2C EEPROM then displayed it back, sometimes it works fines and sometimes it didn't store all of the array.

The only diffrence i found till now is the addresse. ie: when the starting addresse is (0000)H it works fine but when it is (000A)H it doesn't work.
Code:

#include <16f877A.h>
#fuses HS,NOWDT,NOPROTECT
#use delay (clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <24256.c>
#define page 64

main()
{
   int i;
   char k[64];
   long int Add;
   Add = 0x000A;
   
   printf("\nStart \n\r");
   
   // reading the values in an array
   for (i=0; i< page; i++)
   {
      k[i]= getc();
      putc (k[i]);
   }
   
   // writing page in the eeprom     
   page_write_ext_eeprom(Add,k);
   printf ("Page Copied\n\r");
   delay_ms(5);
   
   // reading the page and displaying it
   for (i=0; i<64; i++)
      putc (read_ext_eeprom(Add++));
      
   printf("\n\rDone\n");
}


if anybody get any idea what is going on please advice.
Thanks.
jspencer



Joined: 22 Dec 2003
Posts: 57
Location: Boise, ID USA

View user's profile Send private message

PostPosted: Mon Mar 13, 2006 4:29 pm     Reply with quote

Are there page boundaries on this eeprom? Might be the problem. You have to start the page writes on the physical page boundary. So if the 24256 is the same as the 2432 then it would be 32 byte physical page boundaries, that is probably why you are losing some of your data.
jspencer



Joined: 22 Dec 2003
Posts: 57
Location: Boise, ID USA

View user's profile Send private message

PostPosted: Mon Mar 13, 2006 4:37 pm     Reply with quote

Well it's not the same as the 24LC32, but it does work the same in that you have to start on the physical page boundary, which is multiples of 64.
Ahmed



Joined: 07 Mar 2006
Posts: 19

View user's profile Send private message

PostPosted: Mon Mar 13, 2006 4:52 pm     Reply with quote

jspencer wrote:
Well it's not the same as the 24LC32, but it does work the same in that you have to start on the physical page boundary, which is multiples of 64.


Thanks Jspencer i got it now.
Donlaser



Joined: 17 Sep 2005
Posts: 12
Location: Trenque Lauquen, Argentina

View user's profile Send private message MSN Messenger

PostPosted: Mon Mar 13, 2006 4:54 pm     Reply with quote

Try add a i2c_stop() to stop the bus where you are checking to finish the write.

Code:
Code:
void page_write_ext_eeprom(long int address, char *data)
{
   short int status;
   int i;
   i2c_start();
   i2c_write(0xa0);
   i2c_write(address>>8);
   i2c_write(address);

   for (i=0 ; i<64 ; i++)
      i2c_write(*data++);

   i2c_stop();
   i2c_start();
   status=i2c_write(0xa0);
   while(status==1)
   {
   i2c_start();
   status=i2c_write(0xa0);
  }
  i2c_stop();                          // <<<== ADD THIS
}
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