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/TMS320F28335: Difference in behavior of I2C module when executing from Flash compared to executing from RAM.

Part Number: TMS320F28335


Tool/software: Code Composer Studio

I2C signal ports has proper output when code executes from RAM with emulator attached to DSP board. 

However, I2C signal ports has no output when code executes from FLASH. With emulator attahced, I see I2caRegs.I2CMDR.allI2caRegs.I2CSTR.all and EPwm3Regs.TBCTR are all zero.

Code are same except for two more lines in code that run from FLASH. They are:

MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart); 
InitFlash();

I attach my code here for you to check if any sequence is wrong. Otherwise I think it is 'read from Flash' problem. 

//###########################################################################
//
//
//###########################################################################
// $TI Release: F2833x/F2823x Header Files and Peripheral Examples V142 $
// $Release Date: November  1, 2016 $
// $Copyright: Copyright (C) 2007-2016 Texas Instruments Incorporated -
//             http://www.ti.com/ ALL RIGHTS RESERVED $
//###########################################################################

#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File



void   I2CA_Init(void);
//Uint16 I2CA_WriteData(Uint16 slave_add, Uint16 add, Uint16 data);
Uint16 I2CA_WriteData(struct I2CMSG *msg);
void init_LCD();
void print_S();//print �spark�
void print_Format();
void print_N();//print num of spark
void print_FVP();//print freq voltage and power

//
// defines
//
#define I2C_LCD               0x3E
#define I2C_RGB               0x60
#define I2C_NUMBYTES          2
#define NU                    0x00
#define I2C_Command           0x80
#define I2C_Data              0x40

// Globals
//
struct I2CMSG I2cMsgOut1=
{
    I2C_MSGSTAT_SEND_WITHSTOP,
    I2C_LCD,
    I2C_NUMBYTES,
    NU,
    I2C_Command,
    0x12,                   // Msg Byte 1
};
struct I2CMSG I2cMsgOut2=
{
    I2C_MSGSTAT_SEND_WITHSTOP,
    I2C_RGB,
    I2C_NUMBYTES,
    NU,
    I2C_Command,
    0x12,                   // Msg Byte 1
};
struct I2CMSG I2cMsgOut3=
{
    I2C_MSGSTAT_SEND_WITHSTOP,
    I2C_LCD,
    I2C_NUMBYTES,
    NU,
    I2C_Data,
    0x12,                   // Msg Byte 1
};

//#define Iref_min            0
//#define Vref               500

// To keep track of which way the compare value is moving
//#define EPWM_CMP_UP   1
//#define EPWM_CMP_DOWN 0

//#define lapse_set 1

Uint16 num_call=0;
Uint16 I2C_Format1[11]={'F',' ',' ',' ',' ','V',' ',' ',' ','P',' '};
//Uint16 I2C_Format2[9]={'P','=',' ',' ',' ','W',' ','N','='};
Uint16 I2C_Spark[5]={'S','P','A','R','K'};
Uint16 I2C_FVP[12]={'0','0','.','0',' ','0','0','0',' ','0','0','0'};// "00.0 000 000" ie 15.0(kHz) 450(V) 300(W)
Uint16 I2C_N[4]={0x30,0x30,0x30,0x30};// "0000" number of spark
Uint16 I2C_P[3]={0x30,0x30,0x30};

Uint16 Error;//i2C



//int sci_temp1,sci_temp2,sci_temp3;


void main(void)
 {
// Step 1. Initialize System Control:

// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.

    MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart); // Must have this line for ram download to dsp
    InitFlash();
    InitSysCtrl();
// Step 2. Initialize GPIO, ADC, SCI:


// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
//   InitGpio();
//   InitGpio14_15();  // Gpio14 for relay1, Gpio15 for relay2


   InitI2CGpio();
  // DELAY_US(1000);


  // DELAY_US(1000);


//   scib_xmit(0x2E);


// Step 3. Clear all interrupts and initialize PIE vector table*****************************
// Disable CPU interrupts
   DINT;
// Initialize the 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 DSP2833x_PieCtrl.c file.
   InitPieCtrl();
   // Define ADCCLK clock frequency ( less than or equal to 25 MHz )
   // Assuming InitSysCtrl() has set SYSCLKOUT to 150 MHz
//   EALLOW;
//   SysCtrlRegs.HISPCP.all = 3; // Sysclkout/6=25MHz
//   EDIS;
// 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 DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.
   InitPieVectTable();

//   scib_xmit(0x3E);

  // DELAY_US(10000);

// Step 4.  configure ePWM
// Synch controlling ePWM ***********************************************************
   DELAY_US(100000);
   I2CA_Init();//init I2C
//   scib_xmit(0x4E);


// Step 5. User specific code, enable interrupts:
 //  DELAY_US(1000);
   //init lcd
   init_LCD();
   DELAY_US(1000);
   //print_Format();//print Frequency format
   // Enable int1 which is connected to WAKEINT:


// Step 6. IDLE loop. Just sit and loop forever (optional):
   for(;;)
  {
       int a=0;
       GpioDataRegs.GPBSET.bit.GPIO54 = 1 ; // Main LED
       //print_FVP();

       I2cMsgOut1.MsgBuffer[0]=0x83;
       Error=I2CA_WriteData(&I2cMsgOut1);//where to print r1c3
       DELAY_US(10000);
       for(a=0;a<5;a++)
       {
           I2cMsgOut3.MsgBuffer[0]=I2C_Spark[a];
           Error=I2CA_WriteData(&I2cMsgOut3);
           DELAY_US(1000);
       }
       I2cMsgOut1.MsgBuffer[0]=0xC3;
       Error=I2CA_WriteData(&I2cMsgOut1);//where to print r2c3
       DELAY_US(10000);
       for(a=0;a<5;a++)
       {
           I2cMsgOut3.MsgBuffer[0]=I2C_Spark[a];
           Error=I2CA_WriteData(&I2cMsgOut3);
           DELAY_US(1000);
       }
       I2cMsgOut1.MsgBuffer[0]=0x83;
       Error=I2CA_WriteData(&I2cMsgOut1);//where to print r1c3
       DELAY_US(10000);
       for(a=0;a<5;a++)
       {
           I2cMsgOut3.MsgBuffer[0]=I2C_Spark[a];
           Error=I2CA_WriteData(&I2cMsgOut3);
           DELAY_US(1000);
       }
       I2cMsgOut1.MsgBuffer[0]=0xC3;
       Error=I2CA_WriteData(&I2cMsgOut1);//where to print r2c3
       DELAY_US(10000);
       for(a=0;a<5;a++)
       {
           I2cMsgOut3.MsgBuffer[0]=I2C_Spark[a];
           Error=I2CA_WriteData(&I2cMsgOut3);
           DELAY_US(1000);
       }
       I2cMsgOut1.MsgBuffer[0]=0x83;
       Error=I2CA_WriteData(&I2cMsgOut1);//where to print r1c3
       DELAY_US(10000);
       for(a=0;a<5;a++)
       {
           I2cMsgOut3.MsgBuffer[0]=I2C_Spark[a];
           Error=I2CA_WriteData(&I2cMsgOut3);
           DELAY_US(1000);
       }
       I2cMsgOut1.MsgBuffer[0]=0xC3;
       Error=I2CA_WriteData(&I2cMsgOut1);//where to print r2c3
       DELAY_US(10000);
       for(a=0;a<5;a++)
       {
           I2cMsgOut3.MsgBuffer[0]=I2C_Spark[a];
           Error=I2CA_WriteData(&I2cMsgOut3);
           DELAY_US(1000);
       }

       GpioDataRegs.GPBTOGGLE.bit.GPIO51 = 1 ;//LED blinking
  }
}
 // main function end


void I2CA_Init(void)
{
   // Initialize I2C
   I2caRegs.I2CSAR = 0x3E;        // Slave address - EEPROM control code

   #if (CPU_FRQ_150MHZ)             // Default - For 150MHz SYSCLKOUT
        I2caRegs.I2CPSC.all = 14;   // Prescaler - need 7-12 Mhz on module clk (150/15 = 10MHz)
   #endif
   #if (CPU_FRQ_100MHZ)             // For 100 MHz SYSCLKOUT
     I2caRegs.I2CPSC.all = 9;       // Prescaler - need 7-12 Mhz on module clk (100/10 = 10MHz)
   #endif

   I2caRegs.I2CCLKL = 10;           // NOTE: must be non zero
   I2caRegs.I2CCLKH = 5;            // NOTE: must be non zero
//   I2caRegs.I2CIER.all = 0x24;      // 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;


}


Uint16 I2CA_WriteData(struct I2CMSG *msg)
{
//   Uint16 i;

   // Wait until the STP bit is cleared from any previous master communication.
   // Clearing of this bit by the module is delayed until after the SCD bit is
   // set. If this bit is not checked prior to initiating a new message, the
   // I2C could get confused.
   if (I2caRegs.I2CMDR.bit.STP == 1)
   {
      return I2C_STP_NOT_READY_ERROR;
   }

   // Setup slave address
   I2caRegs.I2CSAR = msg->SlaveAddress;

   // Check if bus busy
   if (I2caRegs.I2CSTR.bit.BB == 1)
   {
      return I2C_BUS_BUSY_ERROR;
   }

   // Setup number of bytes to send
   // MsgBuffer + Address
   I2caRegs.I2CCNT = msg->NumOfBytes;

   // Setup data to send
   I2caRegs.I2CDXR = msg->MemoryLowAddr;
   I2caRegs.I2CDXR = *(msg->MsgBuffer);

   // Send start as master transmitter
   I2caRegs.I2CMDR.all = 0x6E20;
  // I2C_Count++;
   return I2C_SUCCESS;


}

void init_LCD()//70.5ms total
{
    //init 3 times, function set
    int i;
    for(i=0;i<3;i++)
    {
        I2cMsgOut1.MsgBuffer[0]=0x28;
        Error=I2CA_WriteData(&I2cMsgOut1);
        DELAY_US(15000);
    }
    //display control
    I2cMsgOut1.MsgBuffer[0]=0x0C;
    Error=I2CA_WriteData(&I2cMsgOut1);
    DELAY_US(10000);
    //clear display
    I2cMsgOut1.MsgBuffer[0]=0x01;
    Error=I2CA_WriteData(&I2cMsgOut1);
    DELAY_US(12000);
    //entry mode set
    I2cMsgOut1.MsgBuffer[0]=0x06;
        Error=I2CA_WriteData(&I2cMsgOut1);
    DELAY_US(500);
    //set RGB reg mode 1, output, mode2
    I2cMsgOut2.MemoryLowAddr=0x00;
    I2cMsgOut2.MsgBuffer[0]=0x00;
        Error=I2CA_WriteData(&I2cMsgOut2);
    DELAY_US(500);
    I2cMsgOut2.MemoryLowAddr=0x08;
    I2cMsgOut2.MsgBuffer[0]=0xFF;
        Error=I2CA_WriteData(&I2cMsgOut2);
    DELAY_US(500);
    I2cMsgOut2.MemoryLowAddr=0x01;
    I2cMsgOut2.MsgBuffer[0]=0x20;
        Error=I2CA_WriteData(&I2cMsgOut2);
    DELAY_US(500);
    //set RGB white
    I2cMsgOut2.MemoryLowAddr=0x04;
    I2cMsgOut2.MsgBuffer[0]=0x80;
        Error=I2CA_WriteData(&I2cMsgOut2);
    DELAY_US(500);
    I2cMsgOut2.MemoryLowAddr=0x03;
    I2cMsgOut2.MsgBuffer[0]=0x80;
        Error=I2CA_WriteData(&I2cMsgOut2);
    DELAY_US(500);
    I2cMsgOut2.MemoryLowAddr=0x02;
    I2cMsgOut2.MsgBuffer[0]=0x80;
        Error=I2CA_WriteData(&I2cMsgOut2);
    DELAY_US(500);
//    flag2=99;

}
//
//following functions are not used
//
void print_Format()
{
    int a;
    I2cMsgOut1.MsgBuffer[0]=0x81;
    Error=I2CA_WriteData(&I2cMsgOut1);//where to print r1c0
    DELAY_US(500);
    for(a=0;a<11;a++)
    {
        I2cMsgOut3.MsgBuffer[0]=I2C_Format1[a];
        Error=I2CA_WriteData(&I2cMsgOut3);
        //Error=I2CA_WriteData(I2C_LCD,0x40,I2C_Format1[a]);//
        DELAY_US(500);
    }
}

void print_N()
{
    int a;
    for(a=0;a<4;a++)
    {
        I2cMsgOut3.MsgBuffer[0]=I2C_N[a];
        Error=I2CA_WriteData(&I2cMsgOut3);
        //Error=I2CA_WriteData(I2C_LCD,0x40,I2C_N[a]);//
        DELAY_US(500);
    }
}


void print_S()
{
    int a;
    I2cMsgOut1.MsgBuffer[0]=0x01;
    Error=I2CA_WriteData(&I2cMsgOut1);//clear display
    DELAY_US(10000);
    I2cMsgOut1.MsgBuffer[0]=0x83;
        Error=I2CA_WriteData(&I2cMsgOut1);//where to print r1c3
    DELAY_US(500);
    for(a=0;a<5;a++)
    {
        I2cMsgOut3.MsgBuffer[0]=I2C_Spark[a];
            Error=I2CA_WriteData(&I2cMsgOut3);
        DELAY_US(500);
    }
}


void print_FVP()
{
    if(num_call==0)
    {
        I2cMsgOut1.MsgBuffer[0]=0xC0;
        Error=I2CA_WriteData(&I2cMsgOut1);//where to print r1c3
    }
    else
    {
        I2cMsgOut3.MsgBuffer[0]=I2C_FVP[num_call-1];
            Error=I2CA_WriteData(&I2cMsgOut3);
    }

    num_call++;
    if(num_call==13)
        num_call=0;
}

//===========================================================================
// No more.
//===========================================================================

//###########################################################################
//
// FILE:    Example_2833xI2C_eeprom.c
//
// TITLE:   I2C EEPROM Example
//
//! \addtogroup f2833x_example_list
//! <h1>I2C EEPROM (i2c_eeprom)</h1>
//!
//!  This program requires an external I2C EEPROM connected to
//!  the I2C bus at address 0x50. \n
//!  This program will write 1-14 words to EEPROM and read them back.
//!  The data written and the EEPROM address written to are contained
//!  in the message structure, \b I2cMsgOut1. The data read back will be
//!  contained in the message structure \b I2cMsgIn1.
//!
//!  \b Watch \b Variables \n
//!  - I2cMsgIn1
//!  - I2cMsgOut1
//
//###########################################################################
// $TI Release: F2833x Support Library v2.00.00.00 $
// $Release Date: Thu Oct 18 15:47:35 CDT 2018 $
// $Copyright:
// Copyright (C) 2009-2018 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
//   Redistributions of source code must retain the above copyright
//   notice, this list of conditions and the following disclaimer.
//
//   Redistributions in binary form must reproduce the above copyright
//   notice, this list of conditions and the following disclaimer in the
//   documentation and/or other materials provided with the
//   distribution.
//
//   Neither the name of Texas Instruments Incorporated nor the names of
//   its contributors may be used to endorse or promote products derived
//   from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################

//
// Included Files
//
#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File

//
// Note: I2C Macros used in this example can be found in the
// DSP2833x_I2C_defines.h file
//

//
// Function Prototypes
//
void   I2CA_Init(void);
Uint16 I2CA_WriteData(struct I2CMSG *msg);
//Uint16 I2CA_ReadData(struct I2CMSG *msg);
//__interrupt void i2c_int1a_isr(void);
void init_LCD();
void print_S();//print �spark�
void print_Format();
void print_N();//print num of spark
void print_FVP();//print freq voltage and power


#define I2C_LCD               0x3E
#define I2C_RGB               0x60
#define I2C_NUMBYTES          2
#define NU                    0x00
#define I2C_Command           0x80
#define I2C_Data              0x40

//
// Defines
//


//
// Globals
//



struct I2CMSG I2cMsgOut1=
{
    I2C_MSGSTAT_SEND_WITHSTOP,
    I2C_LCD,
    I2C_NUMBYTES,
    NU,
    I2C_Command,
    0x12,                   // Msg Byte 1
};
struct I2CMSG I2cMsgOut2=
{
    I2C_MSGSTAT_SEND_WITHSTOP,
    I2C_RGB,
    I2C_NUMBYTES,
    NU,
    I2C_Command,
    0x12,                   // Msg Byte 1
};
struct I2CMSG I2cMsgOut3=
{
    I2C_MSGSTAT_SEND_WITHSTOP,
    I2C_LCD,
    I2C_NUMBYTES,
    NU,
    I2C_Data,
    0x12,                   // Msg Byte 1
};

//struct I2CMSG I2cMsgIn1=
//{   I2C_MSGSTAT_SEND_NOSTOP,
//    I2C_SLAVE_ADDR,
//    I2C_NUMBYTES,
//    I2C_EEPROM_HIGH_ADDR,
//    I2C_EEPROM_LOW_ADDR
//};

//
// Globals
//
//struct I2CMSG *CurrentMsgPtr;               // Used in interrupts
//Uint16 PassCount;
//Uint16 FailCount;
Uint16 num_call=0;
Uint16 I2C_Format1[11]={'F',' ',' ',' ',' ','V',' ',' ',' ','P',' '};
//Uint16 I2C_Format2[9]={'P','=',' ',' ',' ','W',' ','N','='};
Uint16 I2C_Spark[5]={'S','P','A','R','K'};
Uint16 I2C_FVP[12]={'0','0','.','0',' ','0','0','0',' ','0','0','0'};// "00.0 000 000" ie 15.0(kHz) 450(V) 300(W)
Uint16 I2C_N[4]={0x30,0x30,0x30,0x30};// "0000" number of spark
Uint16 I2C_P[3]={0x30,0x30,0x30};
Uint16 Error;

//
// Main
//
void main(void)
{
//    Uint16 Error;
//    Uint16 i;

//    CurrentMsgPtr = &I2cMsgOut1;

    //
    // Step 1. Initialize System Control:
    // PLL, WatchDog, enable Peripheral Clocks
    // This example function is found in the DSP2833x_SysCtrl.c file.
    //
    InitSysCtrl();

    //
    // Step 2. Initialize GPIO:
    // This example function is found in the DSP2833x_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 DSP2833x_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 DSP2833x_DefaultIsr.c.
    // This function is found in DSP2833x_PieVect.c.
    //
    InitPieVectTable();

    //
    // Interrupts that are used in this example are re-mapped to
    // ISR functions found within this file.
    //
//    EALLOW;     // This is needed to write to EALLOW protected registers
//    PieVectTable.I2CINT1A = &i2c_int1a_isr;
//    EDIS;   // This is needed to disable write to EALLOW protected registers

    //
    // Step 4. Initialize all the Device Peripherals:
    // This function is found in DSP2833x_InitPeripherals.c
    //
    // InitPeripherals(); // Not required for this example
    DELAY_US(100000);
    I2CA_Init();

    //
    // Step 5. User specific code
    //

    //
    // Clear Counters
    //
//    PassCount = 0;
//    FailCount = 0;

    //
    // Clear incoming message buffer
    //
//    for (i = 0; i < I2C_MAX_BUFFER_SIZE; i++)
//    {
//        I2cMsgIn1.MsgBuffer[i] = 0x0000;
//    }

    //
    // Enable interrupts required for this example
    //

//    //
//    // Enable I2C interrupt 1 in the PIE: Group 8 interrupt 1
//    //
//    PieCtrlRegs.PIEIER8.bit.INTx1 = 1;
//
//    //
//    // Enable CPU INT8 which is connected to PIE group 8
//    //
//    IER |= M_INT8;
//    EINT;
    init_LCD();
   DELAY_US(1000);

    //
    // Application loop
    //
    for(;;)
    {
        int a=0;
        //
        GpioDataRegs.GPBSET.bit.GPIO54 = 1 ; // Main LED
               //print_FVP();

               I2cMsgOut1.MsgBuffer[0]=0x83;
               Error=I2CA_WriteData(&I2cMsgOut1);//where to print r1c3
               DELAY_US(10000);
               for(a=0;a<5;a++)
               {
                   I2cMsgOut3.MsgBuffer[0]=I2C_Spark[a];
                   Error=I2CA_WriteData(&I2cMsgOut3);
                   DELAY_US(1000);
               }
               I2cMsgOut1.MsgBuffer[0]=0xC3;
               Error=I2CA_WriteData(&I2cMsgOut1);//where to print r2c3
               DELAY_US(10000);
               for(a=0;a<5;a++)
               {
                   I2cMsgOut3.MsgBuffer[0]=I2C_Spark[a];
                   Error=I2CA_WriteData(&I2cMsgOut3);
                   DELAY_US(1000);
               }
               I2cMsgOut1.MsgBuffer[0]=0x83;
               Error=I2CA_WriteData(&I2cMsgOut1);//where to print r1c3
               DELAY_US(10000);
               for(a=0;a<5;a++)
               {
                   I2cMsgOut3.MsgBuffer[0]=I2C_Spark[a];
                   Error=I2CA_WriteData(&I2cMsgOut3);
                   DELAY_US(1000);
               }
               I2cMsgOut1.MsgBuffer[0]=0xC3;
               Error=I2CA_WriteData(&I2cMsgOut1);//where to print r2c3
               DELAY_US(10000);
               for(a=0;a<5;a++)
               {
                   I2cMsgOut3.MsgBuffer[0]=I2C_Spark[a];
                   Error=I2CA_WriteData(&I2cMsgOut3);
                   DELAY_US(1000);
               }
               I2cMsgOut1.MsgBuffer[0]=0x83;
               Error=I2CA_WriteData(&I2cMsgOut1);//where to print r1c3
               DELAY_US(10000);
               for(a=0;a<5;a++)
               {
                   I2cMsgOut3.MsgBuffer[0]=I2C_Spark[a];
                   Error=I2CA_WriteData(&I2cMsgOut3);
                   DELAY_US(1000);
               }
               I2cMsgOut1.MsgBuffer[0]=0xC3;
               Error=I2CA_WriteData(&I2cMsgOut1);//where to print r2c3
               DELAY_US(10000);
               for(a=0;a<5;a++)
               {
                   I2cMsgOut3.MsgBuffer[0]=I2C_Spark[a];
                   Error=I2CA_WriteData(&I2cMsgOut3);
                   DELAY_US(1000);
               }

               GpioDataRegs.GPBTOGGLE.bit.GPIO51 = 1 ;//LED blinking
    }
}   // end of main

//
// I2CA_Init -
//
void
I2CA_Init(void)
{
    //
    // Initialize I2C
    //
    I2caRegs.I2CSAR = 0x3E; // Slave address - EEPROM control code

#if (CPU_FRQ_150MHZ)            // Default - For 150MHz SYSCLKOUT
    //
    // Prescaler - need 7-12 Mhz on module clk (150/15 = 10MHz)
    //
    I2caRegs.I2CPSC.all = 14;
#endif
#if (CPU_FRQ_100MHZ)            // For 100 MHz SYSCLKOUT
    //
    // Prescaler - need 7-12 Mhz on module clk (100/10 = 10MHz)
    //
    I2caRegs.I2CPSC.all = 9;
#endif

    I2caRegs.I2CCLKL = 10;      // NOTE: must be non zero
    I2caRegs.I2CCLKH = 5;       // NOTE: must be non zero
//    I2caRegs.I2CIER.all = 0x24;   // Enable SCD & ARDY interrupts

    //
    // Take I2C out of reset
    // Stop I2C when suspended
    //
    I2caRegs.I2CMDR.all = 0x0020;

    I2caRegs.I2CFFTX.all = 0x6000;  // Enable FIFO mode and TXFIFO
    I2caRegs.I2CFFRX.all = 0x2040;  // Enable RXFIFO, clear RXFFINT,

    return;
}

//
// I2CA_WriteData -
//
Uint16
I2CA_WriteData(struct I2CMSG *msg)
{
//    Uint16 i;

    //
    // Wait until the STP bit is cleared from any previous master communication
    // Clearing of this bit by the module is delayed until after the SCD bit is
    // set. If this bit is not checked prior to initiating a new message, the
    // I2C could get confused.
    //
    if (I2caRegs.I2CMDR.bit.STP == 1)
    {
        return I2C_STP_NOT_READY_ERROR;
    }

    //
    // Setup slave address
    //
    I2caRegs.I2CSAR = msg->SlaveAddress;

    //
    // Check if bus busy
    //
    if (I2caRegs.I2CSTR.bit.BB == 1)
    {
        return I2C_BUS_BUSY_ERROR;
    }

    //
    // Setup number of bytes to send MsgBuffer + Address
    //
    I2caRegs.I2CCNT = msg->NumOfBytes;

    //
    // Setup data to send
    //
    //I2caRegs.I2CDXR = msg->MemoryHighAddr;
    I2caRegs.I2CDXR = msg->MemoryLowAddr;

//    for (i=0; i<msg->NumOfBytes; i++)
//    {
//        I2caRegs.I2CDXR = *(msg->MsgBuffer+i);
//    }
    I2caRegs.I2CDXR = *(msg->MsgBuffer);
    //
    // Send start as master transmitter
    //
    I2caRegs.I2CMDR.all = 0x6E20;

    return I2C_SUCCESS;
}


void init_LCD()//70.5ms total
{
    //init 3 times, function set
    int i;
    for(i=0;i<3;i++)
    {
        I2cMsgOut1.MsgBuffer[0]=0x28;
        Error=I2CA_WriteData(&I2cMsgOut1);
        DELAY_US(15000);
    }
    //display control
    I2cMsgOut1.MsgBuffer[0]=0x0C;
    Error=I2CA_WriteData(&I2cMsgOut1);
    DELAY_US(10000);
    //clear display
    I2cMsgOut1.MsgBuffer[0]=0x01;
    Error=I2CA_WriteData(&I2cMsgOut1);
    DELAY_US(12000);
    //entry mode set
    I2cMsgOut1.MsgBuffer[0]=0x06;
        Error=I2CA_WriteData(&I2cMsgOut1);
    DELAY_US(500);
    //set RGB reg mode 1, output, mode2
    I2cMsgOut2.MemoryLowAddr=0x00;
    I2cMsgOut2.MsgBuffer[0]=0x00;
        Error=I2CA_WriteData(&I2cMsgOut2);
    DELAY_US(500);
    I2cMsgOut2.MemoryLowAddr=0x08;
    I2cMsgOut2.MsgBuffer[0]=0xFF;
        Error=I2CA_WriteData(&I2cMsgOut2);
    DELAY_US(500);
    I2cMsgOut2.MemoryLowAddr=0x01;
    I2cMsgOut2.MsgBuffer[0]=0x20;
        Error=I2CA_WriteData(&I2cMsgOut2);
    DELAY_US(500);
    //set RGB white
    I2cMsgOut2.MemoryLowAddr=0x04;
    I2cMsgOut2.MsgBuffer[0]=0x80;
        Error=I2CA_WriteData(&I2cMsgOut2);
    DELAY_US(500);
    I2cMsgOut2.MemoryLowAddr=0x03;
    I2cMsgOut2.MsgBuffer[0]=0x80;
        Error=I2CA_WriteData(&I2cMsgOut2);
    DELAY_US(500);
    I2cMsgOut2.MemoryLowAddr=0x02;
    I2cMsgOut2.MsgBuffer[0]=0x80;
        Error=I2CA_WriteData(&I2cMsgOut2);
    DELAY_US(500);

}
//
//following functions are not used
//
void print_Format()
{
    int a;
    I2cMsgOut1.MsgBuffer[0]=0x81;
    Error=I2CA_WriteData(&I2cMsgOut1);//where to print r1c0
    DELAY_US(500);
    for(a=0;a<11;a++)
    {
        I2cMsgOut3.MsgBuffer[0]=I2C_Format1[a];
        Error=I2CA_WriteData(&I2cMsgOut3);
        //Error=I2CA_WriteData(I2C_LCD,0x40,I2C_Format1[a]);//
        DELAY_US(500);
    }
}

void print_N()
{
    int a;
    for(a=0;a<4;a++)
    {
        I2cMsgOut3.MsgBuffer[0]=I2C_N[a];
        Error=I2CA_WriteData(&I2cMsgOut3);
        //Error=I2CA_WriteData(I2C_LCD,0x40,I2C_N[a]);//
        DELAY_US(500);
    }
}


void print_S()
{
    int a;
    I2cMsgOut1.MsgBuffer[0]=0x01;
    Error=I2CA_WriteData(&I2cMsgOut1);//clear display
    DELAY_US(10000);
    I2cMsgOut1.MsgBuffer[0]=0x83;
        Error=I2CA_WriteData(&I2cMsgOut1);//where to print r1c3
    DELAY_US(500);
    for(a=0;a<5;a++)
    {
        I2cMsgOut3.MsgBuffer[0]=I2C_Spark[a];
            Error=I2CA_WriteData(&I2cMsgOut3);
        DELAY_US(500);
    }
}


void print_FVP()
{
    if(num_call==0)
    {
        I2cMsgOut1.MsgBuffer[0]=0xC0;
        Error=I2CA_WriteData(&I2cMsgOut1);//where to print r1c3
    }
    else
    {
        I2cMsgOut3.MsgBuffer[0]=I2C_FVP[num_call-1];
            Error=I2CA_WriteData(&I2cMsgOut3);
    }

    num_call++;
    if(num_call==13)
        num_call=0;
}

//
// End of File
//

Can anybody help me with this issue?

Thank you!

Xiaoming