embpic
Advanced Member level 3
i am using keil and lpc2148 and interface with 24lc04 eeprom but facing problem and my code is
i used status as per written in datasheet so what are the corrections in this code.
thanx..
- - - Updated - - -
and my full project is as follows
Code:
void init_i2c(void);
void i2c_start(void);
void i2c_stop(void);
void i2c_tc(void)__irq;
unsigned char read_d[6]={0},a;
unsigned char status;
void init_i2c(void)
{
I2C0CONCLR=0x6C;
I2C0CONSET = 0x40;
I2C0CONCLR = 0x00;
I2C0SCLH=80;
I2C0SCLL=70;
VICIntEnable |= 0x00000200;
VICIntSelect |= 0x00000000;
VICVectCntl0 = 0x00000029;
VICVectAddr0 = (unsigned long)i2c_tc;
PINSEL0&=0xFFFFFF0F;
PINSEL0|=0x00000050;
}
void i2c_start(void)
{
I2C0CONSET = 0x20;
}
void i2c_stop(void)
{
I2C0CONSET = 0x10;
}
void i2c_tc()__irq
{
status = I2C0STAT;
I2C0CONCLR = 0x28;
VICVectAddr = 0xff;
}
void write_eeprom(void)
{
i2c_start();
while(!(status & 0x08));
I2C0DAT = 0xA0;
while(!(status & 0x18));
I2C0DAT = 0x00;
while(!(status & 0x28));
I2C0DAT = 0x00;
while(!(status & 0x28));
I2C0DAT = 'A';
while(!(status & 0x28));
I2C0DAT = 'B';
while(!(status & 0x28));
I2C0DAT = 'C';
while(!(status & 0x28));
I2C0DAT = 'D';
while(!(status & 0x28));
I2C0DAT = 'E';
while(!(status & 0x28));
i2c_stop();
}
void read_eeprom(void)
{
i2c_start();
while(!(status & 0x08));
I2C0DAT = 0xA0;
while(!(status & 0x18));
I2C0DAT = 0x00;
while(!(status & 0x28));
I2C0DAT = 0x00;
while(!(status & 0x28));
i2c_start();
while(!(status & 0x10));
I2C0DAT = 0xA1;
while(!(status & 0x40));
// I2C0CONCLR=0x04; //set hardware to send nack
for(a=0;a<4;a++)
{
read_d[a] = I2C0DAT;
I2C0CONSET=0x04; //set hardware to send ack
while(!(status & 0x50));
}
read_d[4] = I2C0DAT;
I2C0CONCLR=0x04; //set hardware to send nack
while(!(status & 0x58));
i2c_stop();
}
i used status as per written in datasheet so what are the corrections in this code.
thanx..
- - - Updated - - -
and my full project is as follows