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.

CCS/TMS320F28069: I2C problem (not working)

Part Number: TMS320F28069

Tool/software: Code Composer Studio

I have a problem with I2C module on the TMS320F28069. In particular my code generate the start condition, the address of the slave (are present on the SDA pin), but doesn't generate the data bytes!!!!!!

My code snippet is the follow:

InitI2C(void)

{

    I2caRegs.I2CSAR = 0x0069; // Slave address - EEPROM control code
    I2caRegs.I2CPSC.all = 0x08; // Prescaler - need 7-12 Mhz on module clk
    I2caRegs.I2CCLKL = 10; // NOTE: must be non zero
    I2caRegs.I2CCLKH = 5; // NOTE: must be non zero
  

    I2caRegs.I2CMDR.all = 0x0020;

I2caRegs.I2CFFTX.all = 0x6000; // Enable FIFO mode and TXFIFO

}

Uint16 I2CA_WriteData(unsigned short slaveaddr, unsigned int length, unsigned char Data)
{

while (I2caRegs.I2CSTR.bit.BB != 0);

I2caRegs.I2CMDR.bit.MST=1;//Set to Transmit mode

while(I2caRegs.I2CMDR.bit.STP !=0); // 0-->STP is automatically cleared after the STOP condition has been generated.

I2caRegs.I2CSAR = slaveaddr;     //0x69;// slave address

while (I2caRegs.I2CSTR.bit.BB != 0);

I2caRegs.I2CCNT = length;//Setup number of bytes to send

I2caRegs.I2CDXR =0xA5;

// Send start as master transmitter
I2caRegs.I2CSTR.bit.NACK = 1;

I2caRegs.I2CMDR.bit.FDF=0;
I2caRegs.I2CMDR.bit.TRX=1;

I2caRegs.I2CMDR.bit.BC = 0;

I2caRegs.I2CMDR.bit.STT=1;
I2caRegs.I2CMDR.bit.FREE=1;


// I2caRegs.I2CMDR.all=0x6E20; not used 


while(I2caRegs.I2CSTR.bit.NACK == 0);
I2caRegs.I2CMDR.bit.STP = 1;

}

int  main (){

InitI2C();

 I2CA_WriteData(0x68,0x01,0x05);

}

this what am getting in the scope

*************

Thanking you,

Regards

Arjun k 

:)

  • Hi Arjun,

    Thank you for providing the waveform. The slave device doesn't seem to ACK the slave address, i.e. 9th bit is left high, and so the communication is stopped. The signal you provided is what's seen at the slave device, correct?

    What is your slave device? It looks like you set up the clocking to be 400KHz (fast mode), but maybe the slave device isn't compatible with fast mode and doesn't have clock stretching? If so, clocking SCL at 100KHz should work.

    Hope this helps,
    Kevin
  • Hi  Kevin,

      I am using  MPU 6050  . 


    The Slave  is compatible with fast mode, i tried  with the 100Khz ( Standard mode)  also  No change in the output .

    Programming Sequence is correct or any changes is required ? 

    InitI2C(void)

    {

        I2caRegs.I2CSAR = 0x0069; // Slave address - EEPROM control code
        I2caRegs.I2CPSC.all = 0x08; // Prescaler - need 7-12 Mhz on module clk
        I2caRegs.I2CCLKL = 10; // NOTE: must be non zero
        I2caRegs.I2CCLKH = 5; // NOTE: must be non zero
      

        I2caRegs.I2CMDR.all = 0x0020;

    I2caRegs.I2CFFTX.all = 0x6000; // Enable FIFO mode and TXFIFO

    }

    Uint16 I2CA_WriteData(unsigned short slaveaddr, unsigned int length, unsigned char Data)
    {

    while (I2caRegs.I2CSTR.bit.BB != 0);

    I2caRegs.I2CMDR.bit.MST=1;//Set to Transmit mode

    while(I2caRegs.I2CMDR.bit.STP !=0); // 0-->STP is automatically cleared after the STOP condition has been generated.

    I2caRegs.I2CSAR = slaveaddr;     //0x69;// slave address

    while (I2caRegs.I2CSTR.bit.BB != 0);

    I2caRegs.I2CCNT = length;//Setup number of bytes to send

    I2caRegs.I2CDXR =0xA5;

    // Send start as master transmitter
    I2caRegs.I2CSTR.bit.NACK = 1;

    I2caRegs.I2CMDR.bit.FDF=0; 
    I2caRegs.I2CMDR.bit.TRX=1;

    I2caRegs.I2CMDR.bit.BC = 0;

    I2caRegs.I2CMDR.bit.STP=1;

    I2caRegs.I2CMDR.bit.STT=1;
    I2caRegs.I2CMDR.bit.FREE=1;


    // I2caRegs.I2CMDR.all=0x6E20; not used 

    }

    int  main (){

    InitI2C();

     I2CA_WriteData(0x68,0x01,0x05);

    }

     Let me know the programming sequence is correct or not ? 

    Do you have any Driver Code for this .

    with regards 

    Arjun  k

  • Hi Arjun,

    Can you double check that the signal connections to the MPU 6050 are correct? Maybe SDA/SCL are going to the wrong pins. I assume you have tried both possible slave addresses already correct, 0x68 and 0x69?

    Does it make a difference if you write to the entire address in the write data function rather than each bit? (i.e. I2caRegs.I2CMDR.all = 0x6E20;)

    The only I2C driver currently available is that which is used in the i2c_eeprom example, which it looks like you're already referencing.

    Best,
    Kevin
  • Hi Kevin ,

    Thanks for clarification.Thank you Kevin for posting the solution!
    Best regards,

    ARJUN K