I have been trying to write data in eeprom through I2C but data is not writing properly and i am using polling method.
here is my code
I2caRegs.I2CMDR.all = 0;
I2caRegs.I2CSAR = I2C_SLAVE_ADDR; //Set slave address
I2caRegs.I2CCNT = I2C_NUMBYTES + 1;
I2caRegs.I2CMDR.bit.IRS = 1;
I2caRegs.I2CDXR =0x00; //Send eeprom address
while ((I2caRegs.I2CSTR.bit.BB == 1 ));
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.I2CMDR.bit.STP = 1; //Stop when internal counter becomes 0
I2caRegs.I2CMDR.bit.STT = 1; //Send the start bit, transmission will follow
while(I2caRegs.I2CSTR.bit.XRDY == 0){};
for(i = 0; i < I2C_NUMBYTES; i++){
while(I2caRegs.I2CSTR.bit.XRDY == 0){}; //Do nothing till data is shifted out
I2caRegs.I2CDXR = Data[i];
}
}