Hi,
I'm trying to communicate with a M24256 EEPROM via I2C. I've achieved to write without any problems, but I can't find the way to read from the eeprom. The problem occurs on the part of the code where I set STT for repeated start and set STP for generating a stop condition once the countdown set by I2CCNT is 0. Just after setting STP (no matter before or after STT on repeatedstart) the MST bit automatically get cleared, so then when I check RRDY in order to read received data, this RRDY doesn't sets.
Could you help me with this problem?
The config and read routine I'm using is the following, I already attached an image of M24256 eeprom protocol:
config:
I2caRegs.I2CMDR.bit.BC = 000
I2caRegs.I2CMDR.bit.FDF = 0
I2caRegs.I2CMDR.bit.STB = 0
I2caRegs.I2CMDR.bit.DLB = 0
I2caRegs.I2CMDR.bit.RM = 0
I2caRegs.I2CMDR.bit.XA = 0
I2caRegs.I2CPSC.all = 0x0009
I2caRegs.I2CCLKL = 0x002D
I2caRegs.I2CCLKH = 0x002D
I2caRegs.I2CFFTX.all = 0x6080
I2caRegs.I2CIER = 0x0000
I2caRegs.I2CFFRX.all = 0x2080
void EEPROM_read()
{
I2caRegs.I2CSAR = 0x51; //Set slave address
I2caRegs.I2CCNT = 2; //Set count to 2 address bytes
I2caRegs.I2CMDR.bit.TRX = 1; //Set to Transmit mode
I2caRegs.I2CMDR.bit.MST = 1; //Set to Master mode
I2caRegs.I2CMDR.bit.FREE = 1; //Run in FREE mode
I2caRegs.I2CDXR = 0x00; //Send eeprom high address byte
I2caRegs.I2CMDR.bit.STP = 0; //Dont release the bus after Tx
I2caRegs.I2CMDR.bit.STT = 1; //Send the start bit, transmission will follow
while(I2caRegs.I2CSTR.bit.XRDY == 0){}; //Do nothing till data is shifted out
I2caRegs.I2CDXR = 0x01; //Send eeprom low address byte
while(I2caRegs.I2CSTR.bit.XRDY == 0){}; //Do nothing till data is shifted out
I2caRegs.I2CCNT = 1; //read 5 bytes from eeprom
I2caRegs.I2CMDR.bit.TRX = 0; //Set to Recieve mode
I2caRegs.I2CMDR.bit.MST = 1; //Set to Master mode
I2caRegs.I2CMDR.bit.FREE = 1; //Run in FREE mode
I2caRegs.I2CMDR.bit.STP = 1; //Stop when internal counter becomes 0
//-->Just after that STP the MST bit clears automatically, then in while (I2caRegs....RRDY) I don't get it set.
I2caRegs.I2CMDR.bit.STT = 1; //Repeated start, Reception will follow
I2caRegs.I2CMDR.bit.NACKMOD = 1; // noack before stop condition
while(I2caRegs.I2CSTR.bit.RRDY == 0){};
ResultatEEPROM[i] = I2caRegs.I2CDRR;
}