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.

TMS320F28069M: I2C interrupt problem

Part Number: TMS320F28069M

Hello,

I use TMS320F28069M for i2c communication. The following code is my code for  i2c communication.

#include "DSP28x_Project.h"
#include "i2c.h"
#include "mpu6050.h"


__interrupt void IMU(void);




float b=0;
double po=0;
Uint16 c=0;
Uint16 aaaa=0;






void main(void)
{


   InitSysCtrl();



   I2CA_Init();
   MPU6050_Init();



   /////////////////////////////////////////////////////////
   DINT;
   IER = 0x0000;
   IFR = 0x0000;
   InitPieCtrl();
   InitPieVectTable();
   EALLOW;
   PieVectTable.I2CINT1A = &IMU;
   EDIS;


   PieCtrlRegs.PIECTRL.bit.ENPIE = 1;   // Enable the PIE block
   PieCtrlRegs.PIEIER8.bit.INTx1=1;     //I2CINT1A
   IER|=M_INT8;                         //I2CINT1A
   EINT;                                // Enable Global Interrupts
   ERTM;
   ///////////////////////////////////////////////////////
       while (I2caRegs.I2CSTR.bit.BB == 1);        // busy loop
       I2caRegs.I2CSTR.bit.SCD = 1;                // Clear the SCD bit (stop condition bit)
       while(I2caRegs.I2CMDR.bit.STP == 1);        // stop bit loop
       I2caRegs.I2CSAR = MPU6050_ADDR;             // I2C slave address
       I2caRegs.I2CCNT     = 1;                    // assume register address is one byte
       I2caRegs.I2CDXR     = WHO_AM_I;                  // register address of the sensor (1 byte)
       I2caRegs.I2CMDR.all = 0x6620;               // start, no stop bit, master, tx, reset I2C 00100110
   ///////////////////////////////////////////////////////

    for(;;)

    {


       //DELAY_US(100.0);
       //po=GYRO_READ(GYRO_YOUT_H);
       //b=TEMP_READ(TEMP_OUT_H);
       //c=I2CA_ReadData(MPU6050_ADDR, WHO_AM_I);
    }

}






__interrupt void IMU(void)
{
    switch(I2caRegs.I2CISRC.bit.INTCODE)
    {
    case 3:
        I2caRegs.I2CSTR.bit.ARDY = 1;
        I2caRegs.I2CCNT     = 1;                    // assume register address is one byte
        I2caRegs.I2CMDR.all = 0x6C20;               // start, stop bit when CNT =0, master, rx, reset I2C 00101100;
        break;

    case 6:
        I2caRegs.I2CSTR.bit.SCD = 1;                // Clear the SCD bit (stop condition bit)
        aaaa = I2caRegs.I2CDRR;
        //while(I2caRegs.I2CMDR.bit.STP == 1);        // stop bit loop
        I2caRegs.I2CCNT     = 1;                    // assume register address is one byte
        I2caRegs.I2CDXR     = WHO_AM_I;                  // register address of the sensor (1 byte)
        I2caRegs.I2CMDR.all = 0x6620;               // start, no stop bit, master, tx, reset I2C 00100110
        break;
    }

    PieCtrlRegs.PIEACK.all|=PIEACK_GROUP8;
}

As you can see, there is  two states in interrupt service routine:  I2caRegs.I2CISRC.bit.INTCODE=3 (Registers ready to be accessed) and I2caRegs.I2CISRC.bit.INTCODE=6  (Stop condition detected).

my problem is:

In I2caRegs.I2CISRC.bit.INTCODE=6  I have to use  while(I2caRegs.I2CMDR.bit.STP == 1) or a delay of 100 micro second for properly working of I2C. So what is the problem of code without that delay and what can I do for removing that delay or while(I2caRegs.I2CMDR.bit.STP == 1) in my code.

Regards,

Mohammad.

  • Unfortunately, you can't send data until I2CMDR.STP is cleared. I'm not sure why this happens so much later than the I2CSTR.SCD bit getting set, but that does explain why it doesn't work.

    Can you measure how long you have to wait in that while loop? Is it an unreasonable amount of time for the ISR?

    Whitney