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.

I2C communication problems with TMS320F28035

Other Parts Discussed in Thread: TMS320F28035, CONTROLSUITE

Am trying to read MPU9150 sensors values through I2c by using TMS320F28035 piccolo [GPIO28 and GPIO29],my problem is  I don't see the activity on SCL line however. As the pin was initially high, as soon as the code is run, the SCL goes low and stays low. It's not pulsing at all. I'm not seeing SDATA doing any activity either. It stays as it is, high.

So this code is what I come with

//**************I2c initialization

void I2CA_Init(void)
{
I2caRegs.I2CMDR.all = 0x0000;

I2caRegs.I2CSAR = 0x68;

I2caRegs.I2CPSC.all = 6;

I2caRegs.I2CCLKL = 10; 

I2caRegs.I2CCLKH = 5; 

I2caRegs.I2CIER.all = 0x3E; 

I2caRegs.I2CMDR.all = 0x0020; 

I2caRegs.I2CFFTX.all = 0x6000; 

I2caRegs.I2CFFRX.all = 0x2040; 

return;
}

//************WRITE FUNCTION

void writeRegisterWithPiccolo(char reg,char write_data,char stop_bit)
{

while(I2caRegs.I2CMDR.bit.STP == 1) { //// wait until the STP bit is cleared from any previous master communication
}

while (I2caRegs.I2CSTR.bit.BB == 1) { // wait until bus not busy
}

// Setup slave address
I2caRegs.I2CSAR = MPU9150_I2C_ADDR;

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

// Setup data to send
I2caRegs.I2CDXR = reg; 

I2caRegs.I2CDXR = write_data; 


if(stop_bit == 'y') // if there should be a stop bit at the end of transmission, then

{
while(I2caRegs.I2CMDR.all != 0x6E20){
I2caRegs.I2CMDR.all = 0x6E20; // send start as master transmitter, w/ stop condition once all bytes have been sent
}

while(I2caRegs.I2CSTR.bit.SCD != 1) {} // wait until stop condition is detected

I2caRegs.I2CSTR.bit.SCD = 1; // clear stop condition detected bit in I2C status register

}

else // if there should not be a stop condition at end of transmission (master retains control of bus), then

{
while(I2caRegs.I2CMDR.all != 0x2620){
I2caRegs.I2CMDR.all = 0x2620; // start condition, master mode, TX mode
}

while(I2caRegs.I2CSTR.bit.ARDY != 1) {} // wait for I2C registers to finish working

I2caRegs.I2CSTR.bit.ARDY = 1; // clear ARDY bit in I2C status register
}

}

//***************READ FUNCTION

 unsigned short readRegisterWithPiccolo(unsigned char reg)

{

while(I2caRegs.I2CMDR.bit.STP == 1) { //// wait until the STP bit is cleared from any previous master communication
}

I2caRegs.I2CSAR = MPU9150_I2C_ADDR;

// Check if bus busy
while (I2caRegs.I2CSTR.bit.BB == 1){ // wait until bus not busy
}

I2caRegs.I2CCNT = 1;
I2caRegs.I2CDXR = reg;

while(I2caRegs.I2CMDR.all != 0x2620)
{
I2caRegs.I2CMDR.all = 0x2620; // Send data to setup MEMS address
}
I2caRegs.I2CCNT = 2; // Setup how many bytes to expect

while(I2caRegs.I2CMDR.all != 0x2C20)
{
I2caRegs.I2CMDR.all = 0x2C20; // 0x2C20 --Send restart as master receiver
}


return I2caRegs.I2CDRR;
}

PLEASE help me

  • Hi Chandini,

    Are you following this procedure?


    Regards,

    Gautam

  • Gowtham

    Am following the same way i verified BB bit is 0 before proceding. my problem is no activity on SCL and SDA.

    as soon as the code is run, the SCL goes low and stays low. It's not pulsing at all. I'm not seeing SDATA doing any activity either. It stays as it is, high.

    if i check this after 1st data tranfer, execution stops at below line 

    while(I2caRegs.I2CMDR.bit.STP == 1) { //// wait until the STP bit is cleared from any previous master communication
    }

     

    whatever my big question is why am not getting any signals on SCL and SDA

  • Someone can help me please

  • Hello,

    I want to confirm:

    - How do you set GPIO28 and GPIO29?

    - What docking station/kit that you use for TMS320F28035? Is it TI board or custom board?

    - Please make sure the hardware connection of your sensor (MPU9150) is correct (typically need pull up).

    Best regards,

    Maria

  • Also you can refer to the attached i2c.c file in this thread

    http://e2e.ti.com/support/microcontrollers/c2000/f/171/p/266550/931938.aspx#931938

    Best regards,

    Maria

  • Maria

    am using custom board not TI board ..my hardware connection is proper i think there is internal pull up resistor on SCL and SDA [in MPU9150]. and value of pull up is 10k

  • ok i ll go through that file and get back to you

  • -am setting GPIO28 and GPIO29 as follows

    void InitI2CGpio()
    {

    EALLOW;

    GpioCtrlRegs.GPAPUD.bit.GPIO28 = 0;
    GpioCtrlRegs.GPAPUD.bit.GPIO29 = 0;

    GpioCtrlRegs.GPAQSEL2.bit.GPIO28 = 3;

    GpioCtrlRegs.GPAQSEL2.bit.GPIO29 = 3;

    GpioCtrlRegs.GPAMUX2.bit.GPIO28 = 2; // // 0=GPIO, 1=SCIRX-A, 2=I2CSDA-A, 3=TZ2
    GpioCtrlRegs.GPAMUX2.bit.GPIO29 = 2; // // 0=GPIO, 1=SCIRX-A, 2=I2CSDA-A, 3=TZ2

    EDIS;
    }

  • Are you using ControlSuite as your project template or are you making it from beginning?

    I just want to make sure that GPIO28 and GPIO29 are not set anywhere else. And I want to make sure your GPIO28 and GPIO29 pins don't have contention with SCI/ any other connection in your hardware.

    Best regards,

    Maria

  • Maria

    new project  ..am sure GPIO28 and GPIO29 are not set anywhere els..bcz this project is only for I2c with MPU9150.

    how cn i attach my project code here.??

     

  • chandini raj said:
    the SCL goes low and stays low.


    Did you already enable the I2C clock ( SysCtrlRegs.PCLKCR0.bit.I2CAENCLK = 1;)?

  • chandini raj said:
    how cn i attach my project code here.??

    Just paste your code here. Or insert the file using the clip icon in the editor.

  • zip file of my project is attached here..

    --am already enabled the I2C clock ( SysCtrlRegs.PCLKCR0.bit.I2CAENCLK = 1) 

    picolo_Test2.rar
  • #include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
    #include "Piccolo_Mpu9150.h"
    
    void   I2CA_Init(void);
    
    unsigned char accelerometer[6],gyroscope[6];
    
    
    void main(void)
    {
    
    // Step 1. Initialize System Control:
    // PLL, WatchDog, enable Peripheral Clocks
    // This example function is found in the DSP2803x_SysCtrl.c file.
       InitSysCtrl();
    
    // Step 2. Initalize GPIO:
    // This example function is found in the DSP2803x_Gpio.c file and
    // illustrates how to set the GPIO to it's default state.
    // InitGpio();
    // Setup only the GP I/O only for I2C functionality
       InitI2CGpio();
    
    // Step 3. Clear all interrupts and initialize PIE vector table:
    // Disable CPU interrupts
       DINT;
    
    // Initialize PIE control registers to their default state.
    // The default state is all PIE interrupts disabled and flags
    // are cleared.
    // This function is found in the DSP2803x_PieCtrl.c file.
       InitPieCtrl();
    
    // Disable CPU interrupts and clear all CPU interrupt flags:
       IER = 0x0000;
       IFR = 0x0000;
    
    // Initialize the PIE vector table with pointers to the shell Interrupt
    // Service Routines (ISR).
    // This will populate the entire table, even if the interrupt
    // is not used in this example.  This is useful for debug purposes.
    // The shell ISR routines are found in DSP2803x_DefaultIsr.c.
    // This function is found in DSP2803x_PieVect.c.
       InitPieVectTable();
    
    
        I2CA_Init();
    
       initSensorWithPiccolo();
       
       EINT;   // Enable Global interrupt INTM
       ERTM;   // Enable Global realtime interrupt DBGM
    
       while(1)
       	{
       		accelerometer[0]=readRegisterWithPiccolo(ACCEL_XOUT_H);
    //   		accelerometer[1]=readRegisterWithPiccolo(ACCEL_XOUT_L);
    //   		accelerometer[2]=readRegisterWithPiccolo(ACCEL_YOUT_H);
    //   		accelerometer[3]=readRegisterWithPiccolo(ACCEL_YOUT_L);
    //   		accelerometer[4]=readRegisterWithPiccolo(ACCEL_ZOUT_H);
    //   		accelerometer[5]=readRegisterWithPiccolo(ACCEL_ZOUT_L);
    //
    //   		gyroscope[0] 	=readRegisterWithPiccolo(GYRO_XOUT_H);
    //   		gyroscope[1]	=readRegisterWithPiccolo(GYRO_XOUT_L);
    //   		gyroscope[2]	=readRegisterWithPiccolo(GYRO_YOUT_H);
    //   		gyroscope[3]	=readRegisterWithPiccolo(GYRO_YOUT_L);
    //   		gyroscope[4]	=readRegisterWithPiccolo(GYRO_ZOUT_H);
    //   		gyroscope[5]	=readRegisterWithPiccolo(GYRO_ZOUT_L);
       	}
    
    }// end of main
    
    void I2CA_Init(void)
    {
    	I2caRegs.I2CMDR.all = 0x0000;
       // Initialize I2C
       I2caRegs.I2CSAR = 0x68;		// MEMS address
    
       I2caRegs.I2CPSC.all = 6;		    // 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.I2CIER.all = 0x3E;		// Enable SCD & ARDY interrupts
    
       I2caRegs.I2CMDR.all = 0x0020;	// Take I2C out of reset
       									// Stop I2C when suspended
    
       I2caRegs.I2CFFTX.all = 0x6000;	// Enable FIFO mode and TXFIFO
       I2caRegs.I2CFFRX.all = 0x2040;	// Enable RXFIFO, clear RXFFINT,
    
       return;
    }
    //===========================================================================
    // No more.
    //===========================================================================
    
    

    Can you try this main.c and let me know whether you get the pulse or not.

  • Maria

    same thing as before ,no activity on SDA and SCL ..SCL goes low and stays low.

  • Then I want to know when you test this ControlSuite example (C:\ti\controlSUITE\device_support\f2803x\v127\DSP2803x_examples_ccsv5\i2c_eeprom), do you get any pulse?

  • Maria

    ya already i tried using [C:\ti\controlSUITE\device_support\f2803x\v127\DSP2803x_examples_ccsv5\i2c_eeprom] controlsuit program ..if i simply run that program without connecting EEPROM am getting some signals on SDA and SCL . 

  • OK.

    Can you try with the files that I modified? 5381.picolo_Test3.zip

    I modified your read and write functions based on my I2C code (to EEPROM). I adapted it for your I2C sensor.

    In main, I disable the write function to see whether you get the pulse or not.

    Also, when you debug your code and pause it, does it stop in the same line?

  • Maria

    thanks again for your replay.. ya i tried with those files ..yes now am getting some signals on SCL and SDA lines

  • That's good as a start!

    Then I hope you can continue modifying it for your application.


    Good luck!

    Best regards,

    Maria

  • ya i ll take care from now on..good thing is that after uncommenting my initSensorWithPiccolo() in the main als am getting some signals on SDA and SCL lines

    thanks a lot Maria

  • That's good. You're welcome!

    Best regards,

    Maria