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

M051 I2C Peripheral Driver. More...

Collaboration diagram for M051 I2C:

Modules

 I2C Status Type
 

Values that can be passed to UARTIntEnable, I2CIntDisable, and I2CIntClear as the ulIntFlags parameter, and returned from I2CIntStatus.


 I2C Transfer Type
 I2C General Call
 

Values that can be passed to I2CSlaveOwnAddressSet().


 I2C Time Out
 

Values that can be passed to I2CTimeoutCounterSet().


 I2C Interrupt Type
 

Values that can be passed to I2CIntEnable(),I2CIntDisable().


 M051 I2C Exported Types
 M051 I2C API

Detailed Description

M051 I2C Peripheral Driver.

The CoX Peripheral Library also provide APIs for full functions of M051 I2C. This module supports the whole M051.


Contents


1. M051 I2C Functional Description

I2C is two-wire, bi-directional serial bus to transfer data. One bus is SCL which provide the clock pulse for each data bit transfer on the other SDA bus.

I2c can be configured as master mode or slave mode. Master mode provides clock and start/stop signal. Arbitration exist between simultaneously transmitting masters.

Programmable clocks allow versatile rate control, i2c supports multiple address with mask option.

When any of the status change will cause an interrupt if the interrupt enable bit set.

A timeout function is provide to distinguish the restart signal form stop signal.


2. M051 I2C API Group

The I2C API is broken into three groups of functions:


2.1 I2C Init APIs

I2C Enable or Disable :

The I2C master init functions are:

The I2C slave init functions are:


2.2 I2C Transfer APIs

Get the i2c status

Master transfer API includes:

Slave transfer API includes:


2.3 I2C interrupt handler functions

The Callback functions


2.4 I2C API Timeout


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 initialize the I2C.
 //
 // \return None.
 //
 //*****************************************************************************
 void I2C0Init(void)
 {
     //
     // Configure the i2c pin
     //
     PinTypeI2C(I2C0SCL, PA11);
     PinTypeI2C(I2C0DATA, PA10);
    
     //
     // Enable the i2c peripheral
     //
     SysCtlPeripheralEnable(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;
     
     I2C0Init();
     //
     // Init the I2C as master, change the rata form 0 to 2000000
     //    
     I2CMasterInit(I2C0_BASE, 1000000);
     
     //
     // master transfer with polling mode
     //
     ucFlag = I2CMasterTransfer(I2C0_BASE, &I2CMasterTrCfg, I2C_TRANSFER_POLLING);   
     
     while(1);
 }
Note: