Beispiel #1
0
int main(void) {
     SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
     SysCtlDelay(10000);

     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

     GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0);
     GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);

     GPIOPinConfigure(GPIO_PD0_I2C3SCL);
     GPIOPinConfigure(GPIO_PD1_I2C3SDA);

     SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3);

     I2CSlaveInit(I2C3_SLAVE_BASE, I2C_SLAVE_ADDRESS);
     I2CSlaveAddressSet(I2C3_SLAVE_BASE, I2C_SLAVE_ADDRESS, 0);
     I2CSlaveIntEnableEx(I2C3_SLAVE_BASE, I2C_SLAVE_INT_START|I2C_SLAVE_INT_STOP|I2C_SLAVE_INT_DATA);
     I2CSlaveEnable(I2C3_SLAVE_BASE);
     IntEnable(INT_I2C3);
	 IntMasterEnable();

     while(1) {
    	 SysCtlDelay(100000);
     }
 }
Beispiel #2
0
//Initialize as a slave
void TwoWire::begin(uint8_t address)
{

    if(i2cModule == NOT_ACTIVE) {
        i2cModule = BOOST_PACK_WIRE;
    }

    ROM_SysCtlPeripheralEnable(g_uli2cPeriph[i2cModule]);
    ROM_GPIOPinConfigure(g_uli2cConfig[i2cModule][0]);
    ROM_GPIOPinConfigure(g_uli2cConfig[i2cModule][1]);
    ROM_GPIOPinTypeI2C(g_uli2cBase[i2cModule], g_uli2cSDAPins[i2cModule]);
    ROM_GPIOPinTypeI2CSCL(g_uli2cBase[i2cModule], g_uli2cSCLPins[i2cModule]);
    slaveAddress = address;

    //Enable slave interrupts
    ROM_IntEnable(g_uli2cInt[i2cModule]);
    I2CSlaveIntEnableEx(SLAVE_BASE, I2C_SLAVE_INT_DATA | I2C_SLAVE_INT_STOP);
    HWREG(SLAVE_BASE + I2C_O_SICR) =
        I2C_SICR_DATAIC | I2C_SICR_STARTIC | I2C_SICR_STOPIC;

    //Setup as a slave device
    ROM_I2CMasterDisable(MASTER_BASE);
    I2CSlaveEnable(SLAVE_BASE);
    I2CSlaveInit(SLAVE_BASE, address);

    ROM_IntMasterEnable();

}
Beispiel #3
0
//*****************************************************************************
//! Initializes the I2C Slave block.
//!
//! \param ulBase is the base address of the I2C Slave module.
//! \param ucSlaveAddr 7-bit slave address
//!
//! This function initializes operation of the I2C Slave block.  Upon
//! successful initialization of the I2C blocks, this function will have set
//! the slave address and have enabled the I2C Slave block.
//!
//! The parameter \e ucSlaveAddr is the value that will be compared against the
//! slave address sent by an I2C master.
//!
//! \return None.
//*****************************************************************************
void
I2CSlaveInit(unsigned long ulBase, unsigned char ucSlaveAddr)
{
    // Check the arguments.
    ASSERT((ulBase == I2C0_SLAVE_BASE) || (ulBase == I2C1_SLAVE_BASE));
    ASSERT(!(ucSlaveAddr & 0x80));

    // Must enable the device before doing anything else.
    I2CSlaveEnable(ulBase);

    // Set up the slave address.
    HWREG(ulBase + I2C_O_SOAR) = ucSlaveAddr;
}
Beispiel #4
0
//*****************************************************************************
//
//! Initializes the I2C slave block
//!
//! \param ui8SlaveAddr 7-bit slave address
//!
//! This function initializes operation of the I2C slave block.  Upon
//! successful initialization of the I2C blocks, this function has set
//! the slave address has enabled the I2C slave block.
//!
//! The parameter \e ui8SlaveAddr is the value that will be compared against the
//! slave address sent by an I2C master.
//!
//! \return None
//
//*****************************************************************************
void
I2CSlaveInit(uint8_t ui8SlaveAddr)
{
    //
    // Check the arguments.
    //
    ASSERT(!(ui8SlaveAddr & 0x80));

    //
    // Must enable the device before doing anything else.
    //
    I2CSlaveEnable();

    //
    // Set up the slave address.
    //
    HWREG(I2CS_OAR) = ui8SlaveAddr;
}
Beispiel #5
0
//*****************************************************************************
//
//! Initializes the I2C Slave block.
//!
//! \param ulBase is the base address of the I2C Slave module.
//! \param ucSlaveAddr 7-bit slave address
//!
//! This function initializes operation of the I2C Slave block by configuring
//! the slave address and enabling the I2C Slave block.
//!
//! The parameter \e ucSlaveAddr is the value that is compared against the
//! slave address sent by an I2C master.
//!
//! \return None.
//
//*****************************************************************************
void
I2CSlaveInit(unsigned long ulBase, unsigned char ucSlaveAddr)
{
    //
    // Check the arguments.
    //
    ASSERT(I2CSlaveBaseValid(ulBase));
    ASSERT(!(ucSlaveAddr & 0x80));

    //
    // Must enable the device before doing anything else.
    //
    I2CSlaveEnable(ulBase);

    //
    // Set up the slave address.
    //
    HWREG(ulBase + I2C_O_SOAR) = ucSlaveAddr;
}
Beispiel #6
0
int ipmi_i2c_ram_dev_init(ipmi_i2c_ram_dev *dev, ipmi_i2c_bus *bus,
        unsigned char addr, unsigned long reg_size, char *reg_buf)
{
    ASSERT(dev);
    ASSERT(dev->bus);

    if ((addr == 0) ||                  // 不能是广播地址
        (addr & 0x80 == 0x80) ||        // 必须是7位地址,而不是8位地址
        (addr & 0x78 == 0x78))          // 不能是保留地址
    {
        return IPMI_I2C_ERR_ADDR;
    }

    INIT_LIST_HEAD(&dev->list);
    dev->bus            = bus;
    dev->my_addr        = addr;
    dev->ram_reg_size   = reg_size;
    dev->ram_reg        = reg_buf;
    dev->read_lock      = OSSemCreate(0);
    dev->write_lock     = OSSemCreate(0);

    if (dev->read_lock == (void*)0 || dev->write_lock == (void*)0)
    {
        return IPMI_I2C_ERR_INTER;
    }


    // 设置从设备地址
    I2CSlaveInit(dev->bus->i2c_hw_slave_base, dev->my_addr);

    // 开中断
    I2CSlaveIntEnable(dev->bus->i2c_hw_slave_base);
    IntEnable(dev->bus->i2c_int);
    IntMasterEnable();

    // 从设备使能
    I2CSlaveEnable(dev->bus->i2c_hw_slave_base);

    list_add(&dev->list, &ipmi_i2c_ram_dev_root.head);
    ipmi_i2c_ram_dev_root.count++;

    return 0;
}
Beispiel #7
0
//*****************************************************************************
// Defines IPMI Test Task
//*****************************************************************************
void ipmi_cmd_test_task(void *args)
{
#if 0
    // SPI0 master to FPGA test
    {
        uint8_t spibuf[3] = {0};
        uint8_t i;

        while (1)
        {
#if 1
            for (i = 0; i < 15; i++)
            {
                spibuf[0] = 0x00;
                spibuf[1] = i;
                spibuf[2] = 0xa0 + i;

                SPI_spi0_xfer(spibuf, 3, 0, 0);
                DEBUG("write_spi data=0x%x\r\n", spibuf[2]);
            }

            OSTimeDlyHMSM(0, 0, 1, 0);
#endif
            for (i = 0; i < 15; i++)
            {
                spibuf[0] = 0x80;
                spibuf[1] = i;
                spibuf[2] = 0;

                SPI_spi0_xfer(spibuf, 2, &spibuf[2], 1);
                DEBUG("read_spi data=0x%x\r\n", spibuf[2]);
            }

            OSTimeDlyHMSM(0, 0, 3, 0);
        }

    }
#endif

#if 0
    {
#define IPMB_SELF_ADDR  (0x71)
#define SLAVE_ADDR      (0x73)          // 定义从机地址
#if 0
        SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);                 // 使能I2C模块
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);                // 使能I2C管脚所在的GPIO模块
        GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);   // 配置相关管脚为I2C收发功能

        I2CSlaveInit(I2C0_SLAVE_BASE, SLAVE_ADDR);                  // I2C从机模块初始化
        I2CSlaveIntEnable(I2C0_SLAVE_BASE);                         // 使能I2C从机模块中断
        IntEnable(INT_I2C0);                                        // 使能I2C中断
        I2CSlaveEnable(I2C0_SLAVE_BASE);                            // 使能I2C从机
#endif
        {
            unsigned char ulDataTx[128] = {0};
            unsigned char i;
            unsigned long error;
            struct ipmi_req *req;

            ulDataTx[0] = IPMI_FRAME_CHAR[0];
            ulDataTx[1] = IPMI_FRAME_CHAR[1];
            ulDataTx[2] = IPMI_FRAME_CHAR[2];

            req = (struct ipmi_req *)&ulDataTx[3];

            req->msg.data_len = 7;
            req->msg.rs_sa = SLAVE_ADDR;
            req->msg.netfn = 0x06;
            req->msg.rs_lun = 0x0;
            req->msg.checksum1 = 0xff;
            req->msg.rq_sa = IPMB_SELF_ADDR;
            req->msg.rq_lun = 0x0;
            req->msg.rq_seq = 0x01;
            req->msg.cmd = 0x01;

            while (1) {
                OSTimeDlyHMSM(0, 0, 5, 0);
                DEBUG("netfn=0x%x cmd=0x%x rs_sa=0x%x rq_sa=0x%x ",
                    req->msg.netfn, req->msg.cmd, req->msg.rs_sa, req->msg.rq_sa);
                error = I2C_dev_write(I2C0_MASTER_BASE, SLAVE_ADDR, 0, 1, 20, &ulDataTx[0]);
                DEBUG("error=0x%x\r\n", error);
                //SysCtlDelay(10000000);
            }
        }
    }
#endif

#if 0
    // test for eeprom

    uint8_t val[32] = { 0 };
    uint8_t i;
    uint32_t error, addr;
    I2C_DEVICE at24xx_dev;

    I2C_i2c1_slave_dev_init(&at24xx_dev, 0x50, 2);

#if 0
    // set val to i
    for (i = 0; i < 32; i++) {
        val[i] = i;
    }

    // write to eeprom
    I2C_i2c1_slave_dev_set(&at24xx_dev, 0x1800, (uint8_t*)&val[0], 32);
    error = I2C_i2c1_master_write(&at24xx_dev);
    if (error)
    {
        DEBUG("write error=0x%x\r\n", error);
    }
    else
    {
        DEBUG("write to eeprom ok\r\n");
    }

    OSTimeDlyHMSM(0, 0, 1, 0);
#endif

#if 0
    // clear eeprom
    error = at24xx_clear(0x1800, 0x800);
    if (error)
    {
        DEBUG("clear error=0x%x\r\n", error);
    }
    else
    {
        DEBUG("clear OK\r\n");
    }
#endif

    // read eeprom
    for (addr = 0x1800; addr < 0x2000; addr += 32) {

        // clear val
        for (i = 0; i < 32; i++) {
            val[i] = 0;
        }

        // read from eeprom
        error = at24xx_read(addr, val, 32);
        //I2C_i2c1_slave_dev_set(&at24xx_dev, addr, (uint8_t*)&val[0], 32);
        //error = I2C_i2c1_master_read(&at24xx_dev);
        if (error)
        {
            DEBUG("read error=0x%x\r\n", error);
        }
        else
        {
            // show the read
            for (i = 0; i < 32; i++) {
                if (i % 8 == 0) {
                    DEBUG("\r\n0x%04x ", addr+i);
                }
                DEBUG("0x%02x ", val[i]);
            }
        }
    }


    while (1)
    {
        OSTimeDlyHMSM(0, 0, 1, 0);
    }
#endif


#if 0
    // test for i2c1/ipmb
    I2C_DEVICE ipmb_dev;
    uint32_t error;
    //uint8_t addr = 0;
    uint8_t buffer[4] = {0x00, 0x00, 0x00, 0x00};

    I2C_i2c1_slave_dev_init(&ipmb_dev, 0x41, 1);

#if 1
    while (1)
    {
        // write to i2c0
        //addr = (addr + 1) & 0xff;

        I2C_i2c1_slave_dev_set(&ipmb_dev, 0x00, (uint8_t*)&buffer[0], 2);
        error = I2C_i2c1_master_read(&ipmb_dev);
        if (error)
        {
            DEBUG("i2c0 error=0x%x\r\n", error);
        }
        else
        {
            DEBUG("ina230 cfg=0x%x\r\n", (buffer[0] << 8) | buffer[1]);
        }

        I2C_i2c1_slave_dev_set(&ipmb_dev, 0x01, (uint8_t*)&buffer[0], 2);
        error = I2C_i2c1_master_read(&ipmb_dev);
        if (error)
        {
            DEBUG("i2c0 error=0x%x\r\n", error);
        }
        else
        {
            DEBUG("ina230 shunt=0x%x\r\n", (buffer[0] << 8) | buffer[1]);
        }

        I2C_i2c1_slave_dev_set(&ipmb_dev, 0x02, (uint8_t*)&buffer[0], 2);
        error = I2C_i2c1_master_read(&ipmb_dev);
        if (error)
        {
            DEBUG("i2c0 error=0x%x\r\n", error);
        }
        else
        {
            DEBUG("ina230 bus=0x%x\r\n", (buffer[0] << 8) | buffer[1]);
        }

        buffer[0] = 0x2e;
        buffer[1] = 0xcf;
        I2C_i2c1_slave_dev_set(&ipmb_dev, 0x05, (uint8_t*)&buffer[0], 2);
        error = I2C_i2c1_master_write(&ipmb_dev);
        if (error)
        {
            DEBUG("i2c0 error=0x%x\r\n", error);
        }
        else
        {
            DEBUG("ina230 cal=0x%x\r\n", (buffer[0] << 8) | buffer[1]);
        }

        I2C_i2c1_slave_dev_set(&ipmb_dev, 0x04, (uint8_t*)&buffer[0], 2);
        error = I2C_i2c1_master_read(&ipmb_dev);
        if (error)
        {
            DEBUG("i2c0 error=0x%x\r\n", error);
        }
        else
        {
            DEBUG("ina230 cur=0x%x\r\n", (buffer[0] << 8) | buffer[1]);
        }

        I2C_i2c1_slave_dev_set(&ipmb_dev, 0x03, (uint8_t*)&buffer[0], 2);
        error = I2C_i2c1_master_read(&ipmb_dev);
        if (error)
        {
            DEBUG("i2c0 error=0x%x\r\n", error);
        }
        else
        {
            DEBUG("ina230 pow=0x%x\r\n", (buffer[0] << 8) | buffer[1]);
        }

        OSTimeDlyHMSM(0, 0, 3, 0);
    }
#endif

#if 0
    while (1)
    {
        // read device id
        temp_val[0] = temp_val[1] = 0;
        I2C_i2c1_slave_dev_set(&adt7470_dev, 0x3d, (uint8_t*)&temp_val[0], 1);
        error = I2C_i2c1_master_read(&adt7470_dev);
        if (error)
        {
            DEBUG("error=0x%x\r\n", error);
        }
        else
        {
            DEBUG("device id=0x%x\t", temp_val[0]);
        }
        OSTimeDlyHMSM(0, 0, 1, 0);

        DEBUG("\r\n");
    }
#endif
#endif

#if 1
    // test empty
    while (1)
    {
        OSTimeDlyHMSM(0, 0, 1, 0);
    }
#endif
}
//*****************************************************************************
//
// Configure the I2C0 master and slave and connect them using loopback mode.
//
//*****************************************************************************
int
main(void)
{
unsigned long ulDataTx[NUM_I2C_DATA];
unsigned long ulDataRx[NUM_I2C_DATA];
unsigned long ulindex;

    //
    // Set the clocking to run directly from the external crystal/oscillator.
    // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
    // crystal on your board.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_16MHZ);

    //
    // The I2C0 peripheral must be enabled before use.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);

    //
    // For this example I2C0 is used with PortB[3:2].  The actual port and
    // pins used may be different on your part, consult the data sheet for
    // more information.  GPIO port B needs to be enabled so these pins can
    // be used.
    // TODO: change this to whichever GPIO port you are using.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    //
    // Configure the pin muxing for I2C0 functions on port B2 and B3.
    // 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_PB2_I2C0SCL);
    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.
    // TODO: change this to select the port/pin you are using.
    //
    GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);

    //
    // Enable loopback mode.  Loopback mode is a built in feature that is
    // useful for debugging I2C operations.  It internally connects the I2C
    // master and slave terminals, which effectively let's you send data as
    // a master and receive data as a slave.
    // NOTE: For external I2C operation you will need to use external pullups
    // that are stronger than the internal pullups.  Refer to the datasheet for
    // more information.
    //
    HWREG(I2C0_MASTER_BASE + I2C_O_MCR) |= 0x01;

    //
    // 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.
    //
    I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(), false);

    //
    // Enable the I2C0 slave module. This module is enabled only for testing
    // purposes.  It does not need to be enabled for proper operation of the
    // I2Cx master module.
    //
    I2CSlaveEnable(I2C0_SLAVE_BASE);

    //
    // Set the slave address to SLAVE_ADDRESS.  In loopback mode, it's an
    // arbitrary 7-bit number (set in a macro above) that is sent to the
    // I2CMasterSlaveAddrSet function.
    //
    I2CSlaveInit(I2C0_SLAVE_BASE, SLAVE_ADDRESS);

    //
    // Tell the master module what address it will place on the bus when
    // communicating with the slave.  Set the address to SLAVE_ADDRESS
    // (as set in the slave module).  The receive parameter is set to false
    // which indicates the I2C Master is initiating a writes to the slave.  If
    // true, that would indicate that the I2C Master is initiating reads from
    // the slave.
    //
    I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS, false);

    //
    // Set up the serial console to use for displaying messages.  This is
    // just for this example program and is not needed for I2C operation.
    //
    InitConsole();

    //
    // Display the example setup on the console.
    //
    UARTprintf("I2C Loopback Example ->");
    UARTprintf("\n   Module = I2C0");
    UARTprintf("\n   Mode = Single Send/Receive");
    UARTprintf("\n   Rate = 100kbps\n\n");

    //
    // Initalize the data to send.
    //
    ulDataTx[0] = 'I';
    ulDataTx[1] = '2';
    ulDataTx[2] = 'C';

    //
    // Initalize the receive buffer.
    //
    for(ulindex = 0; ulindex < NUM_I2C_DATA; ulindex++)
    {
        ulDataRx[ulindex] = 0;
    }

    //
    // Indicate the direction of the data.
    //
    UARTprintf("Tranferring from: Master -> Slave\n");

    //
    // Send 3 peices of I2C data from the master to the slave.
    //
    for(ulindex = 0; ulindex < NUM_I2C_DATA; ulindex++)
    {
        //
        // Display the data that the I2C0 master is transferring.
        //
        UARTprintf("  Sending: '%c'  . . .  ", ulDataTx[ulindex]);

        //
        // Place the data to be sent in the data register
        //
        I2CMasterDataPut(I2C0_MASTER_BASE, ulDataTx[ulindex]);

        //
        // Initiate send of data from the master.  Since the loopback
        // mode is enabled, the master and slave units are connected
        // allowing us to receive the same data that we sent out.
        //
        I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND);

        //
        // Wait until the slave has received and acknowledged the data.
        //
        while(!(I2CSlaveStatus(I2C0_SLAVE_BASE) & I2C_SCSR_RREQ))
        {
        }

        //
        // Read the data from the slave.
        //
        ulDataRx[ulindex] = I2CSlaveDataGet(I2C0_SLAVE_BASE);

        //
        // Wait until master module is done transferring.
        //
        while(I2CMasterBusy(I2C0_MASTER_BASE))
        {
        }

        //
        // Display the data that the slave has received.
        //
        UARTprintf("Received: '%c'\n", ulDataRx[ulindex]);
    }

    //
    // Reset receive buffer.
    //
    for(ulindex = 0; ulindex < NUM_I2C_DATA; ulindex++)
    {
        ulDataRx[ulindex] = 0;
    }

    //
    // Indicate the direction of the data.
    //
    UARTprintf("\n\nTranferring from: Slave -> Master\n");

    //
    // Modifiy the data direction to true, so that seeing the address will
    // indicate that the I2C Master is initiating a read from the slave.
    //
    I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS, true);

    //
    // Do a dummy receive to make sure you don't get junk on the first receive.
    //
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);

    //
    // Dummy acknowledge and wait for the receive request from the master.
    // This is done to clear any flags that should not be set.
    //
    while(!(I2CSlaveStatus(I2C0_SLAVE_BASE) & I2C_SLAVE_ACT_TREQ))
    {
    }

    for(ulindex = 0; ulindex < NUM_I2C_DATA; ulindex++)
    {
        //
        // Display the data that I2C0 slave module is transferring.
        //
        UARTprintf("  Sending: '%c'  . . .  ", ulDataTx[ulindex]);

        //
        // Place the data to be sent in the data register
        //
        I2CSlaveDataPut(I2C0_SLAVE_BASE, ulDataTx[ulindex]);

        //
        // Tell the master to read data.
        //
        I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);

        //
        // Wait until the slave is done sending data.
        //
        while(!(I2CSlaveStatus(I2C0_SLAVE_BASE) & I2C_SLAVE_ACT_TREQ))
        {
        }

        //
        // Read the data from the master.
        //
        ulDataRx[ulindex] = I2CMasterDataGet(I2C0_MASTER_BASE);

        //
        // Display the data that the slave has received.
        //
        UARTprintf("Received: '%c'\n", ulDataRx[ulindex]);
    }


    //
    // Tell the user that the test is done.
    //
    UARTprintf("\nDone.\n\n");

    //
    // Return no errors
    //
    return(0);
}
Beispiel #9
0
//*****************************************************************************
//
// Configure the I2C0 master and slave and connect them using loopback mode.
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32DataTx;

    //
    // Set the clocking to run directly from the external crystal/oscillator.
    // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
    // crystal on your board.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_16MHZ);

    //
    // The I2C0 peripheral must be enabled before use.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);

    //
    // For this example I2C0 is used with PortB[3:2].  The actual port and
    // pins used may be different on your part, consult the data sheet for
    // more information.  GPIO port B needs to be enabled so these pins can
    // be used.
    // TODO: change this to whichever GPIO port you are using.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    //
    // Configure the pin muxing for I2C0 functions on port B2 and B3.
    // 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_PB2_I2C0SCL);
    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.
    // TODO: change this to select the port/pin you are using.
    //
    GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);

    //
    // Enable loopback mode.  Loopback mode is a built in feature that helps
    // for debug the I2Cx module.  It internally connects the I2C master and
    // slave terminals, which effectively lets you send data as a master and
    // receive data as a slave.  NOTE: For external I2C operation you will need
    // to use external pull-ups that are faster than the internal pull-ups.
    // Refer to the datasheet for more information.
    //
    HWREG(I2C0_BASE + I2C_O_MCR) |= 0x01;

    //
    // Enable the I2C0 interrupt on the processor (NVIC).
    //
    IntEnable(INT_I2C0);

    //
    // Configure and turn on the I2C0 slave interrupt.  The I2CSlaveIntEnableEx()
    // gives you the ability to only enable specific interrupts.  For this case
    // we are only interrupting when the slave device receives data.
    //
    I2CSlaveIntEnableEx(I2C0_BASE, I2C_SLAVE_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.
    //
    I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false);

    //
    // Enable the I2C0 slave module.
    //
    I2CSlaveEnable(I2C0_BASE);

    //
    // Set the slave address to SLAVE_ADDRESS.  In loopback mode, it's an
    // arbitrary 7-bit number (set in a macro above) that is sent to the
    // I2CMasterSlaveAddrSet function.
    //
    I2CSlaveInit(I2C0_BASE, SLAVE_ADDRESS);

    //
    // Tell the master module what address it will place on the bus when
    // communicating with the slave.  Set the address to SLAVE_ADDRESS
    // (as set in the slave module).  The receive parameter is set to false
    // which indicates the I2C Master is initiating a writes to the slave.  If
    // true, that would indicate that the I2C Master is initiating reads from
    // the slave.
    //
    I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS, false);

    //
    // Set up the serial console to use for displaying messages.  This is just
    // for this example program and is not needed for proper I2C operation.
    //
    InitConsole();

    //
    // Enable interrupts to the processor.
    //
    IntMasterEnable();

    //
    // Display the example setup on the console.
    //
    UARTprintf("I2C Slave Interrupt Example ->");
    UARTprintf("\n   Module = I2C0");
    UARTprintf("\n   Mode = Receive interrupt on the Slave module");
    UARTprintf("\n   Rate = 100kbps\n\n");

    //
    // Initialize the data to send.
    //
    ui32DataTx = 'I';

    //
    // Indicate the direction of the data.
    //
    UARTprintf("Transferring from: Master -> Slave\n");

    //
    // Display the data that I2C0 is transferring.
    //
    UARTprintf("  Sending: '%c'", ui32DataTx);

    //
    // Place the data to be sent in the data register.
    //
    I2CMasterDataPut(I2C0_BASE, ui32DataTx);

    //
    // Initiate send of single piece of data from the master.  Since the
    // loopback mode is enabled, the Master and Slave units are connected
    // allowing us to receive the same data that we sent out.
    //
    I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);

    //
    // Wait for interrupt to occur.
    //
    while(!g_bIntFlag)
    {
    }

    //
    // Display that interrupt was received.
    //
    UARTprintf("\n  Slave Interrupt Received!\n");

    //
    // Display the data that the slave has received.
    //
    UARTprintf("  Received: '%c'\n\n", g_ui32DataRx);

    //
    // Loop forever.
    //
    while(1)
    {
    }
}