CoX Peripheral Interface(M051 Implement) V2.1.1.0
API Reference
xI2C

CoX I2C Peripheral Interface. More...

Collaboration diagram for xI2C:

Modules

 xI2C Master Interrupt
 xI2C Master Event
 xI2C Slave Interrupt
 xI2C Slave Event
 xI2C Master Error
 xI2C General Call
 

Values that show xI2C General Call
.


 xI2C API
 

xI2C API Reference.



Detailed Description

CoX I2C Peripheral Interface.

The xI2C is the I2C Peripheral Interface of CoX. It defines some common macros and APIs.

Contents


1. How is the xI2C Standard Define?

CoX I2C defines the APIs based on the following common functions:


2. API Groups

The CoX I2C API is broken into three groups of functions:


2.1 I2C Init APIs

The I2C master init functions are: xI2CMasterInit()

The I2C slave init functions are:


2.2 xI2C Transfer APIs

Master transfer API includes:

Slave transfer API includes:


2.3 I2C interrupt handler functions

The Callback functions

The master interrupt handler functions

The slave interrupt handler functions


3. Usage & Program Examples

The following example shows how to use the I2C API to initialize the master I2C, and how to transfer data to slave.

 //*****************************************************************************
 // 
 // I2C transfer and receive data config
 //
 //*****************************************************************************
 static tI2CMasterTransferCfg I2CMasterTrCfg;

 static unsigned char SendBuf[] = "MasterToSlv";
 static unsigned long SendLength =  11;
 static unsigned char SlaveAddress = 0x05;

 //*****************************************************************************
 //
 // \brief something should do before the test execute of xi2c002 test.
 //
 // \return None.
 //
 //*****************************************************************************
 void xI2CInit(void)
 {
     //
     // Set System clock.
     //
     xSysCtlClockSet(12000000, xSYSCTL_XTAL_12MHZ | xSYSCTL_OSC_MAIN);
     //
     // Configure the i2c pin
     //
     xPinTypeI2C(I2C0SCL, PA11);
     xPinTypeI2C(I2C0DATA, PA10);
    
     //
     // Enable the i2c peripheral
     //
     xSysCtlPeripheralEnable(xSYSCTL_PERIPH_I2C0);
     
     //
     // I2C master transfer config
     //
     I2CMasterTrCfg.ulSlave = SlaveAddress;
     I2CMasterTrCfg.pvWBuf = SendBuf;
     I2CMasterTrCfg.ulWLen = SendLength;
     I2CMasterTrCfg.ulWCount = 0;
     I2CMasterTrCfg.pvRBuf = 0;
     I2CMasterTrCfg.ulRLen = 0;
     I2CMasterTrCfg.ulRCount = 0;      
   
 }
 
 //*****************************************************************************
 //
 // \brief xI2C main body.
 //
 // \return None.
 //
 //*****************************************************************************
 void main(void)
 {
     unsigned char ucFlag;
     xI2CInit();
     //
     // Init the I2C as master, change the rata form 0 to 2000000
     //    
     xI2CMasterInit(I2C0_BASE, 1000000);
     
     //
     // master transfer with polling mode
     //
     ucFlag = xI2CMasterTransfer(I2C0_BASE, &I2CMasterTrCfg, I2C_TRANSFER_POLLING);   
     
     while(1);
 }