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