This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320VC5502: I2C Slave read/write detection

Part Number: TMS320VC5502
When the I2C peripheral is configured as a slave and the peripheral indicates that it is addressed (i.e. the BB and AAS bits in the I2CSTR register are set), how do I determine if the master is reading or writing? The  XRDY bit always indicates that it wants Tx data even when the master is writing.
Besides SPRU146D, is there an app note and/or working example code for an I2C slave on the '5502? I stress working since none of the examples I found in the CSL or ezDSP are useful.
  • Hi Steven,

    The I2C master uses the R/W bit to distinguish between writes to the slave and reads from the slave.
    My impression is that when the I2C is configured as a slave receiver, and the R/W bit from the master is a 1, then the I2C slave transitions from slave receiver to slave transmitter, and shifts out the data in I2CDXR. I would expect the XRDY bit to be set in the I2CSTR in that case.

    When the slave receiver receives a R/W bit = 0, it should remain in slave receiver mode and shift in the data from the master into the I2CDRR register, and I would expect the RRDY bit to get set in the I2CSTR. I did not verify this behavior, however.

    Do you observe the XRDY bit getting set when the master sends the R/W bit as 1 verses the RRDY bit being set when the master sends the R/W bit as a 0?

    I don't believe you can determine if the slave went into transmitter or receiver mode by checking the TRX bit inside of I2CMDR. Table 7 in SPRU146D states that the TRX bit is a dont care when in slave mode with free data format disabled.

    It would also be interesting if the R/W bit showed up in the I2CDRR register, but I don't expect it will.

    My understanding is that the I2C hardware state machine automatically acts upon the R/W bit by either transitioning into slave transmitter mode and shifting out the contents of I2CDXR (R/W = 1) or remaining in slave receiver mode and shifting data from the master into the I2CDRR register (R/W = 0).

    I will let you know if I find an I2C slave example for a different device with similar I2C IP.

    Hope this helps,
    Mark
  • The observed behavior is that XRDY is always set as soon as the I2C peripheral comes out of reset. It is set regardless of whether the slave is addressed for reading, addressed for writing, or not addressed at all. XRDY stays set until you write 2 words to I2CDXR. It will then stay cleared until the slave is addressed for reading and a byte has been shifted out. The RRDY bit operates as expected and goes high after the master writes a byte to the slave and goes low after reading from I2CDRR.

  • Okay. Thanks for the detail.

    Can you at least detect when the master has put the DSP into slave receiver mode by checking the RRDY bit?
    Let me ask around to see how the software on other processors that support I2C slave mode handle detection of slave receiver vs slave transmitter. I did not find any I2C slave examples for C5502.

    Regards,
    Mark
  • Yes, you can infer that the device has been selected for writing when the RRDY bit comes along. However, you don't know if the master is reading or writing until _after_ receiving the first byte, some 25 to 30 us after the AAS bit goes high.

    Most other I2C peripherals that I've used provide the value of bit 0 of the address and/or their transmitter ready indication is only active when the slave has been selected for reading.
  • Hi Steve,

    I'm glad that you figured out that if you write a dummy value to the XDR to clear XRDY, you can overwrite the XDR again later (while XRDY is still low) and get the right data out.

    I just wanted to post this solution for the benefit of anyone else trying to use C55x I2C in slave mode. Thanks for sharing.

    Regards,
    Mark