Part Number: TMS320F28379D
I have some I2C slave code that polls the XRDY bit in I2CSTR when a slave transmit is requested.
Have noticed that on the first call the slave transmit works as expected. On subsequent calls XRDY isn't set and the first data byte that the slave sends is a stale byte from the end of the Tx buffer from the last call.
Seems like during the last call the slave wrote to I2CDXR but the master NACKd indicating the transfer was done and so the slave never sent out the data to I2CXSR, data is still in I2CDXR, and the XRDY bit didn't get set. So on the next call this old byte gets sent first. Writing a 1 to XRDY before starting the slave transmit loop seems to fix the stale byte issue but I noticed in the TRM that XRDY is indicated as read only (R) but then in the description it infers R/W. From what I can tell I can write a 1 to XRDY but not a 0.
Wondering if there's any issue with forcing XRDY to 1 before starting the transfer or if there's a cleaner way that would maybe avoid this last byte getting written to I2CDXR? Thanks!
if (I2caRegs.I2CSTR.bit.AAS == 1 && I2caRegs.I2CSTR.bit.SDIR == 1)
{
I2caRegs.I2CMDR.bit.TRX = 1;
//I2caRegs.I2CSTR.bit.XRDY = 1; // when this line is uncommented the stale byte problem goes away
while (I2caRegs.I2CSTR.bit.SCD == 0)
{
if (I2caRegs.I2CSTR.bit.XRDY == 1)
{
I2caRegs.I2CDXR.all = *data++;
}
}
I2caRegs.I2CSTR.bit.SCD = 1;
I2caRegs.I2CMDR.bit.TRX = 0;
}

