M051 I2C Peripheral Driver. More...
|
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 | |
M051 I2C Peripheral Driver.
The CoX Peripheral Library also provide APIs for full functions of M051 I2C. This module supports the whole M051.
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.
The I2C API is broken into three groups of functions:
I2C Enable or Disable :
The I2C master init functions are:
The I2C slave init functions are:
Get the i2c status
Master transfer API includes:
Slave transfer API includes:
The Callback functions
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); }