Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

EEPROM 24C64 with LPC2387 problem

Status
Not open for further replies.

Dhaval Shah

Junior Member level 3
Joined
Sep 24, 2010
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,554
Hi

I am trying to read and write data to AT24C64.

I am using it with LPC2387 and used sample code of i2c provided by nxp.
My problem is when I write and read single page its working fine.

But when i try to write multiple pages and than try to read all pages, its not working.

I am too much confused why its not working with multiple pages.

Pls give me suggestion where i am doing mistake..
I have spent 2 days behind it but didn't get any mistake..

below is the sample code of nxp.

void I2C0MasterHandler(void) __irq
{
BYTE StatValue;

/* this handler deals with master read and master write only */
StatValue = I20STAT;
IENABLE; /* handles nested interrupt */
switch ( StatValue )
{
case 0x08: /* A Start condition is issued. */
I20DAT = I2CMasterBuffer[0];
I20CONCLR = (I2CONCLR_SIC | I2CONCLR_STAC);
I2CMasterState = I2C_STARTED;
break;

case 0x10: /* A repeated started is issued */
if ( I2CCmd == LM75_CONFIG )
{
I20DAT = I2CMasterBuffer[3];
}
I20CONCLR = (I2CONCLR_SIC | I2CONCLR_STAC);
I2CMasterState = I2C_RESTARTED;
break;

case 0x18: /* Regardless, it's a ACK */
if ( I2CMasterState == I2C_STARTED )
{
I20DAT = I2CMasterBuffer[1+WrIndex];
WrIndex++;
I2CMasterState = DATA_ACK;
}
I20CONCLR = I2CONCLR_SIC;
break;

case 0x28: /* Data byte has been transmitted, regardless ACK or NACK */
case 0x30:
if ( WrIndex != I2CWriteLength )
{
I20DAT = I2CMasterBuffer[1+WrIndex]; /* this should be the last one */
WrIndex++;
if ( WrIndex != I2CWriteLength )
{
I2CMasterState = DATA_ACK;
}
else
{
I2CMasterState = DATA_NACK;
if ( I2CReadLength != 0 )
{
I20CONSET = I2CONSET_STA; /* Set Repeated-start flag */
I2CMasterState = I2C_REPEATED_START;
}
}
}
else
{
if ( I2CReadLength != 0 )
{
I20CONSET = I2CONSET_STA; /* Set Repeated-start flag */
I2CMasterState = I2C_REPEATED_START;
}
else
{
I2CMasterState = DATA_NACK;
I20CONSET = I2CONSET_STO; /* Set Stop flag */
}
}
I20CONCLR = I2CONCLR_SIC;
break;

case 0x40: /* Master Receive, SLA_R has been sent */
I20CONSET = I2CONSET_AA; /* assert ACK after data is received */
I20CONCLR = I2CONCLR_SIC;
break;

case 0x50: /* Data byte has been received, regardless following ACK or NACK */
case 0x58:
I2CMasterBuffer[4+RdIndex] = I20DAT;
RdIndex++;
if ( RdIndex != I2CReadLength )
{
I2CMasterState = DATA_ACK;
}
else
{
RdIndex = 0;
I2CMasterState = DATA_NACK;
}
I20CONSET = I2CONSET_AA; /* assert ACK after data is received */
I20CONCLR = I2CONCLR_SIC;
break;

case 0x20: /* regardless, it's a NACK */
case 0x48:
I20CONCLR = I2CONCLR_SIC;
I2CMasterState = DATA_NACK;
break;

case 0x38: /* Arbitration lost, in this example, we don't
deal with multiple master situation */
default:
I20CONCLR = I2CONCLR_SIC;
break;
}
IDISABLE;
VICVectAddr = 0; /* Acknowledge Interrupt */
}

DWORD I2CStart( void )
{
DWORD timeout = 0;
DWORD retVal = FALSE;

/*--- Issue a start condition ---*/
I20CONSET = I2CONSET_STA; /* Set Start flag */

/*--- Wait until START transmitted ---*/
while( 1 )
{
if ( I2CMasterState == I2C_STARTED )
{
retVal = TRUE;
break;
}
if ( timeout >= MAX_TIMEOUT )
{
retVal = FALSE;
break;
}
timeout++;
}
return( retVal );
}

DWORD I2CStop( void )
{
I20CONSET = I2CONSET_STO; /* Set Stop flag */
I20CONCLR = I2CONCLR_SIC; /* Clear SI flag */

/*--- Wait for STOP detected ---*/
while( I20CONSET & I2CONSET_STO );
return TRUE;
}

DWORD I2CInit( DWORD I2cMode )
{
PCONP |= (1 << 19);
PINSEL1 &= ~0x03C00000;
PINSEL1 |= 0x01400000; /* set PIO0.27 and PIO0.28 to I2C0 SDA and SCK */
/* function to 01 on both SDA and SCK. */
/*--- Clear flags ---*/
I20CONCLR = I2CONCLR_AAC | I2CONCLR_SIC | I2CONCLR_STAC | I2CONCLR_I2ENC;

/*--- Reset registers ---*/
I20SCLL = I2SCLL_SCLL;
I20SCLH = I2SCLH_SCLH;
if ( I2cMode == I2CSLAVE )
{
I20ADR = LM75_ADDR;
}

/* Install interrupt handler */
if ( install_irq( I2C0_INT, (void *)I2C0MasterHandler, HIGHEST_PRIORITY ) == FALSE )
{
return( FALSE );
}
I20CONSET = I2CONSET_I2EN;
return( TRUE );
}

DWORD I2CEngine( void )
{
I2CMasterState = I2C_IDLE;
RdIndex = 0;
WrIndex = 0;
if ( I2CStart() != TRUE )
{
I2CStop();
return ( FALSE );
}

while ( 1 )
{
if ( I2CMasterState == DATA_NACK )
{
I2CStop();
break;
}
}
return ( TRUE );
}

int main(void)

DWORD i;

init_timer( 0, TIME_INTERVAL );

if ( I2CInit( (DWORD)I2CMASTER ) == FALSE ) /* initialize I2c */
{
while ( 1 ); /* Fatal error */
}

for(i=0;i<1000;i++)
{
buf = 0;
}

for ( i = 0; i < BUFSIZE; i++ ) /* clear buffer */
{
I2CMasterBuffer = 0;
}
I2CWriteLength = 35;
I2CReadLength = 0;
I2CMasterBuffer[0] = LM75_ADDR;
I2CMasterBuffer[1] = 0x01;
I2CMasterBuffer[2] = 0xA0;
I2CMasterBuffer[3] = 0x51;
I2CMasterBuffer[4] = 0x52;
I2CMasterBuffer[5] = 0x53;
I2CMasterBuffer[6] = 0x54;
I2CMasterBuffer[7] = 0x55;
I2CMasterBuffer[8] = 0x56;
I2CMasterBuffer[9] = 0x57;
I2CMasterBuffer[10] = 0x58;
I2CMasterBuffer[11] = 0x59;
I2CMasterBuffer[12] = 0x60;
I2CMasterBuffer[13] = 0x61;
I2CMasterBuffer[14] = 0x62;
I2CMasterBuffer[15] = 0x63;
I2CMasterBuffer[16] = 0x64;
I2CMasterBuffer[17] = 0x65;
I2CMasterBuffer[18] = 0x66;
I2CMasterBuffer[19] = 0x67;
I2CMasterBuffer[20] = 0x68;
I2CMasterBuffer[21] = 0x69;
I2CMasterBuffer[22] = 0x70;
I2CMasterBuffer[23] = 0x71;
I2CMasterBuffer[24] = 0x72;
I2CMasterBuffer[25] = 0x73;
I2CMasterBuffer[26] = 0x74;
I2CMasterBuffer[27] = 0x75;
I2CMasterBuffer[28] = 0x76;
I2CMasterBuffer[29] = 0x77;
I2CMasterBuffer[30] = 0x78;
I2CMasterBuffer[31] = 0x79;
I2CMasterBuffer[32] = 0x80;
I2CMasterBuffer[33] = 0x81;
I2CMasterBuffer[34] = 0x82;
I2CEngine();
delayMs(0,200);
for ( i = 0; i < BUFSIZE; i++ ) /* clear buffer */
{
I2CMasterBuffer = 0;
}
delayMs(0,200);
if ( I2CInit( (DWORD)I2CMASTER ) == FALSE ) /* initialize I2c */
{
while ( 1 ); /* Fatal error */
}
I2CWriteLength = 35;
I2CReadLength = 0;
I2CMasterBuffer[0] = LM75_ADDR;
I2CMasterBuffer[1] = 0x10;
I2CMasterBuffer[2] = 0xA0;
I2CMasterBuffer[3] = 0x01;
I2CMasterBuffer[4] = 0x02;
I2CMasterBuffer[5] = 0x03;
I2CMasterBuffer[6] = 0x04;
I2CMasterBuffer[7] = 0x05;
I2CMasterBuffer[8] = 0x06;
I2CMasterBuffer[9] = 0x07;
I2CMasterBuffer[10] = 0x08;
I2CMasterBuffer[11] = 0x09;
I2CMasterBuffer[12] = 0x10;
I2CMasterBuffer[13] = 0x11;
I2CMasterBuffer[14] = 0x12;
I2CMasterBuffer[15] = 0x13;
I2CMasterBuffer[16] = 0x14;
I2CMasterBuffer[17] = 0x15;
I2CMasterBuffer[18] = 0x16;
I2CMasterBuffer[19] = 0x17;
I2CMasterBuffer[20] = 0x18;
I2CMasterBuffer[21] = 0x19;
I2CMasterBuffer[22] = 0x20;
I2CMasterBuffer[23] = 0x21;
I2CMasterBuffer[24] = 0x22;
I2CMasterBuffer[25] = 0x23;
I2CMasterBuffer[26] = 0x24;
I2CMasterBuffer[27] = 0x25;
I2CMasterBuffer[28] = 0x26;
I2CMasterBuffer[29] = 0x27;
I2CMasterBuffer[30] = 0x28;
I2CMasterBuffer[31] = 0x29;
I2CMasterBuffer[32] = 0x30;
I2CMasterBuffer[33] = 0x31;
I2CMasterBuffer[34] = 0x32;
I2CEngine();
delayMs(0,200);
for ( i = 0; i < BUFSIZE; i++ ) /* clear buffer */
{
I2CMasterBuffer = 0;
}
delayMs(0,200);

// PAGE READ PORTION

if ( I2CInit( (DWORD)I2CMASTER ) == FALSE ) /* initialize I2c */
{
while ( 1 ); /* Fatal error */
}
I2CWriteLength = 2;
I2CReadLength = 32;
I2CMasterBuffer[0] = LM75_ADDR;
I2CMasterBuffer[1] = 0x01;
I2CMasterBuffer[2] = 0xA0;
I2CMasterBuffer[0] = LM75_ADDR;
I2CMasterBuffer[3] = LM75_ADDR | RD_BIT;
I2CCmd = LM75_CONFIG;
I2CEngine();
delayMs(0,200);
for ( i = 0; i < BUFSIZE; i++ ) /* clear buffer */
{
I2CMasterBuffer = 0;
}
delayMs(0,200);

if ( I2CInit( (DWORD)I2CMASTER ) == FALSE ) /* initialize I2c */
{
while ( 1 ); /* Fatal error */
}
I2CWriteLength = 2;
I2CReadLength = 32;
I2CMasterBuffer[0] = LM75_ADDR;
I2CMasterBuffer[1] = 0x10;
I2CMasterBuffer[2] = 0xA0;
I2CMasterBuffer[0] = LM75_ADDR;
I2CMasterBuffer[3] = LM75_ADDR | RD_BIT;
I2CCmd = LM75_CONFIG;
I2CEngine();

delayMs(0,200);

for(i=0;i<100;i++)
{
buf = I2CMasterBuffer[3+i];
}
}

Please let me know where i am wrong.

Thanks in advance.
 

Hello!

I don't use the 24C series very often because they are very limited in capacity
(compared to other flash memories that can handle 32MB for about the same
chip size and price). However, if I remember correctly, you cannot sequentially write
more than one block. And on top of that, if you start writing from a given location
within a page, then you cannot cross the page border.
You can write one page? Then why not writing one page, then another one, etc...
As for reading, it's possible to read the whole memory at once, as stated in the
specs...

Dora.
 

24c64 has a different frame format compared to other eeproms .. 24c04 and 24c64 frame format differs.. please check the datasheet for more details.........
 

Hi ckshivaram

I have read the datasheet and have follow the proper format as i said if i write only one page, i am able to read proper data.
But the problem is if i am trying to write about 5 pages, i am not able to read proper data.

So if you have used this eeprom then pls let me what i am missing..it will be very helpful.

Thanks

---------- Post added at 10:36 ---------- Previous post was at 10:34 ----------

Hi Nikhilele,

I have put delay of 200ms.. I think it is more than enough.
 

I have written a program to read/write a smartcard with LPC2378(similar to 24C16). See
**broken link removed**
I noticed that i had a problem writing in a burst across 8 byte page boundaries (no problem reading).
I think the device needs some time.
I suggest to change your code to automatically divide your data in smaller bursts that don't cross page boundaries.
 

Hi Stemmer,

Thanks for the reply.

Yes you are right. I have checked this code with 24C08 and its working good.
But not with 24C64.
So i would like to know what is the difference between AT24C64 and AT24C08.

If you have used it with any LPC microcontroller than let me from where i will get sample code for EEPROM.
I have google a lot but i didn't find it anywhere.

Thanks once again.
 

Hi Stemmer,

Thanks for the reply.

Yes you are right. I have checked this code with 24C08 and its working good.
But not with 24C64.
So i would like to know what is the difference between AT24C64 and AT24C08.

If you have used it with any LPC microcontroller than let me from where i will get sample code for EEPROM.
I have google a lot but i didn't find it anywhere.

Thanks once again.

The main difference in between 24C08 and 24C64 is of Address Bytes.

24C01 to 24C16 EEPROMS uses only one Address byte for memory

24C32 and 24C64 use two address bytes for memory, which ranges 0000 to 8192 for 24C64

Regards,
masterleous
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top