EmbeddedRelated.com
Forums
Memfault Beyond the Launch

LPC 2148 & 24C256

Started by vpack2000 March 17, 2012
Hi , this is my first time here ,

I am new with LPC 2148 ,I did buy a kit 3 years ago , now I begin to stuy it , I had programmer of 8051 for 10 years , but now I try to make the lpc 2148 read a 24c256 eeprom , but I could not , I work on it for 15 days , every day , someone can help me ?

I am use the keil , I got the answer from eeprom :0x08 ,0x18 , 0x28, but never a answer that I could get the date like 0x50.
regards ,

Marcos from Brasil

An Engineer's Guide to the LPC2100 Series

Hi Marcos,

On Sat, 2012-03-17 at 04:33 +0000, vpack2000 wrote:
> Hi , this is my first time here,

Please provide more information like source code the
next time you are here.
That allows us to help you much better :-)
> I got the answer from eeprom :0x08 ,0x18 , 0x28,

It looks like you are using the i2c bus, the eeprom type
number you provided has an i2c interface according to the
datasheet.
These 3 states are for MT mode.
> but never a answer that I could get the date like 0x50.

This state is from MR mode.

Please describe the program flow you are using and show
some source code if you want help.

roelof

void I2C_ISR(void)__irq {

int temp=0 ;
temp = I2C0STAT ;
IO0CLR=BIT31; // LIGO O LED


switch (temp)
{
case ( 0x08 ): // ENVIEI START


I2C0CONSET=0X04; // Reset I2C flag Interrupt
I2C0CONCLR=0x28; // Reset I2C flag Interrupt e habilita I2C
I2C0DAT=E2PROM_DADO;
break;

case ( 0x10 ): // repeat start condition


I2C0CONSET=0X04;
I2C0CONCLR=0x28;
I2C0DAT=E2PROM_DADO ;
break;

case ( 0x18 ): // ESCREVEU NA E2PROM E VOLTOU ACK


if ( dezoitoEnviado == 0){

dezoitoEnviado = 1;
E2PROM_DADO = 0x00; // MSB
I2C0CONSET=0X04;
I2C0CONCLR=0x28;
I2C0DAT=E2PROM_DADO;
dezoitoEnviado = 1;
}
else
break;

case ( 0x20 ): // ESCREVEU NA E2PROM E NAO VOLTOU ACK
break;

case ( 0x28 ): // I2DAT FOI TRANSMITIDO, VEIO ACK


if (I2CLocked ==1) {

I2C0CONSET=0X04;
I2C0CONCLR=0x28;
break;
}
else {

if (I2CTerminado == 0){

I2C0CONSET=0X04;
I2C0CONCLR=0x28;
I2C0DAT=0x00;
I2CTerminado = 1 ;
break;
}
else {
I2CLocked = 1;
delay();
E2PROM_DADO = 0xA1 ;

I2C0CONSET=0X04;
I2C0CONCLR=0x28;
I2C0CONSET=0x20;
I2C0DAT= E2PROM_DADO;

}
}
break;

case ( 0x30 ):

break;

case ( 0x40 ): // SLA + R FOI TRANSMITIDO, VEIO ACK

I2C0CONSET=0X04;
I2C0CONCLR=0x28;
quarenta = 0x28;
break;

case ( 0x48 ): // slave adress + R, NOT Ack
break;

case ( 0x50 ): //DATA BYTE FOI TRANSMITIDO E VEIO ACK

I2C0CONSET = 0x10; //Stop condition
I2C0CONSET=0X04;
I2C0CONCLR=0x28;
I2C0CONCLR=0x3C;
IO0SET=BIT31; // DESLIGO O LED

break;

case ( 0x58 ): // Dado recebido .NOT ACK

E2PROM = I2C0DAT ;
I2C0CONSET = 0x20; //Resend Start condition

break;

default:

break;
}
I2C0CONCLR = 0x08; // Limpa flag de I2C( interrupo )

VICVectAddr = 0x0; //RESET VIC ADRESS INTERRUPT LAST ONE

Hi Marcos,

What do you expect me to do with ISR code you send,
still no description of what it is you are trying
to accomplish.
You told us that you never received state 0x50.
By looking at the code you send it is clear that you
will need to read and understand the tables with i2c
states as described in the lpc2148 user manual.
You are constantly clearing the start and interrupt
bit, do not do that. Only clear the interrupt bit AFTER
you have done what is necessary for the particular
i2c state. Once the start, stop or aa bits are set or
cleared they will stay in that state till you do
otherwise.
Also the if{}else{} constructs are missing in states
0x40 and 0x50 to decide if an ack or nack needs to be
send.

Here is your code back, I cleaned it up a bit, removed
all the excess spaces (did you fall asleep on the spacebar ?)
and put in some comments about the i2c states. I used
a TAB size of 4.

roelof
void I2C_ISR(void) __irq
{
int temp = 0;

temp = I2C0STAT;
switch(temp)
{
case 0x08: // ENVIEI START
// A start condition has been send
// Slave address and write bit will be send
I2C0CONSET = 0X04; // set aa bit
I2C0CONCLR = 0x28; // clear start and interrupt bit
I2C0DAT = E2PROM_DADO; // load eeprom address
break;

case 0x10: // repeat start condition
// A repeated start condition has been send
// Slave address will be send
// Load slave address in the transmit buffer
I2C0CONSET = 0X04; // set aa bit
I2C0CONCLR = 0x28; // clear start and interrupt bit
I2C0DAT = E2PROM_DADO; // load eeprom address
break;

case 0x18: // ESCREVEU NA E2PROM E VOLTOU ACK
// Slave address and write bit have been transmitted
// Acknowledge has been received
// Load a data byte from the buffer
E2PROM_DADO = 0x00; // MSB
I2C0CONSET = 0X04;
I2C0CONCLR = 0x28;
I2C0DAT = E2PROM_DADO;
break;

case 0x20: // ESCREVEU NA E2PROM E NAO VOLTOU ACK
// Slave addres and write bit have been transmitted
// NOT_ACK has been received
// Generate stop condition for now
break;

case 0x28: // I2DAT FOI TRANSMITIDO, VEIO ACK
// Data byte has been transmitted
// Acknowledge has been received
// A data byte from the mtd buffer will be transmitted
if(I2CLocked == 1)
{
I2C0CONSET = 0X04;
I2C0CONCLR = 0x28;
break;
}
else
{
if(I2CTerminado == 0)
{
I2C0CONSET = 0X04;
I2C0CONCLR = 0x28;
I2C0DAT = 0x00;
I2CTerminado = 1;
break;
}
else
{
I2CLocked = 1;
delay();
E2PROM_DADO = 0xA1;
I2C0CONSET = 0X04;
I2C0CONCLR = 0x28;
I2C0CONSET = 0x20;
I2C0DAT= E2PROM_DADO;
}
}
break;

case 0x30:
break;

case 0x40: // SLA + R FOI TRANSMITIDO, VEIO ACK
// Slave addres and read bit have been transmitted
I2C0CONSET = 0X04;
I2C0CONCLR = 0x28;
break;

case 0x48: // slave adress + R, NOT Ack
// Slave address + read has been send with no Ack
// Generate a stop condition for now
break;

case 0x50: //DATA BYTE FOI TRANSMITIDO E VEIO ACK
// Data byte received
// Ack has been returned
// Read the byte
// Receive another byte, return ack or no ack
I2C0CONSET = 0x10; //Stop condition
I2C0CONSET = 0X04;
I2C0CONCLR = 0x28;
I2C0CONCLR = 0x3C;
break;

case 0x58: // Dado recebido .NOT ACK
// Data byte received, No ack sent!
// Read the byte
// Stop the transfer
E2PROM = I2C0DAT;
I2C0CONSET = 0x20; //Resend Start condition
break;

default:
break;
}
I2C0CONCLR = 0x08; // Limpa flag de I2C( interrupção)
VICVectAddr = 0x0; //RESET VIC ADRESS INTERRUPT LAST ONE


Memfault Beyond the Launch