View previous topic :: View next topic |
Author |
Message |
Ahmed
Joined: 07 Mar 2006 Posts: 19
|
I2C EEPROM page Write & RS232 |
Posted: Mon Mar 13, 2006 4:24 pm |
|
|
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
|
|
Posted: Mon Mar 13, 2006 4:29 pm |
|
|
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
|
|
Posted: Mon Mar 13, 2006 4:37 pm |
|
|
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
|
|
Posted: Mon Mar 13, 2006 4:52 pm |
|
|
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
|
|
Posted: Mon Mar 13, 2006 4:54 pm |
|
|
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
} |
|
|
|
|