hi
if someone has already used port I2C, thank you to help me,
I wants to address an eeprom (at24c32).
but its fact 15 days that I test without successes! I put pullups of 10k to 5v on scl and sda. I joint you the code, thank you
i’m using lpch 2129 with keil µVISION
///////////////////////////////////////////////////////////////////////////////////////
I2Cinit()
{
PINSEL0 = 0x50; //
I2CONCLR = 0x6C; // clear all flags
I2SCLL= 80; //100Khz
I2SCLH= 80;
I2CONSET = 0x40; // activ I²C
}
//////////////////////////////////////////////////////////////////////////////////////////
/****************************************************************************************/
slave(char ad)
{
if(!(ad & 0x01)) //if write
{
I2CONSET = 0x20;
while((I2STAT != 0x08) && (!(I2CONSET & 0x08)));
I2DAT = ad;
I2CONCLR = 0x28;
while((I2STAT != 0x18) && (!(I2CONSET & 0x08)));
lcdprint (" address ok");
}
else
{
I2CONSET = 0x20;
while((I2STAT != 0x10) && (!(I2CONSET & 0x08)));
I2DAT = ad;
I2CONCLR = 0x28;
while((I2STAT != 0x40) && (!(I2CONSET & 0x08)));
home();
lcdprint (" adress1 ok");
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
writeI2C(char da)
{
char r;
I2DAT= da;
I2CONCLR = 0x08;//clear SI
while(!(I2CONSET & 0x08));
r=I2STAT;
if (r != 0x28)
{
lcdprint("error");
}
mili(10);
}
/*************************************************************
char readI2C(void)
{
char r;
I2CONCLR = 0x08; // clear SI
while(!(I2CONSET & 0x08));
r=I2STAT; // check for error
if (r != 0x50)
{
lcdprint("error1");
}
return I2DAT;
}
////////////////////////////////////////////////////////////////////////////////////////////
StopI2C(void)
{
I2CONSET =0x10 ;
}
/***************************************************************************************/
eeprom()
{
char temp;
I2Cinit();
slave(0xA0);
slave(0x02); // to read at adress 0200
slave(0x00);
slave(0xA1);
temp=readI2C();
StopI2C();
}