Part Number: TMS320F28034
I'm working with I2C of TMS320F28034 to read and write data in a EEPROM AT24C08C.
I'm facing problem with ramdon read operation.
case 1)
following the sequence -> Write to Word Adress -> read from the same Word Adress -> reg (I2CDRR) is loaded with the right data. However the variable quadbyte
is not loaded with the right data. I need to call the read function Uint16 Reade2Prom(Uint16 e2promaddress) twice in order to get quadbyte = I2caRegs.I2CDRR;
is it right to check the flag while(!I2caRegs.I2CSTR.bit.SCD); before quadbyte = I2caRegs.I2CDRR;?
case 2)
when the reas function Uint16 Reade2Prom(Uint16 e2promaddress) is called to read a different Word Adress it doesn't work I2CDRR is not updated.
There is something wrong in my code below?
Could someone help me with some example to perform these operations correctly?
for(;;) //infinite loop
{
if (FlagTestI2CREAD == 1)
{
quadbyteTEST = Reade2Prom(e2promaddress);
FlagTestI2CREAD = 0 ;
}
if (FlagTestI2CWRITE == 1)
{
Write2Prom(e2promaddress,EEdata);
FlagTestI2CWRITE = 0;
}
}
void I2CInit(void)
{
I2caRegs.I2CMDR.bit.IRS = 0;
I2caRegs.I2CPSC.all = 5; //
I2caRegs.I2CCLKH = 21; //
I2caRegs.I2CCLKL = 69; //
I2caRegs.I2CIER.all = 0x0000; //
I2caRegs.I2CFFTX.all = 0x6040;
I2caRegs.I2CFFRX.all = 0x2040; //
I2caRegs.I2CMDR.all = 0x0020;
}
Uint16 Reade2Prom(Uint16 e2promaddress)
{
Uint16 addresslow;
Uint16 addresshigh;
addresslow = e2promaddress & 0x00FF;
addresshigh = (e2promaddress>>8) & 0x00FF;
I2caRegs.I2CSAR = EEPROM_ADDR;//0x0050;
I2caRegs.I2CCNT = 0x0002;
I2caRegs.I2CDXR = addresshigh;
I2caRegs.I2CDXR = addresslow;
I2caRegs.I2CMDR.all = 0x2620; // Transmitter mode - master mode // START
while(!I2caRegs.I2CSTR.bit.ARDY);
I2caRegs.I2CCNT = 0x0001;
I2caRegs.I2CMDR.all = 0x2C20; // Receiver mode - master mode // START -
while(!I2caRegs.I2CSTR.bit.SCD);
quadbyte = I2caRegs.I2CDRR;
return(quadbyte);
}
void Write2Prom(Uint16 e2promaddress, Uint16 EEdata)
{
Uint16 addresslow;
Uint16 addresshigh;
addresslow = e2promaddress&0x00FF;
addresshigh = (e2promaddress>>8)&0x00FF;
I2caRegs.I2CSAR = EEPROM_ADDR;//0x0050;
I2caRegs.I2CCNT = 3 ;
I2caRegs.I2CDXR = addresshigh;
I2caRegs.I2CDXR = addresslow;
I2caRegs.I2CDXR = EEdata;
I2caRegs.I2CMDR.all = 0x2E20; // Transmitter mode - master mode // START
while(!I2caRegs.I2CSTR.bit.SCD);
I2caRegs.I2CSTR.bit.SCD = 1;
}

