AnsweredAssumed Answered

Help: TWI/I2C Repeated Start Issue

Question asked by bigwave on Aug 26, 2014
Latest reply on Sep 23, 2014 by Jithul_Janardhanan



I'm using the TWI interface from a ADSP-21489 to talk with a TMP411 remote temperature sensor. This project has specific requirements to use a polling method instead of interrupts. To obtain the remote and local temperatures from the device a repeated start is used to read the value immediately after the target register is written to the device. 


Below is the extract logic used for this communication. This logic actually resides in a state machine which is executed once every 16khz.


If the loop count for the "Simulate delay", which occurs now between different states in the actual code, is set to 0xFF then the repeated start works as expected. If the loop count is set to 0xFFF then the TWI Controller sends the second i2c address, right after the repeated start pulse, with the R/W bit set to write instead of read.


I have attached screen dumps from the logic analyzer showing a good communication and one showing a bad communication.


   int localtemp, temp;


   SRU(LOW, DPI_PB11_I);  /* input buffer is low */
   SRU(TWI_DATA_PBEN_O, DPI_PBEN11_I); /* TWI data output */
   SRU(DPI_PB11_O, TWI_DATA_I);  /* TWI data input */
   SRU2(LOW, DPI_PB12_I);  /* input buffer is low */
   SRU2(TWI_CLK_PBEN_O, DPI_PBEN12_I); /* TWI clock output */
   SRU2(DPI_PB12_O, TWI_CLK_I);  /* TWI clock input */


   *pTWIMITR = (0x14) | TWIEN;
   *pTWIDIV = (CLKHI << 8) | CLKLOW;


    /* Flush transmit and receive buffers */


   *pTWIMADDR = 0x4c;  /* device address on the bus */
   *pTXTWI8 = 0x00;
   *pTWIMCTL = (1<< 6) | TWIRSTART | TWIMEN;


    //Check whether I2C write transfer is complete
    while ((*pTWIIRPTL & TWIMCOM) != TWIMCOM)
            ; // Keep looping


    for (long i=0; i<0xFF; i++) // 0xFF = Good, 0xFFF = Bad
         ; // Simulate delay

    *pTWIMCTL = (1 << 6) | TWIMDIR | TWIMEN;
    temp = *pRXTWI8;


    //Check whether I2C write transfer is complete
    while ((*pTWIIRPTL & TWIMCOM) != TWIMCOM)
          ; // Keep looping



    localtemp = temp;

Can anyone shine some light on why this could be occurring or explain if I can do anything about it.

Thanks so much,