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.

LAUNCHXL-F28069M: Simple I2C gyro reading code - migration from C2000Ware to Motorware

Part Number: LAUNCHXL-F28069M
Other Parts Discussed in Thread: MOTORWARE, C2000WARE

Hi,

Thanks to your help, I wrote the program that reads gyro x axis degrees using i2c communication.

I based it on example:

C:\ti\c2000\C2000Ware_1_00_06_00\device_support\f2806x\examples\c28\i2c_eeprom

Now I need to paste that code into motorware project (I want to change the speed of my motor by angle of sensor.)

I spent two days on it, and only progress i make is replacing floats data type to _IQ standard.

How can I access to i2c registers in motorware project? (How to write :    "I2caRegs.I2CSAR = 0x0068;" ?)

Is it possible not to use API? (it looks very difficult to write and use)

There is another problem -  InitI2CGpio(); function makes some pinout setup:

    GpioCtrlRegs.GPBPUD.bit.GPIO32 = 0; // Enable pull-up for GPIO32 (SDAA)
    GpioCtrlRegs.GPBPUD.bit.GPIO33 = 0;	// Enable pull-up for GPIO33 (SCLA)

    GpioCtrlRegs.GPBQSEL1.bit.GPIO32 = 3;  // Asynch input GPIO32 (SDAA)
    GpioCtrlRegs.GPBQSEL1.bit.GPIO33 = 3;  // Asynch input GPIO33 (SCLA)

    GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 1;
    GpioCtrlRegs.GPBMUX1.bit.GPIO33 = 1;

How can I do that setup in motorware project?

I attach my code:

void main(void)
{

    InitSysCtrl();

    InitI2CGpio();

    DINT;

	//init of i2c:
    I2caRegs.I2CSAR = 0x0068;       // Slave address - EEPROM control code
    I2caRegs.I2CPSC.all = 35;        // 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;

	//write to gyro 0x00 to wake it up
    I2caRegs.I2CSAR = 0x68;                         //Set slave address
    I2caRegs.I2CCNT = 2;                            //Set count to 5 characters plus 2 address bytes
    I2caRegs.I2CDXR = 0x6B;                         //register where i will write 0x00
    I2caRegs.I2CMDR.bit.TRX = 1;                    //Set to Transmit mode
    I2caRegs.I2CMDR.bit.MST = 1;                    //Set to Master mode
    I2caRegs.I2CMDR.bit.FREE = 1;                   //Run in FREE mode
    I2caRegs.I2CMDR.bit.STP = 1;                    //Stop when internal counter becomes 0
    I2caRegs.I2CMDR.bit.STT = 1;                    //Send the start bit, transmission will follow

    while(I2caRegs.I2CSTR.bit.XRDY == 0){};         //Do nothing till data is shifted out
    I2caRegs.I2CDXR = 0x00;

	
	//delay loop
    j=5;
    for(i = 0; i < 4000; i++){
        j++;
    }
    for(i = 0; i < 4000; i++){
        j--;
    }

	
    for(;;)
    {


        I2caRegs.I2CSAR = 0x68;                      //Set slave address
        I2caRegs.I2CCNT = 1;                         //Set count to 1 address bytes
        I2caRegs.I2CDXR = 0x3B;                      //Send high address of register to read
        I2caRegs.I2CMDR.bit.TRX = 1;                 //Set to Transmit mode
        I2caRegs.I2CMDR.bit.MST = 1;                 //Set to Master mode
        I2caRegs.I2CMDR.bit.FREE = 1;                //Run in FREE mode
        I2caRegs.I2CMDR.bit.STP = 0;                 //Dont release the bus after Tx
        I2caRegs.I2CMDR.bit.STT = 1;                 //Send the start bit, transmission will follow

		//delay loop
        j=5;
        for(i = 0; i < 1000; i++){
            j++;
        }
        for(i = 0; i < 1000; i++){
            j--;
        }

        while(I2caRegs.I2CSTR.bit.XRDY == 0){};      //Do nothing till data is shifted out
        I2caRegs.I2CCNT = 14;                        //read 14 bytes from eeprom
        I2caRegs.I2CMDR.bit.TRX = 0;                 //Set to Recieve mode
        I2caRegs.I2CMDR.bit.MST = 1;                 //Set to Master mode
        I2caRegs.I2CMDR.bit.FREE = 1;                //Run in FREE mode
        I2caRegs.I2CMDR.bit.STP = 1;                 //Stop when internal counter becomes 0
        I2caRegs.I2CMDR.bit.STT = 1;                 //Repeated start, Reception will follow

        for(i = 0; i < 14; i++){
             while(I2caRegs.I2CSTR.bit.RRDY == 0){}; //I2CDRR not ready to read?
             RxdData[i] = I2caRegs.I2CDRR;			 //data reading
        }
		
		//raw data to degrees 
        for(i = 0; i < 7; i++){
            GyroData[i] = RxdData[2*i]<<8 | RxdData[(2*i)+1];
        }
        x_acce=(GyroData[0]-333)*1.304347;
        y_acce=(GyroData[1]-333)*1.304347;
        z_acce=(GyroData[2]-333)*1.304347;
        x_angle=((atan2(-y_acce,-z_acce)+M_PI)*180)/M_PI;

		
		//delay loop
        j=5;
        for(i = 0; i < 60000; i++){
            j++;
        }
        for(i = 0; i < 60000; i++){
            j--;
        }



    }
}

Regards,
Wojciech

  • You can use the bitfield headers in a Motorware project, but you will need to add the correct include paths to the CCS project and inside of the source files in order for the compiler to recognize the structs. Have you tried replicating the CCS include tree that can be found in the I2C examples in C2000Ware? I would recommend starting there 

    Sean

  • Hi,

    Thanks for your reply,

    I added following line in lab_01 source file:

    #include "C:\ti\c2000\C2000Ware_1_00_06_00\device_support\f2806x\headers\include\F2806x_I2c_copy_for_motorware.h"

    File F2806x_I2c_copy_for_motorware.h is the same as F2806x_I2c.h file, I only changed Uint16 to uint16_t integer definitions.

    I added two include paths from c2000 project to "includes" in motorware project tree:

    include tree in c2000 project looks that:

    Then I compiled and there were no errors.

    Then I added one line of code in poj_lab01.c using bitfield:

      I2caRegs.I2CSAR = 0x0068;

    and then an error occurred:

    It looks like the registers structs are working because earlier there were errors like "identifier "I2caRegs" is undefined" in source file, and now they have disappeared.

    How to deal with the above "unresolved symbol _I2caRegs, first referenced in ./proj_lab01.obj" error?

    Regards,
    Wojciech

  • I think you're just missing a few more files. Can you copy the F2806x_GlobalVariableDefs.c and F2806x_Headers_nonBIOS.cmd files into your lab project? Does that get rid of the error about I2caRegs?

    Whitney
  • After adding these files, everything works.
    Thank you!
    Wojciech