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.

MSP430G2553: MSP430G2553 communicate with tm4c123 or TM4C1294NCPDT using i2c

Part Number: MSP430G2553
Other Parts Discussed in Thread: TM4C1294NCPDT,

Hi Team,

Good day. We need your help to check our customer's concern. 

Mainly they want to use msp430g2553 to communicate with tm4c123/tm4c1294ncpdt using i2c where msp430 is master and tm4c123 /tm4c1294 is a slave. 

Kindly check the attached code slave/master here. 

master-tm4c1294 code.txt and slavemsp430 code.txt

Only 5 data send when it's completely working good and then they want to send array of data msp430 to tm4c1294.

We are open for any suggestion as well. Looking forward to your response and thank you in advance. 

Best regards,

Jonathan

  • Hi Jonathan,

    I checked the code of the MSP part. You are using the msp430g2553 as the I2C slave in your code. And it works in echo mode, the TxData is [0x11, 0x22, 0x33, 0x44, 0x55]. What is your concerns here?

    Best regards,

    Cash Hao

  • Cash Hao

    communication between two board its not working

  • Hi Cash,

    Thank you for the response, Yes the main issue is communication between two board its not working. Govind is our customer by the way.  

    If I understand it correctly, the code was use to communicate but failed. They have send 5 byte(0x11,0x22,0x33,0x44,0x55) by msp430 and receive by tm4c1294 but getting only 1 byte(0x11)  received. 

    Best regards,

    Jonathan

  • ----- tm4c:

    >       I2CMasterIntEnableEx(I2C0_BASE, I2C_MASTER_INT_DATA);

    Since main() is polling, I expect you shouldn't enable the interrupt.

    -------

    I don't see any (active) calls to I2CMasterBusy() here. I2CMasterDataGet doesn't interlock on Busy either. I would expect to see a

    > while(I2CMasterBusy(I2C0_BASE));   // Wait for completion

     before every call to I2CMasterDataGet.

    ----- msp430:

    >  UCB0I2CIE |= UCSTPIE + UCSTTIE; // Enable STT and STP interrupt

    This will cause USCIAB0RX_ISR to wake up main on a start, which will cause main to reset PTxData, and send the first byte (0x11) twice. You don't seem to have any use for the STTIE, so I suggest instead:

    >  UCB0I2CIE |= UCSTPIE; // Enable STP interrupt

  • Hi Bruce, 

    Our customer have modified the code with your help but still encountering issue.

    Customer still receive1 byte (0x11) only. 

    ----- tm4c:

    >       I2CMasterIntEnableEx(I2C0_BASE, I2C_MASTER_INT_DATA);

    Since main() is polling, I expect you shouldn't enable the interrupt.

    Customer have followed the no interrupt but still fails to communicate.

    I have attached here below the modified code for your checking. Thank you

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    master tm4c1294
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    
    #include <stdint.h>
    #include <stdbool.h>
    #include <math.h>
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/fpu.h"
    #include "driverlib/gpio.h"
    #include "driverlib/i2c.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/rom.h"
    #include "driverlib/rom_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/timer.h"
    #include "driverlib/uart.h"
    #include "utils/uartstdio.h"
    
    
    
    
    void ConfigureGPIO(void);
    void ConfigureI2C0(void);
    
    
    
    //*****************************************************************************
    // Define MSP430  I2C Address.
    //
    //*****************************************************************************
    #define SLAVE_ADDRESS  0x48
    
    //*****************************************************************************
    //
    // Counter to count the number of interrupts that have been called.
    //
    //*****************************************************************************
    static volatile uint32_t g_ui32Counter = 0;
    static uint32_t g_ui32DataRx;
    static bool g_bIntFlag = false;
    
    //****************************************************************************
    //
    // System clock rate in Hz.
    //
    //****************************************************************************
    uint32_t g_ui32SysClock;
    uint32_t pui32DataRx[5] = {0};
    uint32_t ui32Index;
    //*****************************************************************************
    //
    // Flags that contain the current value of the interrupt indicator as displayed
    // on the UART.
    //
    //*****************************************************************************
    //uint32_t g_ui32Flags;
    volatile uint_fast8_t g_ui32Flags;
    
    //*****************************************************************************
    //
    // The error routine that is called if the driver library encounters an error.
    //
    //*****************************************************************************
    #ifdef DEBUG
    void
    __error__(char *pcFilename, uint32_t ui32Line)
    {
    }
    #endif
    
    //*****************************************************************************
    //
    // Configure the UART and its pins.  This must be called before UARTprintf().
    //
    //*****************************************************************************
    void ConfigureUART(void)
    {
        //
        // Enable the GPIO Peripheral used by the UART.
        //
        MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    
        //
        // Enable UART0.
        //
        MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    
        //
        // Configure GPIO Pins for UART mode.
        //
        MAP_GPIOPinConfigure(GPIO_PA0_U0RX);
        MAP_GPIOPinConfigure(GPIO_PA1_U0TX);
        MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
        //
        // Initialize the UART for console I/O.
        //
        UARTStdioConfig(0, 115200, g_ui32SysClock);
    }
    
    /*
    
    void
    I2C0IntHandler(void)
    {
        UARTprintf("\n  I2C0MASTERIntHandler.........");
    
        //
        // Clear the I2C0 interrupt flag.
        //
        I2CMasterIntClear(I2C0_BASE);
    
        //
        // Read the data from the slave.
        //
        g_ui32DataRx = I2CMasterDataGet(I2C0_BASE);
    
        //
        // Set a flag to indicate that the interrupt occurred.
        //
        g_bIntFlag = true;
    }
    */
    //*****************************************************************************
    //
    // This example application demonstrates the use of the timers to generate
    // periodic interrupts.
    //
    //*****************************************************************************
    int main(void)
    {
        //
        // Run from the PLL at 120 MHz.
        // Note: SYSCTL_CFG_VCO_240 is a new setting provided in TivaWare 2.2.x and
        // later to better reflect the actual VCO speed due to SYSCTL#22.
        //
        g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                                 SYSCTL_OSC_MAIN |
                                                 SYSCTL_USE_PLL |
                                                 SYSCTL_CFG_VCO_480), 120000000);
    
        //
        // Initialize the UART and write status.
        //
        ConfigureUART();
    
    
        ConfigureI2C0();
    
        g_ui32Counter = 0;
    
        // Enable processor interrupts.
        //
    
        MAP_IntMasterEnable();
    
    
        // Loop forever while the timers run.
        //
        while(1)
        {/*
            //
               // Modify the data direction to true, so that seeing the address will
               // indicate that the I2C Master is initiating a read from the slave.
               //
               MAP_I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS, true);
    
               //
               // Setup for first read.  Use I2C_MASTER_CMD_BURST_RECEIVE_START
               // to start a burst mode read.  The I2C master continues to own
               // the bus at the end of this transaction.
               //
               MAP_I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
               while(I2CMasterBusy(I2C0_BASE));   // Wait for completion
    
               //
               // Read the first byte data from the slave.
               //
               pui32DataRx[0] = MAP_I2CMasterDataGet(I2C0_BASE);
    
    
              // while(I2CMasterBusy(I2C0_BASE));
               //
               // Setup for the second read.  Use I2C_MASTER_CMD_BURST_RECEIVE_CONT
               // to continue the burst mode read.  The I2C master continues to own
               // the bus at the end of this transaction.
               //
               MAP_I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
    
               while(I2CMasterBusy(I2C0_BASE));   // Wait for completion
    
               //
               // Read the second byte data from the slave.
               //
               pui32DataRx[1] = MAP_I2CMasterDataGet(I2C0_BASE);
    
    
               MAP_I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
    
    
               while(I2CMasterBusy(I2C0_BASE));   // Wait for completion
              //
              // Read the third byte data from the slave
              //
               pui32DataRx[2] = MAP_I2CMasterDataGet(I2C0_BASE);
    
    
               MAP_I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
               while(I2CMasterBusy(I2C0_BASE));   // Wait for completion
    
               //
               // Read the third byte data from the slave
               //
    
               pui32DataRx[3] = MAP_I2CMasterDataGet(I2C0_BASE);
    
    
               MAP_I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
                         while(I2CMasterBusy(I2C0_BASE));   // Wait for completion
    
                         //
                         // Read the third byte data from the slave
                         //
    
                         pui32DataRx[4] = MAP_I2CMasterDataGet(I2C0_BASE);
               //
               // Setup for the third read.  Use I2C_MASTER_CMD_BURST_RECEIVE_FINISH
               // to terminate the I2C transaction.  At the end of this transaction,
               // the STOP bit will be issued and the I2C bus is returned to the
               // Idle state.
               //
               MAP_I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);*/
    
            MAP_I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS, true);
    
                  //
                  // Do a dummy receive to make sure you don't get junk on the first receive.
                  //
               //   I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
               //  I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
    
               I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
               for(ui32Index = 0; ui32Index < 5; ui32Index++)
                  {
    
    
    
    
                //
                     // Read the data from the slave.
                     //
                     pui32DataRx[ui32Index] = MAP_I2CMasterDataGet(I2C0_BASE);
    
                     //
                     // Wait until master module is done transferring.
                     //
                     while(I2CMasterBusy(I2C0_BASE))
                     {
                     }
                     MAP_I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
    
    
                     //
                     // Display the data that the slave has received.
                     //
                     UARTprintf("Received: '%c'\n", pui32DataRx[ui32Index]);
                 }
               MAP_I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
    
        }
    }
    
    //*****************************************************************************
    //
    // Configures I2C port
    //
    //*****************************************************************************
    void ConfigureI2C0(void)
    {
          //
          // The I2C0 peripheral must be enabled before use.
          //
          MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
          MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);//
    
          //
          // Wait for the I2C0 module to be ready.
          //
          while(!SysCtlPeripheralReady(SYSCTL_PERIPH_I2C0))
          {
          }
          // Configure the pin muxing for I2C0 functions on port D0 and D1.
          // This step is not necessary if your part does not support pin muxing.
          //
          MAP_GPIOPinConfigure(GPIO_PB2_I2C0SCL);
          MAP_GPIOPinConfigure(GPIO_PB3_I2C0SDA);
    
          //
          // Select the I2C function for these pins.  This function will also
          // configure the GPIO pins pins for I2C operation, setting them to
          // open-drain operation with weak pull-ups.  Consult the data sheet
          // to see which functions are allocated per pin.
          //
          MAP_GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
          MAP_GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3); //
    
      //    IntEnable(INT_I2C0);
    
        //  I2CMasterIntEnableEx(I2C0_BASE, I2C_MASTER_INT_DATA);
    
          //
          // Enable and initialize the I2C0 master module.  Use the system clock for
          // the I2C0 module.  The last parameter sets the I2C data transfer rate.
          // If false the data rate is set to 100kbps and if true the data rate will
          // be set to 400kbps.  For this example we will use a data rate of 100kbps.
          //
          MAP_I2CMasterInitExpClk(I2C0_BASE, g_ui32SysClock, false);
    
          //
          // Enable the I2C0 MASTER module.
          //
          I2CMasterEnable(I2C0_BASE);
    
    }
    
    
    
    
    
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    slave msp430
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    
    
    #include <msp430.h>
    
    unsigned char *PTxData;                     // Pointer to TX data
    volatile unsigned char TXByteCtr;
    const unsigned char TxData[] =              // Table of data to transmit
    {
      0x11,
      0x22,
      0x33,
      0x44,
      0x55
    };
    
    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
      uart();
      i2c();
    
      while (1)
      {
        PTxData = (unsigned char *)TxData;      // Start of TX buffer
        TXByteCtr = 0;                          // Clear TX byte count
        __bis_SR_register(CPUOFF + GIE);        // Enter LPM0 w/ interrupts
                                                // Remain in LPM0 until master
                                                // finishes RX
        __no_operation();                       // Set breakpoint >>here<< and
      }                                         // read out the TXByteCtr counter
    }
    
    //------------------------------------------------------------------------------
    // The USCI_B0 data ISR is used to move data from MSP430 memory to the
    // I2C master. PTxData points to the next byte to be transmitted, and TXByteCtr
    // keeps track of the number of bytes transmitted.
    //------------------------------------------------------------------------------
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector = USCIAB0TX_VECTOR
    __interrupt void USCIAB0TX_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCIAB0TX_VECTOR))) USCIAB0TX_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
      UCB0TXBUF = *PTxData++;                   // Transmit data at address PTxData
      TXByteCtr++;                              // Increment TX byte counter
    }
    
    //------------------------------------------------------------------------------
    // The USCI_B0 state ISR is used to wake up the CPU from LPM0 in order to do
    // processing in the main program after data has been transmitted. LPM0 is
    // only exit in case of a (re-)start or stop condition when actual data
    // was transmitted.
    //------------------------------------------------------------------------------
    
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector = USCIAB0RX_VECTOR
    __interrupt void USCIAB0RX_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCIAB0RX_VECTOR))) USCIAB0RX_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
      UCB0STAT &= ~(UCSTPIFG + UCSTTIFG);       // Clear interrupt flags
      if (TXByteCtr)                            // Check TX byte counter
        __bic_SR_register_on_exit(CPUOFF);      // Exit LPM0 if data was
    }                                           // transmitted
    
    void i2c(void)
    {
    
          P1DIR |= 00000001;                        //LED
          P1OUT = 0x01;
          P1SEL |= BIT6 + BIT7;                     // Assign I2C pins to USCI_B0
          P1SEL2|= BIT6 + BIT7;                     // Assign I2C pins to USCI_B0
          UCB0CTL1 |= UCSWRST;                      // Enable SW reset
          UCB0CTL0 = UCMODE_3 + UCSYNC;             // I2C Slave, synchronous mode
          UCB0I2COA = 0x48;                         // Own Address is 048h
          UCB0CTL1 &= ~UCSWRST;                     // Clear SW reset, resume operation
          UCB0I2CIE |= UCSTPIE;           // Enable STT and STP interrupt
          IE2 |= UCB0TXIE;                          // Enable TX interrupt
    
    }
    
    void uart(void){
        if (CALBC1_1MHZ==0xFF)              // Check if calibration constant erased
           {
               while(1);                       // do not load program
           }
           DCOCTL = 0;                         // Select lowest DCO settings
           BCSCTL1 = CALBC1_1MHZ;              // Set DCO to 1 MHz
           DCOCTL = CALDCO_1MHZ;
    
           P1SEL = BIT1 + BIT2 ;               // Select UART RX/TX function on P1.1,P1.2
           P1SEL2 = BIT1 + BIT2;
    
           UCA0CTL1 |= UCSSEL_2;               // UART Clock -> SMCLK
           UCA0BR0 = 104;                      // Baud Rate Setting for 1MHz 9600
           UCA0BR1 = 0;                        // Baud Rate Setting for 1MHz 9600
           UCA0MCTL = UCBRS_1;                 // Modulation Setting for 1MHz 9600
           UCA0CTL1 &= ~UCSWRST;               // Initialize UART Module
    }
    

    Best regards,

    Jonathan

  • Just so I understand: The symptom is that you receive only a single byte (0x11). What happens after that? Does it hang or does it go back and read the same byte again?

    >            I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);

    In the previous version this said I2C_MASTER_CMD_BURST_RECEIVE_START. Using SINGLE will only read 1 byte, since it sets both START and STOP. I suggest you change it back.

  • Hi Bruce,

    Sorry for our late response. Our customer will check your questions and suggestions and I will update here once they have informed me. 

    They want to consider different solution. Can you please help them to provide a simple sample code if possible. A simple communication code between msp430 and tm4c1294. 

    Thank you,

    Jonathan

  • Searching the Forum, I found a reference to an application report on using I2C on the Tiva. There are examples (.zip) via a link in the PDF.

    https://www.ti.com/lit/an/spma073/spma073.pdf

  • Hi Bruce, 

    Thank you for sharing me this information. Moving on, our customer was able to communicate between both controller already. 

    Then encountered another issue. They added crc in the code but failed.

    Added crc code in slave code crc8() function.

    Please help to add crc section in master side.

    I have attached the working code here for your checking. Thank you.

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    slave msp430G2553  
    
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    
    
    #include <msp430.h>
    #include <stdbool.h>
    
    #include <math.h>
    #include <float.h>
    #include <stdlib.h>
    /*
     * main.c
     */
    
    const unsigned char TxData[] =              // Table of data to transmit
    {
      0x11,
      0x22,
      0x33,
      0x44,
      0x55
    };
    
    #define CRC_KEY 7
    #define DELAY_LIMIT 0xffff
    
    void ClockInitialise()
    {
    	DCOCTL = 0xE0;	//DCO = 7, MOD = 0
    
    	BCSCTL1 &= 0x8F;  //RSEL = 0, DCOR = 0, 20MHz Clock
    
    	BCSCTL2 = 0x0;
    
    	BCSCTL3 = 0;
    }
    
    void I2CInitialise()
    {
    	P1SEL |= BIT6 + BIT7;                     // Assign I2C pins to USCI_B0, P1.6 for SCL and P1.7 for SDA
    	P1SEL2|= BIT6 + BIT7;                     // Assign I2C pins to USCI_B0, P1.6 for SCL and P1.7 for SDA
    
    
    
    	UCB0CTL1 |= UCSWRST;                      // Enable SW reset, hold USCI logic in reset state
    	UCB0CTL0 = UCMODE_3 + UCSYNC;			//set to I2C mode, sync=1
        UCB0CTL1 |= UCSSEL_2;                       // Use SMCLK
    
    	UCB0BR0 = 4;                        // fSCL = SMCLK/12 = ~100kHz  10 for 100KHz 4 for 400KHz
    	UCB0BR1 = 0;
    
    
    	UCB0I2CIE = 0;
        IE2 &= ~(UCB0TXIE + UCB0RXIE);	//disable interrupts
    
       // UCB0CTL1 |= UCSSEL_2;
        UCB0CTL1 &= ~UCSWRST;
    }
    
    int I2CSendByte(unsigned char I2CSlaveAddress, unsigned char data)
    {
    	unsigned long int DelayCounter = 0;
    
    	UCB0CTL0 = UCMODE_3 + UCSYNC;             // I2C Slave, synchronous mode
    	UCB0I2COA = I2CSlaveAddress;
    
    	 UCB0CTL1 |= UCTR; //data in transmit direction
    	 UCB0CTL1 |= UCTXSTT; //Generate Start Condition
    	 	 	 	 	 	  //Send Start Byte
    
    	 while(!(IFG2 & UCB0TXIFG))  //if UCB0TXIFG != 0, wait here
    	 {
    		 DelayCounter ++;
    		 if (DelayCounter >= DELAY_LIMIT)
    			 break;
    	 }
    
    	 if (DelayCounter >= DELAY_LIMIT)
    		 return -1;
    
    	 UCB0TXBUF = data;				// send the data
    
    	 DelayCounter = 0;
    
    	 while(DelayCounter < DELAY_LIMIT && !(IFG2 & UCB0TXIFG))
    	 {
    		 DelayCounter++;
    	 }
    
    	 if (DelayCounter >= DELAY_LIMIT)
    		 return -1;
    
    	 UCB0CTL1 |= UCTXSTP;			//send stop bit
    
    	 DelayCounter = 0;
    
    	/* while(DelayCounter < DELAY_LIMIT && (UCB0CTL1 & UCTXSTP))
    	 {
    		 DelayCounter++;
    	 }*/
    
    	 if (DelayCounter >= DELAY_LIMIT)	//check if NACK condition occurred
    		 return -1;
    	 else
    		 return 0;
    
    }
    
    int I2CSendBytes(unsigned char I2CSlaveAddress, unsigned char *DataBuffer, unsigned int ByteCount, unsigned int *SentByte)
    {
    	unsigned long int DelayCounter = 0;
        unsigned int NumberOfBytesSent = 0;
        unsigned char *DataPointer;
    
        UCB0CTL0 = UCMODE_3 + UCSYNC;             // I2C Slave, synchronous mode
    	UCB0I2COA = I2CSlaveAddress;
    
         DataPointer = DataBuffer;
    
    	 UCB0CTL1 |= UCTR; //data in transmit direction
    	 UCB0CTL1 |= UCTXSTT; //Generate Start Condition
    	 	 	 	 	 	  //Send Start Byte
    
    	 while(!(IFG2 & UCB0TXIFG))  //if UCTXSTT != 0, wait here
    	 {
    		 DelayCounter ++;
    		 if (DelayCounter > DELAY_LIMIT)
    			 break;
    	 }
    
    	 if (DelayCounter >= DELAY_LIMIT)   //check if NACK condition occurred
    	 {
    		 *SentByte = NumberOfBytesSent;
    		 UCB0CTL1 |= UCTXSTP;
    		 return -1;
    	 }
    
    	 for(NumberOfBytesSent = 0; NumberOfBytesSent < ByteCount; NumberOfBytesSent++)
    	 {
    		 UCB0TXBUF= *DataPointer;
    
    		 DelayCounter = 0;
    
    		 while(DelayCounter < DELAY_LIMIT && (!(IFG2 & UCB0TXIFG) || (UCB0CTL1 & UCTXSTT)))	//check if the byte has been sent
    		 {
    			 DelayCounter++;
    		 }
    
    		 if (DelayCounter >= DELAY_LIMIT)	//check if NACK condition occurred
    		 {
    			 *SentByte = NumberOfBytesSent;
    			 UCB0CTL1 |= UCTXSTP;				//send stop condition
    			 return -1;
    		 }
    
    		 DataPointer++;
    	 }
    
    	 IFG2 &= ~UCB0TXIFG;
    	 UCB0CTL1 |= UCTXSTP;		//send stop bit
    
    	 DelayCounter = 0;
    
    	 while(DelayCounter < DELAY_LIMIT && ((UCB0CTL1 & UCTXSTP)))
    	 {
    		 DelayCounter++;
    	 }
    
    	 *SentByte =  NumberOfBytesSent;
    
    	 if (DelayCounter >= DELAY_LIMIT)	//check if NACK condition occurred
    	 {
    		 UCB0CTL1 |= UCSWRST;
    		 return -1;
    	 }
    	 else
    		 return 0;
    }
    
    int I2CWriteRegisterByte(unsigned char I2CSlaveAddress, unsigned char Register, unsigned char Data)
    {
    	unsigned char DataBuffer[2];
    	unsigned int SentByte = 0;
    
    
    	DataBuffer[0] = Register;
    	DataBuffer[1] = Data;
    
    	return(I2CSendBytes(I2CSlaveAddress, DataBuffer, 2, &SentByte));
    }
    
    int I2CWriteRegisterByteWithCRC(unsigned char I2CSlaveAddress, unsigned char Register, unsigned char Data)
    {
    	unsigned char DataBuffer[4];
    	unsigned int SentByte = 0;
    
        DataBuffer[0] = I2CSlaveAddress << 1;
    	DataBuffer[1] = Register;
    	DataBuffer[2] = Data;
    	DataBuffer[3] = CRC8(DataBuffer, 3, CRC_KEY);
    
    	return(I2CSendBytes(I2CSlaveAddress, DataBuffer + 1, 3, &SentByte));
    }
    
    int I2CWriteRegisterWordWithCRC(unsigned char I2CSlaveAddress, unsigned char Register, unsigned int Data)
    {
    	unsigned char DataBuffer[6];
    	unsigned int SentByte = 0;
    
        DataBuffer[0] = I2CSlaveAddress << 1;
    	DataBuffer[1] = Register;
    	DataBuffer[2] = LOW_BYTE(Data);
    	DataBuffer[3] = CRC8(DataBuffer, 3, CRC_KEY);
    	DataBuffer[4] = HIGH_BYTE(Data);
    	DataBuffer[5] = CRC8(DataBuffer + 4, 1, CRC_KEY);
    
    	return(I2CSendBytes(I2CSlaveAddress, DataBuffer + 1, 5, &SentByte));
    }
    
    int I2CWriteBlockWithCRC(unsigned char I2CSlaveAddress, unsigned char StartAddress, unsigned char *Buffer, unsigned char Length)
    {
    	unsigned char *BufferCRC, *Pointer;
    	int i;
    	unsigned int SentByte = 0;
    	int result;
    
    	BufferCRC = (unsigned char*)malloc(2*Length + 2);
    	if (NULL == BufferCRC)
    		return -1;
    
    	Pointer = BufferCRC;
    	*Pointer = I2CSlaveAddress << 1;
    	Pointer++;
    	*Pointer = StartAddress;
    	Pointer++;
    	*Pointer = *Buffer;
    	Pointer++;
    	*Pointer = CRC8(BufferCRC, 3, CRC_KEY);
    
    	for(i = 1; i < Length; i++)
    	{
            Pointer++;
            Buffer++;
            *Pointer = *Buffer;
    		*(Pointer + 1) = CRC8(Pointer, 1, CRC_KEY);
    		Pointer++;
    	}
    
    	result = I2CSendBytes(I2CSlaveAddress, BufferCRC + 1, 2*Length + 1, &SentByte);
    
    	free(BufferCRC);
    	BufferCRC = NULL;
    
    	return result;
    }
    
    int I2CWriteRegisterWord(unsigned char I2CSlaveAddress, unsigned char Register, unsigned int Data)
    {
    	unsigned char DataBuffer[3];
    	unsigned int SentByte = 0;
    
    	DataBuffer[0] = Register;
    	DataBuffer[1] = LOWBYTE(Data);
    	DataBuffer[2] = HIGHBYTE(Data);
    
    	return(I2CSendBytes(I2CSlaveAddress, DataBuffer, 3, &SentByte));
    }
    
    int I2CReadBytes(unsigned char I2CSlaveAddress, unsigned char *DataBuffer, unsigned int ExpectedByteNumber, unsigned int *NumberOfReceivedBytes)
    {
    	unsigned long int DelayCounter = 0;
        unsigned char *DataPointer;
        unsigned int *NumberOfReceivedBytesPointer;
    
        NumberOfReceivedBytesPointer = NumberOfReceivedBytes;
        *NumberOfReceivedBytesPointer = 0;
    
        UCB0CTL0 = UCMODE_3 + UCSYNC;             // I2C Slave, synchronous mode
    
        DataPointer = DataBuffer;
        UCB0I2COA = I2CSlaveAddress;
    
    	UCB0CTL1 &= ~(UCTR); //data in receive direction
    
    	UCB0CTL1 |= UCTXSTT; //Generate Start Condition
    
    	 while((UCB0CTL1 & UCTXSTT)
    			 )  //if UCTXSTT != 0, wait here
    	 {
    		 DelayCounter ++;
    		 if (DelayCounter >= DELAY_LIMIT)
    			 break;
    	 }
    
    	 if (DelayCounter >= DELAY_LIMIT || UCB0STAT & UCNACKIFG)   //check if NACK condition occurred
    		 return -1;
    
    	 for(*NumberOfReceivedBytesPointer = 0; *NumberOfReceivedBytesPointer < ExpectedByteNumber; (*NumberOfReceivedBytesPointer)++)
    	 {
    		 if(*NumberOfReceivedBytesPointer + 1 == ExpectedByteNumber)
    			 UCB0CTL1 |= UCTXSTP;
    
    		 DelayCounter = 0;
    
    		 while(DelayCounter < DELAY_LIMIT && !(IFG2 & UCB0RXIFG))
    		 {
    			 DelayCounter++;
    		 }
    
    		 if(DelayCounter == DELAY_LIMIT)
    		 {
    			 UCB0CTL1 |= UCSWRST;   //if I2C overtime condition occurred, reset I2C engine
    			 return -1;
    		 }
    
    		 *DataPointer = UCB0RXBUF;
    
    		 DataPointer++;
    	 }
    
    	 DelayCounter = 0;
    	 while(DelayCounter < DELAY_LIMIT && (UCB0CTL1 & UCTXSTP))
    	 {
    		 DelayCounter++;
    	 }
    
    	 if(DelayCounter >= DELAY_LIMIT)
    	 {
    		 UCB0CTL1 |= UCSWRST;
    		 return -1;
    	 }
    
    	 return 0;
    
    }
    
    int I2CReadRegisterByte(unsigned char I2CSlaveAddress, unsigned char Register, unsigned char *Data)
    {
    	unsigned char TargetRegister = Register;
    	unsigned int SentByte = 0;
    	unsigned int ReadDataCount = 0;
        int ReadStatus = 0;
        int WriteStatus = 0;
    
    	WriteStatus = I2CSendBytes(I2CSlaveAddress, &TargetRegister, 1, &SentByte);
    
    	ReadStatus = I2CReadBytes(I2CSlaveAddress, Data, 1, &ReadDataCount);
    
    	if (ReadStatus != 0 || WriteStatus != 0)
    	{
    		return -1;
    	}
    
    	return 0;
    }
    
    int I2CReadBlock(unsigned char I2CSlaveAddress, unsigned char StartRegisterAddress, unsigned char *Buffer, unsigned int BlockSize, unsigned int *NumberOfBytes)
    {
    	unsigned char TargetRegister = StartRegisterAddress;
    	unsigned int SentByte = 0;
    	int ReadStatus = 0;
    	int WriteStatus = 0;
    
    	WriteStatus = I2CSendBytes(I2CSlaveAddress, &TargetRegister, 1, &SentByte);
    
    	ReadStatus = I2CReadBytes(I2CSlaveAddress, Buffer, BlockSize, NumberOfBytes);
    
    	if(ReadStatus != 0 || WriteStatus != 0)
    	{
    		return -1;
    	}
    
    	return 0;
    }
    
    unsigned char CRC8(unsigned char *ptr, unsigned char len,unsigned char key)
    {
    	unsigned char i;
    	unsigned char crc=0;
    	while(len--!=0)
    	{
    		for(i=0x80; i!=0; i/=2)
    		{
    			if((crc & 0x80) != 0)
    			{
    				crc *= 2;
    				crc ^= key;
    			}
    			else
    				crc *= 2;
    
    			if((*ptr & i)!=0)
    				crc ^= key;
    		}
    		ptr++;
    	}
    	return(crc);
    }
    
    
    
    
    int I2CReadRegisterByteWithCRC(unsigned char I2CSlaveAddress, unsigned char Register, unsigned char *Data)
    {
    	unsigned char TargetRegister = Register;
    	unsigned int SentByte = 0;
    	unsigned char ReadData[2];
    	unsigned int ReadDataCount = 0;
    	unsigned char CRCInput[2];
    	unsigned char CRC = 0;
        int ReadStatus = 0;
        int WriteStatus = 0;
    
    	WriteStatus = I2CSendBytes(I2CSlaveAddress, &TargetRegister, 1, &SentByte);
    
    	ReadStatus = I2CReadBytes(I2CSlaveAddress, ReadData, 2, &ReadDataCount);
    
    	if (ReadStatus != 0 || WriteStatus != 0)
    	{
    		return -1;
    	}
    
    	CRCInput[0] = (I2CSlaveAddress << 1) + 1;
    	CRCInput[1] = ReadData[0];
    
    	CRC = CRC8(CRCInput, 2, CRC_KEY);
    
    	if (CRC != ReadData[1])
    		return -1;
    
    	*Data = ReadData[0];
    	return 0;
    }
    
    int I2CReadRegisterWordWithCRC(unsigned char I2CSlaveAddress, unsigned char Register, unsigned int *Data)
    {
    	unsigned char TargetRegister = Register;
    	unsigned int SentByte = 0;
    	unsigned char ReadData[4];
    	unsigned int ReadDataCount = 0;
    	unsigned char CRCInput[2];
    	unsigned char CRC = 0;
        int ReadStatus = 0;
        int WriteStatus = 0;
    
    	WriteStatus = I2CSendBytes(I2CSlaveAddress, &TargetRegister, 1, &SentByte);
    
    	ReadStatus = I2CReadBytes(I2CSlaveAddress, ReadData, 4, &ReadDataCount);
    
    	if (ReadStatus != 0 || WriteStatus != 0)
    	{
    		return -1;
    	}
    
    	CRCInput[0] = (I2CSlaveAddress << 1) + 1;
    	CRCInput[1] = ReadData[0];
    
    	CRC = CRC8(CRCInput, 2, CRC_KEY);
    
    	if (CRC != ReadData[1])
    		return -1;
    
    	CRC = CRC8(ReadData + 2, 1, CRC_KEY);
    
    	if (CRC != ReadData[3])
    		return -1;
    
    	*Data = ReadData[0];
    
    	*Data = (*Data << 8) + ReadData[2];
    
    	return 0;
    }
    
    int I2CReadBlockWithCRC(unsigned char I2CSlaveAddress, unsigned char Register, unsigned char *Buffer, unsigned char Length)
    {
    	unsigned char TargetRegister = Register;
    	unsigned int SentByte = 0;
    	unsigned char *ReadData = NULL, *StartData = NULL;
    	unsigned int ReadDataCount = 0;
    	unsigned char CRCInput[2];
    	unsigned char CRC = 0;
        int ReadStatus = 0;
        int WriteStatus = 0;
        int i;
    
        StartData = (unsigned char *)malloc(2 * Length);
    
        if (NULL == StartData)
        	return -1;
    
        ReadData = StartData;
    
    	WriteStatus = I2CSendBytes(I2CSlaveAddress, &TargetRegister, 1, &SentByte);
    
    	ReadStatus = I2CReadBytes(I2CSlaveAddress, ReadData, 2 * Length, &ReadDataCount);
    
    	if (ReadStatus != 0 || WriteStatus != 0)
    	{
    		free(StartData);
    		StartData = NULL;
    
    		return -1;
    	}
    
    	CRCInput[0] = (I2CSlaveAddress << 1) + 1;
    	CRCInput[1] = *ReadData;
    
    	CRC = CRC8(CRCInput, 2, CRC_KEY);
    
    	ReadData++;
    	if (CRC != *ReadData)
    	{
    		free(StartData);
    		StartData = NULL;
    		return -1;
    	}
    	else
    		*Buffer = *(ReadData - 1);
    
    	for(i = 1; i < Length; i++)
    	{
    		ReadData++;
    		CRC = CRC8(ReadData, 1, CRC_KEY);
    		ReadData++;
    		Buffer++;
    
    		if (CRC != *ReadData)
    		{
    			free(StartData);
    			StartData = NULL;
    
    			return -1;
    		}
    		else
    			*Buffer = *(ReadData - 1);
    	}
    
    	free(StartData);
    	StartData = NULL;
    
    	return 0;
    }
    
    int main(void)
    {
    	int Result;
    int i,a;
        WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
    
       // DISABLE_INT;
    
       //ClockInitialise();
    
    
        I2CInitialise();
    
    int count = 0;
    
        while(1)
        {
            for( i=0 ; i<5 ;i++)
            {
    
             //   I2CSendByte(0x48,TxData[i]);
    
               I2CWriteRegisterByteWithCRC(0x48, TxData[i],TxData[i]);
    
            }
          //  i=0;
            // I2CWriteRegisterByteWithCRC(0x48, 0x41, 0x42)
    
    
    count++;
    
        }
    
    	return Result;
    }
    
    
    
    
    
    
    
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    master tm4c1294ncpdt
    
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    
    
    
    #include <stdint.h>
    #include <stdbool.h>
    #include "driverlib/debug.h"
    #include "inc/hw_types.h"
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "driverlib/gpio.h"
    #include "driverlib/i2c.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/uart.h"
    #include "utils/uartstdio.h"
    
    #define SLAVE_ADDRESS_EXT  0x48
    //uint8_t Checksum;
    #define NUM_OF_I2CBYTES   5    //RX_Bytes
    
    uint8_t Command  =   0x03;       //TX_Command
    
    //*****************************************************************************
    //
    // Enumerated Data Types for Master State Machine
    //
    //*****************************************************************************
    enum I2C_MASTER_STATE
    {
        I2C_OP_IDLE = 0,
        I2C_OP_RXDATA,
        I2C_OP_STOP,
    
    };
    
    //*****************************************************************************
    //
    // Global variable for Delay Count
    //
    //*****************************************************************************
    volatile uint16_t data;
    volatile uint8_t  g_ui8MasterTxData[1];
    volatile uint16_t  g_ui8MasterRxData[NUM_OF_I2CBYTES];
    volatile uint8_t  g_ui8MasterCurrState;
    volatile uint8_t  g_ui8MasterPrevState;
    volatile bool     g_bI2CRepeatedStart;
    volatile uint8_t  g_ui8MasterBytes       = NUM_OF_I2CBYTES;
    volatile uint8_t  g_ui8MasterBytesLength = NUM_OF_I2CBYTES;
    
    uint32_t ui32I2CMasterInterruptStatus;
    
    //*****************************************************************************
    //
    // Interrupt Handler for I2C Master Interface
    //
    //*****************************************************************************
    void
    I2C2IntHandler(void)
    {
    
        //
        // Toggle PL4 High to Indicate Entry to ISR
        //
        GPIOPinWrite(GPIO_PORTL_BASE, GPIO_PIN_4, GPIO_PIN_4);
    
        //
        // Get the masked interrupt status and clear the flags
        //
        ui32I2CMasterInterruptStatus = I2CMasterIntStatusEx(I2C2_BASE, true);
        I2CMasterIntClearEx(I2C2_BASE, ui32I2CMasterInterruptStatus);
    
    
        //
        // Execute the State Machine
        //
        switch (g_ui8MasterCurrState) {
        case I2C_OP_IDLE:
            //
            // Move from IDLE to Transmit Address State
            //
            g_ui8MasterPrevState = g_ui8MasterCurrState;
    
            //
            // Write the upper bits of the page to the Slave
            //
            I2CMasterSlaveAddrSet(I2C2_BASE, SLAVE_ADDRESS_EXT, false);
            I2CMasterDataPut(I2C2_BASE, 0x01);
            I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_SINGLE_SEND);
            g_ui8MasterCurrState = I2C_OP_STOP;
    
            break;
    
    
        case I2C_OP_RXDATA:
            //
            // Move the current state to the previous state
            // Else continue with the transmission till last byte
            //
            g_ui8MasterPrevState = g_ui8MasterCurrState;
    
    
            //
            // If Address has been NAK'ed then go to stop state
            // If a Stop condition is seen due to number of bytes getting
            // done then move to STOP state and read the last data byte
            //
            if(ui32I2CMasterInterruptStatus & I2C_MASTER_INT_NACK)
            {
                g_ui8MasterCurrState = I2C_OP_STOP;
            }
            else if(ui32I2CMasterInterruptStatus & I2C_MASTER_INT_STOP)
            {
                g_ui8MasterCurrState = I2C_OP_STOP;
                g_ui8MasterRxData[g_ui8MasterBytes++] = I2CMasterDataGet(I2C2_BASE);
               // UARTprintf("Received--1: '%x'\n",g_ui8MasterRxData[g_ui8MasterBytes]);
            }
            else
            {
                //
                // If end then NAK the byte and put Stop. Else continue
                // with ACK of the current byte and receive the next byte
                //
                if(g_bI2CRepeatedStart)
                {
                    //
                    // Send the Slave Address with RnW as Receive. If only byte is
                    // to be received then send START and STOP else send START
                    //
                    I2CMasterSlaveAddrSet(I2C2_BASE, SLAVE_ADDRESS_EXT, true);
                    if(g_ui8MasterBytesLength == 1)
                    {
                        I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
                    }
                    else
                    {
                        I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
                    }
    
                    //
                    // Change the Repeated Start Flag to false as the condition
                    // is now to receive data
                    //
                    g_bI2CRepeatedStart = false;
                }
                else if(g_ui8MasterBytes == (g_ui8MasterBytesLength - 2))
                {
                    //
                    // Read the byte from I2C Buffer and decrement the number
                    // of bytes counter to see if end has been reached or not
                    //
                    g_ui8MasterRxData[g_ui8MasterBytes++] = I2CMasterDataGet(I2C2_BASE);
    
                  // UARTprintf("Received---2: '%x'\n",g_ui8MasterRxData[g_ui8MasterBytes]);
                  // SysCtlDelay(120000);
                   //
                    // Put a STOP Condition on the bus
                    //
                    I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
                }
                else
                {
                    //
                    // Read the byte from I2C Buffer and decrement the number
                    // of bytes counter to see if end has been reached or not
                    //
                    g_ui8MasterRxData[g_ui8MasterBytes++] = I2CMasterDataGet(I2C2_BASE);
    
                    I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
                }
            }
    
            break;
        case I2C_OP_STOP:
            //
            // Move the current state to the previous state
            // Else continue with the transmission till last byte
            //
            g_ui8MasterPrevState = g_ui8MasterCurrState;
    
            break;
    
        default:
    
            break;
        }
    
    
    
        //
        // Toggle PL4 Low to Indicate Exit from ISR
        //
        GPIOPinWrite(GPIO_PORTL_BASE, GPIO_PIN_4, 0x0);
    }
    
    //*****************************************************************************
    //
    // This function sets up UART0 to be used for a console to display information
    // as the example is running.
    //
    //*****************************************************************************
    void
    InitConsole(void)
    {
    
        //
        // Enable GPIO port A which is used for UART0 pins.
        // TODO: change this to whichever GPIO port you are using.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    
        //
        // Configure the pin muxing for UART0 functions on port A0 and A1.
        // This step is not necessary if your part does not support pin muxing.
        // TODO: change this to select the port/pin you are using.
        //
        GPIOPinConfigure(GPIO_PA0_U0RX);
        GPIOPinConfigure(GPIO_PA1_U0TX);
    
        //
        // Enable UART0 so that we can configure the clock.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    
        //
        // Use the internal 16MHz oscillator as the UART clock source.
        //
        UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
    
        //
        // Select the alternate (UART) function for these pins.
        // TODO: change this to select the port/pin you are using.
        //
        GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
        //
        // Initialize the UART for console I/O.
        //
        UARTStdioConfig(0, 115200, 16000000);
    }
    
    //*****************************************************************************
    //
    // Main Program to Configure and Use the I2C Master
    //
    //*****************************************************************************
    int
    main(void)
    {
        uint32_t ui32SysClock;
        uint8_t  ui8Count;
        bool     bError;
    
        //
         // Setup System Clock for 120MHz
         //
         ui32SysClock = SysCtlClockFreqSet((SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_XTAL_25MHZ |
                             SYSCTL_CFG_VCO_480), 120000000);
    
        //
        // Set up the serial console to use for displaying messages.  This is
        // just for this example program and is not needed for EPI operation.
        //
        InitConsole();
    
        initI2C(ui32SysClock);
    
    
    
        //
        // Initialize and Configure the Master Module State Machine
        //
    
        while(1)
        {
    
       //////////// for TX Command //////////////
    
    /*
    
            g_ui8MasterCurrState = I2C_OP_IDLE;
            while(I2CMasterBusBusy(I2C2_BASE));
         //   g_ui8MasterBytes       = 0;
    
            //UARTprintf("Transmit %x bytes to external Slave...\n\n",Command);
    
            //
            // Trigger the Transfer using Software Interrupt
            //
            IntTrigger(INT_I2C2);
            while(g_ui8MasterCurrState != I2C_OP_STOP);
    
    
    
            SysCtlDelay(1000);
    
    */
    
         //////////// for RX Data //////////////
    
            g_ui8MasterCurrState = I2C_OP_RXDATA;
            g_bI2CRepeatedStart    = true;
            g_ui8MasterBytes       = 0;
    
            //
            // Trigger the Transfer using Software Interrupt
            //
            IntTrigger(INT_I2C2);
            while(g_ui8MasterCurrState != I2C_OP_STOP);
            g_ui8MasterCurrState = I2C_OP_IDLE;
    
            data = (g_ui8MasterRxData[0] + (g_ui8MasterRxData[1]<<8));
            //
            // Print Message before sending data
            //
            //UARTprintf("Receiving %d bytes from external Slave...\n\n",g_ui8MasterRxData[NUM_OF_I2CBYTES - 1]);
    
           // UARTprintf("Received--3: '%x'\n",g_ui8MasterRxData[g_ui8MasterBytes]);
            SysCtlDelay(12000);
            
    
    
    
    
        }
    }
    
    
    void initI2C(uint32_t ui32SysClock)
    {
        //
           // Enable GPIO for Configuring the I2C Interface Pins
           //
           SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);
    
           //
           // Wait for the Peripheral to be ready for programming
           //
           while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOL));
    
           //
           // Configure Pins for I2C2 Master Interface
           //
           GPIOPinConfigure(GPIO_PL1_I2C2SCL);
           GPIOPinConfigure(GPIO_PL0_I2C2SDA);
           GPIOPinTypeI2C(GPIO_PORTL_BASE, GPIO_PIN_0);
           GPIOPinTypeI2CSCL(GPIO_PORTL_BASE, GPIO_PIN_1);
    
           //
           // Configure GPIO Pin PL4 for Interrupt Time Processing
           //
           GPIOPinTypeGPIOOutput(GPIO_PORTL_BASE, GPIO_PIN_4);
           GPIOPinWrite(GPIO_PORTL_BASE, GPIO_PIN_4, 0x0);
    
    
           //
           // Stop the Clock, Reset and Enable I2C Module
           // in Master Function
           //
           SysCtlPeripheralDisable(SYSCTL_PERIPH_I2C2);
           SysCtlPeripheralReset(SYSCTL_PERIPH_I2C2);
           SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C2);
    
           //
           // Wait for the Peripheral to be ready for programming
           //
           while(!SysCtlPeripheralReady(SYSCTL_PERIPH_I2C2));
    
           //
           // Initialize and Configure the Master Module
           //
           I2CMasterInitExpClk(I2C2_BASE, ui32SysClock, false);  // false = 100khz , true = 400khz
    
           //
           // Enable Interrupts for Arbitration Lost, Stop, NAK, Clock Low
           // Timeout and Data.
           //
           I2CMasterIntEnableEx(I2C2_BASE, (I2C_MASTER_INT_STOP | I2C_MASTER_INT_NACK | I2C_MASTER_INT_DATA));
    
           //
           // Enable the Interrupt in the NVIC from I2C Master
           //
           IntEnable(INT_I2C2);
    
           //
           // Enable the Glitch Filter. Writting a value 0 will
           // disable the glitch filter
           // I2C_MASTER_GLITCH_FILTER_DISABLED
           // I2C_MASTER_GLITCH_FILTER_1
           // I2C_MASTER_GLITCH_FILTER_2 : Ideal Value when in HS Mode
           //                              for 120MHz clock
           // I2C_MASTER_GLITCH_FILTER_4
           // I2C_MASTER_GLITCH_FILTER_8 : Ideal Value when in Std,
           //                              Fast, Fast+ for 120MHz clock
           // I2C_MASTER_GLITCH_FILTER_16
           // I2C_MASTER_GLITCH_FILTER_32
           //
           I2CMasterGlitchFilterConfigSet(I2C2_BASE, I2C_MASTER_GLITCH_FILTER_8);
    }
    
    
    
    
    
    

    Best regards,

    Jonathan

  • If you need a CRC8() function on the Tm4C, I don't see any reason you couldn't just copy the one you're using on the G2553.

    It looks like the G2553 is configuring itself as a slave, but the rest of its code is acting as a master. I'm not quite sure what is intended here.

**Attention** This is a public forum